Forum Discussion
Altera_Forum
Honored Contributor
10 years agoTimer Period not correctly
Hi all, my goal is to set a timer with a period time of 1ms and start it. After the time is elapsed it should rise an IRQ (once). The timer itself with interrupt works, but the time is always ab...
Altera_Forum
Honored Contributor
10 years agoOk, I tried to do it like this:
// set on shot time
IOWR_ALTERA_AVALON_TIMER_SNAPL(HIRES_TIMER_BASE, 0x03E8);
IOWR_ALTERA_AVALON_TIMER_SNAPH(HIRES_TIMER_BASE, 0x0000);
// Start timer, single, with IRQ
IOWR_ALTERA_AVALON_TIMER_CONTROL(HIRES_TIMER_BASE, 0x0005);
and then also like this: // set on shot time
IOWR_ALTERA_AVALON_TIMER_SNAPL(HIRES_TIMER_BASE, 0x03E8);
IOWR_ALTERA_AVALON_TIMER_SNAPH(HIRES_TIMER_BASE, 0x0000);
IOWR_ALTERA_AVALON_TIMER_PERIODL(HIRES_TIMER_BASE, 0x03E8);
IOWR_ALTERA_AVALON_TIMER_PERIODH(HIRES_TIMER_BASE, 0x0000);
// Start timer, single, with IRQ
IOWR_ALTERA_AVALON_TIMER_CONTROL(HIRES_TIMER_BASE, 0x0005);
always with the same behavour, about 6 to 8us until the IRQ is served.... In the data sheet it is written on the control register bit CONT: "When the counter reaches zero, it reloads with the value stored in the period registers, regardless of the CONT bit" Thus I would assume that with the second shot the time should be right? Also a test with writing a 7 to the Control register witch also enables the CONT bit (continuous) just "activates" the IRQ just once and not every 1000ms??? Is there maybe a problem with the period setting in QSYS? => Set to 1us assuming the timer decrements every 1us meaning with 1000 set to period/snapshot register counter reaches 0 at 1ms.