From: bish on
I am trying to use a timer for regular interrupt in microblaze. I am
using edk 9.2i and spartan 3a dsp 1800a.
Even following a simple lab example widely used by beginners didn't
work: http://users.utcluj.ro/~baruch/ssce/labor/EDK-L5-e.pdf

I have connected all the interrupt ports correctly as evident from the
following portion of the mhs file:
BEGIN microblaze
PARAMETER HW_VER = 7.00.a
............
............
PORT INTERRUPT = interrupt
END

BEGIN xps_timer
PARAMETER INSTANCE = delay
PARAMETER HW_VER = 1.00.a
PARAMETER C_ONE_TIMER_ONLY = 1
PARAMETER C_BASEADDR = 0x8141c200
PARAMETER C_HIGHADDR = 0x8141c3ff
BUS_INTERFACE SPLB = mb_plb
PORT Interrupt = timer1
PORT CaptureTrig0 = net_gnd
END

BEGIN xps_intc
PARAMETER INSTANCE = xps_intc_0
PARAMETER HW_VER = 1.00.a
PARAMETER C_BASEADDR = 0x81418000
PARAMETER C_HIGHADDR = 0x814181ff
BUS_INTERFACE SPLB = mb_plb
PORT Irq = interrupt
PORT Intr = timer1
END


Now for the software settings since I am using edk 9.2i, it does not
have option for registering our interrupt handler in software platform
settings window (which is what the lab suggests), I used the
microblaze_register_handler(...) function ( I took me 3 days to figure
out this), but I still don't get how it works differently from the
function XIntc_RegisterHandler.
The portion of C file is as follows:
void timer_int_handler(void * baseaddr_p) {
/* Add variable declarations here */
unsigned int csr;
/* Read timer 0 CSR to see if it raised the interrupt */
csr = XTmrCtr_mGetControlStatusReg(XPAR_DELAY_BASEADDR,0);
/* If the interrupt occurred, then increment a counter */
/* and set one_second_flag to 1 */
if (csr & XTC_CSR_INT_OCCURED_MASK ) {
count ++;
one_second_flag = 1;
}

/* Display the count on the LEDs */
XGpio_mSetDataReg(XPAR_LED_HIGHADDR, LEDChan, count);

/* Print the count using the UART*/
xil_printf("count value is: %x\n\r", count);
/* Clear the timer interrupt */
XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR,0,csr);
}

int main() {

int count_mod_3;

//registering an interrupt handler
microblaze_register_handler((XInterruptHandler) timer_int_handler,
(void *)0);

/* Register the Timer interrupt handler in the vector table */
XIntc_RegisterHandler(XPAR_XPS_INTC_0_BASEADDR,
XPAR_XPS_INTC_0_DELAY_INTERRUPT_INTR,
(XInterruptHandler) timer_int_handler,
(void *)XPAR_DELAY_BASEADDR);
/* Enable MicroBlaze Interrupts */
microblaze_enable_interrupts();


/* Initialize and set the direction of the GPIO connected to LEDs */
XGpio_Initialize(&gpio, XPAR_LED_DEVICE_ID);
XGpio_SetDataDirection(&gpio,LEDChan, 0);

/* Start the interrupt controller */
XIntc_mMasterEnable(XPAR_XPS_INTC_0_BASEADDR);
XIntc_mEnableIntr(XPAR_XPS_INTC_0_BASEADDR, 0x1);

/* Set the gpio as output on high 8 bits (LEDs)*/
XGpio_mSetDataReg(XPAR_LED_DEVICE_ID,LEDChan, ~count);
xil_printf("The value of count = %d\n\r", count);

/* Set the number of cycles the timer counts before interrupting */
XTmrCtr_mSetLoadReg(XPAR_DELAY_BASEADDR, 0,
(timer_count*timer_count) * 50000000);

/* Reset the timers, and clear interrupts */
XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0,
XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK );

/* Enable timer interrupts in the interrupt controller */
XIntc_mEnableIntr(XPAR_DELAY_BASEADDR, XPAR_DELAY_INTERRUPT_MASK);

/* Start the timers */
XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0,
XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK |
XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK);

/* Wait for interrupts to occur */
while(1) {
if(one_second_flag){
count_mod_3 = count % 3;
if(count_mod_3 == 0)
xil_printf("Interrupt taken at %d seconds \n\r",count);
one_second_flag=0;
xil_printf(".");
}
}
}

When I run the system, the value of count does not change from 1. What
could be the problem?

From: Matthias Alles on
Hi!

I wonder, whether "one_second_flag" is declared as volatile? If not, the
compiler optimizes your if-statement in the while(1) loop away. You can
check this by using mb-objdump.

Cheers,
Matthias


bish schrieb:
> I am trying to use a timer for regular interrupt in microblaze. I am
> using edk 9.2i and spartan 3a dsp 1800a.
> Even following a simple lab example widely used by beginners didn't
> work: http://users.utcluj.ro/~baruch/ssce/labor/EDK-L5-e.pdf
>
> I have connected all the interrupt ports correctly as evident from the
> following portion of the mhs file:
> BEGIN microblaze
> PARAMETER HW_VER = 7.00.a
> ...........
> ...........
> PORT INTERRUPT = interrupt
> END
>
> BEGIN xps_timer
> PARAMETER INSTANCE = delay
> PARAMETER HW_VER = 1.00.a
> PARAMETER C_ONE_TIMER_ONLY = 1
> PARAMETER C_BASEADDR = 0x8141c200
> PARAMETER C_HIGHADDR = 0x8141c3ff
> BUS_INTERFACE SPLB = mb_plb
> PORT Interrupt = timer1
> PORT CaptureTrig0 = net_gnd
> END
>
> BEGIN xps_intc
> PARAMETER INSTANCE = xps_intc_0
> PARAMETER HW_VER = 1.00.a
> PARAMETER C_BASEADDR = 0x81418000
> PARAMETER C_HIGHADDR = 0x814181ff
> BUS_INTERFACE SPLB = mb_plb
> PORT Irq = interrupt
> PORT Intr = timer1
> END
>
>
> Now for the software settings since I am using edk 9.2i, it does not
> have option for registering our interrupt handler in software platform
> settings window (which is what the lab suggests), I used the
> microblaze_register_handler(...) function ( I took me 3 days to figure
> out this), but I still don't get how it works differently from the
> function XIntc_RegisterHandler.
> The portion of C file is as follows:
> void timer_int_handler(void * baseaddr_p) {
> /* Add variable declarations here */
> unsigned int csr;
> /* Read timer 0 CSR to see if it raised the interrupt */
> csr = XTmrCtr_mGetControlStatusReg(XPAR_DELAY_BASEADDR,0);
> /* If the interrupt occurred, then increment a counter */
> /* and set one_second_flag to 1 */
> if (csr & XTC_CSR_INT_OCCURED_MASK ) {
> count ++;
> one_second_flag = 1;
> }
>
> /* Display the count on the LEDs */
> XGpio_mSetDataReg(XPAR_LED_HIGHADDR, LEDChan, count);
>
> /* Print the count using the UART*/
> xil_printf("count value is: %x\n\r", count);
> /* Clear the timer interrupt */
> XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR,0,csr);
> }
>
> int main() {
>
> int count_mod_3;
>
> //registering an interrupt handler
> microblaze_register_handler((XInterruptHandler) timer_int_handler,
> (void *)0);
>
> /* Register the Timer interrupt handler in the vector table */
> XIntc_RegisterHandler(XPAR_XPS_INTC_0_BASEADDR,
> XPAR_XPS_INTC_0_DELAY_INTERRUPT_INTR,
> (XInterruptHandler) timer_int_handler,
> (void *)XPAR_DELAY_BASEADDR);
> /* Enable MicroBlaze Interrupts */
> microblaze_enable_interrupts();
>
>
> /* Initialize and set the direction of the GPIO connected to LEDs */
> XGpio_Initialize(&gpio, XPAR_LED_DEVICE_ID);
> XGpio_SetDataDirection(&gpio,LEDChan, 0);
>
> /* Start the interrupt controller */
> XIntc_mMasterEnable(XPAR_XPS_INTC_0_BASEADDR);
> XIntc_mEnableIntr(XPAR_XPS_INTC_0_BASEADDR, 0x1);
>
> /* Set the gpio as output on high 8 bits (LEDs)*/
> XGpio_mSetDataReg(XPAR_LED_DEVICE_ID,LEDChan, ~count);
> xil_printf("The value of count = %d\n\r", count);
>
> /* Set the number of cycles the timer counts before interrupting */
> XTmrCtr_mSetLoadReg(XPAR_DELAY_BASEADDR, 0,
> (timer_count*timer_count) * 50000000);
>
> /* Reset the timers, and clear interrupts */
> XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0,
> XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK );
>
> /* Enable timer interrupts in the interrupt controller */
> XIntc_mEnableIntr(XPAR_DELAY_BASEADDR, XPAR_DELAY_INTERRUPT_MASK);
>
> /* Start the timers */
> XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0,
> XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK |
> XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK);
>
> /* Wait for interrupts to occur */
> while(1) {
> if(one_second_flag){
> count_mod_3 = count % 3;
> if(count_mod_3 == 0)
> xil_printf("Interrupt taken at %d seconds \n\r",count);
> one_second_flag=0;
> xil_printf(".");
> }
> }
> }
>
> When I run the system, the value of count does not change from 1. What
> could be the problem?
>
From: bish on
On Nov 25, 12:25 pm, Matthias Alles <REMOVEallesCAPIT...(a)NOeit.SPAMuni-
kl.de> wrote:
> Hi!
>
> I wonder, whether "one_second_flag" is declared as volatile? If not, the
> compiler optimizes your if-statement in the while(1) loop away. You can
> check this by using mb-objdump.

I tried using the volatile for one_second_flag, still it does not
work. It just prints "the value of count = 1" once in terminal and
nothing happens then.

>
> Cheers,
> Matthias
>
> bish schrieb:
>
>
>
> > I am trying to use a timer for regular interrupt in microblaze. I am
> > using edk 9.2i and spartan 3a dsp 1800a.
> > Even following a simple lab example widely used by beginners didn't
> > work:http://users.utcluj.ro/~baruch/ssce/labor/EDK-L5-e.pdf
>
> > I have connected all the interrupt ports correctly as evident from the
> > following portion of the mhs file:
> > BEGIN microblaze
> >  PARAMETER HW_VER = 7.00.a
> > ...........
> > ...........
> > PORT INTERRUPT = interrupt
> > END
>
> > BEGIN xps_timer
> >  PARAMETER INSTANCE = delay
> >  PARAMETER HW_VER = 1.00.a
> >  PARAMETER C_ONE_TIMER_ONLY = 1
> >  PARAMETER C_BASEADDR = 0x8141c200
> >  PARAMETER C_HIGHADDR = 0x8141c3ff
> >  BUS_INTERFACE SPLB = mb_plb
> >  PORT Interrupt = timer1
> >  PORT CaptureTrig0 = net_gnd
> > END
>
> > BEGIN xps_intc
> >  PARAMETER INSTANCE = xps_intc_0
> >  PARAMETER HW_VER = 1.00.a
> >  PARAMETER C_BASEADDR = 0x81418000
> >  PARAMETER C_HIGHADDR = 0x814181ff
> >  BUS_INTERFACE SPLB = mb_plb
> >  PORT Irq = interrupt
> >  PORT Intr = timer1
> > END
>
> > Now for the software settings since I am using edk 9.2i, it does not
> > have option for registering our interrupt handler in software platform
> > settings window (which is what the lab suggests), I used the
> > microblaze_register_handler(...) function ( I took me 3 days to figure
> > out this),  but I still don't get how it works differently from the
> > function XIntc_RegisterHandler.
> > The portion of C file is as follows:
> > void timer_int_handler(void * baseaddr_p) {
> >     /* Add variable declarations here */
> >    unsigned int csr;
> >    /* Read timer 0 CSR to see if it raised the interrupt */
> >    csr = XTmrCtr_mGetControlStatusReg(XPAR_DELAY_BASEADDR,0);
> >    /* If the interrupt occurred, then increment a counter */
> >    /* and set one_second_flag to 1 */
> >    if (csr & XTC_CSR_INT_OCCURED_MASK ) {
> >            count ++;
> >            one_second_flag = 1;
> >    }
>
> >    /* Display the count on the LEDs */
> >    XGpio_mSetDataReg(XPAR_LED_HIGHADDR, LEDChan, count);
>
> >    /* Print the count using the UART*/
> >    xil_printf("count value is: %x\n\r", count);
> >    /* Clear the timer interrupt */
> >    XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR,0,csr);
> > }
>
> > int main() {
>
> >   int count_mod_3;
>
> >   //registering an interrupt handler
> >   microblaze_register_handler((XInterruptHandler) timer_int_handler,
> > (void *)0);
>
> >   /* Register the Timer interrupt handler in the vector table */
> >   XIntc_RegisterHandler(XPAR_XPS_INTC_0_BASEADDR,
> >                              XPAR_XPS_INTC_0_DELAY_INTERRUPT_INTR,
> >                              (XInterruptHandler) timer_int_handler,
> >                              (void *)XPAR_DELAY_BASEADDR);
> >   /* Enable MicroBlaze Interrupts */
> >   microblaze_enable_interrupts();
>
> >   /* Initialize and set the direction of the GPIO connected to LEDs */
> >   XGpio_Initialize(&gpio, XPAR_LED_DEVICE_ID);
> >   XGpio_SetDataDirection(&gpio,LEDChan, 0);
>
> >   /* Start the interrupt controller */
> >   XIntc_mMasterEnable(XPAR_XPS_INTC_0_BASEADDR);
> >   XIntc_mEnableIntr(XPAR_XPS_INTC_0_BASEADDR, 0x1);
>
> >   /* Set the gpio as output on high 8 bits (LEDs)*/
> >   XGpio_mSetDataReg(XPAR_LED_DEVICE_ID,LEDChan, ~count);
> >   xil_printf("The value of count = %d\n\r", count);
>
> >   /* Set the number of cycles the timer counts before interrupting */
> >   XTmrCtr_mSetLoadReg(XPAR_DELAY_BASEADDR, 0,
> > (timer_count*timer_count) * 50000000);
>
> >   /* Reset the timers, and clear interrupts */
> >   XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0,
> > XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK );
>
> >   /* Enable timer interrupts in the interrupt controller */
> >   XIntc_mEnableIntr(XPAR_DELAY_BASEADDR, XPAR_DELAY_INTERRUPT_MASK);
>
> >   /* Start the timers */
> >   XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0,
> > XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK |
> >                                            XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK);
>
> >   /* Wait for interrupts to occur */
> >   while(1) {
> >    if(one_second_flag){
> >            count_mod_3 = count % 3;
> >            if(count_mod_3 == 0)
> >                    xil_printf("Interrupt taken at %d seconds \n\r",count);
> >            one_second_flag=0;
> >            xil_printf(".");
> >            }
> >    }
> > }
>
> > When I run the system, the value of count does not change from 1. What
> > could be the problem?- Hide quoted text -
>
> - Show quoted text -

From: Bryan on
There is a 9.2 MicroBlaze Timer Interrupt example done by Avnet at
www.em.avnet.com/virtex4lx-sx-mb-dev, then click Support Files &
Downloads.

Bryan

On Nov 24, 7:19 pm, bish <bishes...(a)gmail.com> wrote:
> I am trying to use a timer for regular interrupt in microblaze. I am
> using edk 9.2i and spartan 3a dsp 1800a.
> Even following a simple lab example widely used by beginners didn't
> work:http://users.utcluj.ro/~baruch/ssce/labor/EDK-L5-e.pdf
>
> I have connected all the interrupt ports correctly as evident from the
> following portion of the mhs file:
> BEGIN microblaze
>  PARAMETER HW_VER = 7.00.a
> ...........
> ...........
> PORT INTERRUPT = interrupt
> END
>
> BEGIN xps_timer
>  PARAMETER INSTANCE = delay
>  PARAMETER HW_VER = 1.00.a
>  PARAMETER C_ONE_TIMER_ONLY = 1
>  PARAMETER C_BASEADDR = 0x8141c200
>  PARAMETER C_HIGHADDR = 0x8141c3ff
>  BUS_INTERFACE SPLB = mb_plb
>  PORT Interrupt = timer1
>  PORT CaptureTrig0 = net_gnd
> END
>
> BEGIN xps_intc
>  PARAMETER INSTANCE = xps_intc_0
>  PARAMETER HW_VER = 1.00.a
>  PARAMETER C_BASEADDR = 0x81418000
>  PARAMETER C_HIGHADDR = 0x814181ff
>  BUS_INTERFACE SPLB = mb_plb
>  PORT Irq = interrupt
>  PORT Intr = timer1
> END
>
> Now for the software settings since I am using edk 9.2i, it does not
> have option for registering our interrupt handler in software platform
> settings window (which is what the lab suggests), I used the
> microblaze_register_handler(...) function ( I took me 3 days to figure
> out this),  but I still don't get how it works differently from the
> function XIntc_RegisterHandler.
> The portion of C file is as follows:
> void timer_int_handler(void * baseaddr_p) {
>     /* Add variable declarations here */
>         unsigned int csr;
>         /* Read timer 0 CSR to see if it raised the interrupt */
>         csr = XTmrCtr_mGetControlStatusReg(XPAR_DELAY_BASEADDR,0);
>         /* If the interrupt occurred, then increment a counter */
>         /* and set one_second_flag to 1 */
>         if (csr & XTC_CSR_INT_OCCURED_MASK ) {
>                 count ++;
>                 one_second_flag = 1;
>         }
>
>         /* Display the count on the LEDs */
>         XGpio_mSetDataReg(XPAR_LED_HIGHADDR, LEDChan, count);
>
>         /* Print the count using the UART*/
>         xil_printf("count value is: %x\n\r", count);
>         /* Clear the timer interrupt */
>         XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR,0,csr);
>
> }
>
> int main() {
>
>   int count_mod_3;
>
>   //registering an interrupt handler
>   microblaze_register_handler((XInterruptHandler) timer_int_handler,
> (void *)0);
>
>   /* Register the Timer interrupt handler in the vector table */
>   XIntc_RegisterHandler(XPAR_XPS_INTC_0_BASEADDR,
>                              XPAR_XPS_INTC_0_DELAY_INTERRUPT_INTR,
>                              (XInterruptHandler) timer_int_handler,
>                              (void *)XPAR_DELAY_BASEADDR);
>   /* Enable MicroBlaze Interrupts */
>   microblaze_enable_interrupts();
>
>   /* Initialize and set the direction of the GPIO connected to LEDs */
>   XGpio_Initialize(&gpio, XPAR_LED_DEVICE_ID);
>   XGpio_SetDataDirection(&gpio,LEDChan, 0);
>
>   /* Start the interrupt controller */
>   XIntc_mMasterEnable(XPAR_XPS_INTC_0_BASEADDR);
>   XIntc_mEnableIntr(XPAR_XPS_INTC_0_BASEADDR, 0x1);
>
>   /* Set the gpio as output on high 8 bits (LEDs)*/
>   XGpio_mSetDataReg(XPAR_LED_DEVICE_ID,LEDChan, ~count);
>   xil_printf("The value of count = %d\n\r", count);
>
>   /* Set the number of cycles the timer counts before interrupting */
>   XTmrCtr_mSetLoadReg(XPAR_DELAY_BASEADDR, 0,
> (timer_count*timer_count) * 50000000);
>
>   /* Reset the timers, and clear interrupts */
>   XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0,
> XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK );
>
>   /* Enable timer interrupts in the interrupt controller */
>   XIntc_mEnableIntr(XPAR_DELAY_BASEADDR, XPAR_DELAY_INTERRUPT_MASK);
>
>   /* Start the timers */
>   XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0,
> XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK |
>                                                 XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK);
>
>   /* Wait for interrupts to occur */
>   while(1) {
>         if(one_second_flag){
>                 count_mod_3 = count % 3;
>                 if(count_mod_3 == 0)
>                         xil_printf("Interrupt taken at %d seconds \n\r",count);
>                 one_second_flag=0;
>                 xil_printf(".");
>                 }
>         }
>
> }
>
> When I run the system, the value of count does not change from 1. What
> could be the problem?

From: David on
On Nov 26, 2:37 am, bish <bishes...(a)gmail.com> wrote:
> On Nov 25, 12:25 pm, Matthias Alles <REMOVEallesCAPIT...(a)NOeit.SPAMuni-
>
> kl.de> wrote:
> > Hi!
>
> > I wonder, whether "one_second_flag" is declared as volatile? If not, the
> > compiler optimizes your if-statement in the while(1) loop away. You can
> > check this by using mb-objdump.
>
> I tried using the volatile for one_second_flag, still it does not
> work. It just prints "the value of count = 1" once in terminal and
> nothing happens then.
>
>
>
> > Cheers,
> > Matthias
>
> > bish schrieb:
>
> > > I am trying to use a timer for regular interrupt in microblaze. I am
> > > using edk 9.2i and spartan 3a dsp 1800a.
> > > Even following a simple lab example widely used by beginners didn't
> > > work:http://users.utcluj.ro/~baruch/ssce/labor/EDK-L5-e.pdf
>
> > > I have connected all the interrupt ports correctly as evident from the
> > > following portion of the mhs file:
> > > BEGIN microblaze
> > >  PARAMETER HW_VER = 7.00.a
> > > ...........
> > > ...........
> > > PORT INTERRUPT = interrupt
> > > END
>
> > > BEGIN xps_timer
> > >  PARAMETER INSTANCE = delay
> > >  PARAMETER HW_VER = 1.00.a
> > >  PARAMETER C_ONE_TIMER_ONLY = 1
> > >  PARAMETER C_BASEADDR = 0x8141c200
> > >  PARAMETER C_HIGHADDR = 0x8141c3ff
> > >  BUS_INTERFACE SPLB = mb_plb
> > >  PORT Interrupt = timer1
> > >  PORT CaptureTrig0 = net_gnd
> > > END
>
> > > BEGIN xps_intc
> > >  PARAMETER INSTANCE = xps_intc_0
> > >  PARAMETER HW_VER = 1.00.a
> > >  PARAMETER C_BASEADDR = 0x81418000
> > >  PARAMETER C_HIGHADDR = 0x814181ff
> > >  BUS_INTERFACE SPLB = mb_plb
> > >  PORT Irq = interrupt
> > >  PORT Intr = timer1
> > > END
>
> > > Now for the software settings since I am using edk 9.2i, it does not
> > > have option for registering our interrupt handler in software platform
> > > settings window (which is what the lab suggests), I used the
> > > microblaze_register_handler(...) function ( I took me 3 days to figure
> > > out this),  but I still don't get how it works differently from the
> > > function XIntc_RegisterHandler.
> > > The portion of C file is as follows:
> > > void timer_int_handler(void * baseaddr_p) {
> > >     /* Add variable declarations here */
> > >    unsigned int csr;
> > >    /* Read timer 0 CSR to see if it raised the interrupt */
> > >    csr = XTmrCtr_mGetControlStatusReg(XPAR_DELAY_BASEADDR,0);
> > >    /* If the interrupt occurred, then increment a counter */
> > >    /* and set one_second_flag to 1 */
> > >    if (csr & XTC_CSR_INT_OCCURED_MASK ) {
> > >            count ++;
> > >            one_second_flag = 1;
> > >    }
>
> > >    /* Display the count on the LEDs */
> > >    XGpio_mSetDataReg(XPAR_LED_HIGHADDR, LEDChan, count);
>
> > >    /* Print the count using the UART*/
> > >    xil_printf("count value is: %x\n\r", count);
> > >    /* Clear the timer interrupt */
> > >    XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR,0,csr);
> > > }
>
> > > int main() {
>
> > >   int count_mod_3;
>
> > >   //registering an interrupt handler
> > >   microblaze_register_handler((XInterruptHandler) timer_int_handler,
> > > (void *)0);
>
> > >   /* Register the Timer interrupt handler in the vector table */
> > >   XIntc_RegisterHandler(XPAR_XPS_INTC_0_BASEADDR,
> > >                              XPAR_XPS_INTC_0_DELAY_INTERRUPT_INTR,
> > >                              (XInterruptHandler) timer_int_handler,
> > >                              (void *)XPAR_DELAY_BASEADDR);
> > >   /* Enable MicroBlaze Interrupts */
> > >   microblaze_enable_interrupts();
>
> > >   /* Initialize and set the direction of the GPIO connected to LEDs */
> > >   XGpio_Initialize(&gpio, XPAR_LED_DEVICE_ID);
> > >   XGpio_SetDataDirection(&gpio,LEDChan, 0);
>
> > >   /* Start the interrupt controller */
> > >   XIntc_mMasterEnable(XPAR_XPS_INTC_0_BASEADDR);
> > >   XIntc_mEnableIntr(XPAR_XPS_INTC_0_BASEADDR, 0x1);
>
> > >   /* Set the gpio as output on high 8 bits (LEDs)*/
> > >   XGpio_mSetDataReg(XPAR_LED_DEVICE_ID,LEDChan, ~count);
> > >   xil_printf("The value of count = %d\n\r", count);
>
> > >   /* Set the number of cycles the timer counts before interrupting */
> > >   XTmrCtr_mSetLoadReg(XPAR_DELAY_BASEADDR, 0,
> > > (timer_count*timer_count) * 50000000);
>
> > >   /* Reset the timers, and clear interrupts */
> > >   XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0,
> > > XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK );
>
> > >   /* Enable timer interrupts in the interrupt controller */
> > >   XIntc_mEnableIntr(XPAR_DELAY_BASEADDR, XPAR_DELAY_INTERRUPT_MASK);
>
> > >   /* Start the timers */
> > >   XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0,
> > > XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK |
> > >                                            XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK);
>
> > >   /* Wait for interrupts to occur */
> > >   while(1) {
> > >    if(one_second_flag){
> > >            count_mod_3 = count % 3;
> > >            if(count_mod_3 == 0)
> > >                    xil_printf("Interrupt taken at %d seconds \n\r",count);
> > >            one_second_flag=0;
> > >            xil_printf(".");
> > >            }
> > >    }
> > > }
>
> > > When I run the system, the value of count does not change from 1. What
> > > could be the problem?- Hide quoted text -
>
> > - Show quoted text -

Hello,

Here is how I set up a timer interrupt in 9.2:

void TimerCounterHandler(void *CallBackRef)
{
print("timer interrupt ");
}

Int main (void) {

XIntc intr_ctrl;
XTmrCtr timr;


XIntc_Initialize(&intr_ctrl,XPAR_XPS_INTC_0_DEVICE_ID);
XTmrCtr_Initialize(&timr,XPAR_XPS_TIMER_1_DEVICE_ID);

XIntc_Connect(&intr_ctrl, XPAR_XPS_INTC_0_XPS_TIMER_1_INTERRUPT_INTR,
(XInterruptHandler)
XTmrCtr_InterruptHandler,
(void *)&timr);

XIntc_Start(&intr_ctrl, XIN_REAL_MODE);

XIntc_Enable(&intr_ctrl, XPAR_XPS_INTC_0_XPS_TIMER_1_INTERRUPT_INTR);

XTmrCtr_SetHandler(&timr, (void *)TimerCounterHandler, void);

XTmrCtr_SetOptions(&timr, 0,
XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION);

XTmrCtr_SetResetValue(&timr, 0, 0xF0000000);

XTmrCtr_Start(&timr,0);

microblaze_enable_interrupts();

while(1){
//wait for interrupts
}

}

If you are using the Intc component, you no longer need to use the
microblaze_register_handler function - instead use the XIntc_Connect()
function.
The XTmrCtr driver provides its own interrupt handler
XTmrCtr_InterruptHandler() which you should use to service the
interrupt. It will issue a callback to a function of your choice (set
with XTmrCtr_SetHandler)

Hope this helps,

David