EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Atmega162: to check the Timer0 ticking

Started by Roman Mashak December 7, 2004
Hello, All!

When I initialize Timer0/1, how can I check amount of time spent by timer 
ticking, for example, if timer is configured for 10ms, how can I verify that 
10ms really have gone.  I suppose, I can attach probe of oscilloscope to 
pin1 of ATmega162 (according to datasheet it's OC0), but I don't see 
anything. Here is my code:

...

// ISR for Timer0
SIGNAL(SIG_OUTPUT_COMPARE0)
{
 LED0_blink();    //my function


/*
 Timer/Counter0 initialization
 CLock source: system clock
 Prescaler value: 8
 Clock value:
 Mode: increment CTC top=OCR0
 Interrupt: enable
*/
void Timer0_Init(void)
{
 TCCR0 = 0x00;  //stop timer
 TCNT0 = 0x00;
 TCCR0 = _BV(CS01) | _BV(WGM01);
 OCR0 = 0xFF;
 TIMSK = _BV(OCIE0);
}

int main(void)
{
 Timer0_Init();
 sei();

while (1)
{
.........
}

return 1;
}

With best regards, Roman Mashak.  E-mail: mrv@tusur.ru 


"Roman Mashak" <mrv@tusur.ru> wrote in message 
news:cp3m57$drb$1@mpeks.tomsk.su...
> Hello, All! > > When I initialize Timer0/1, how can I check amount of time spent by timer > ticking, for example, if timer is configured for 10ms, how can I verify > that 10ms really have gone. I suppose, I can attach probe of oscilloscope > to pin1 of ATmega162 (according to datasheet it's OC0), but I don't see > anything. Here is my code:
I'd use the simulator. The CPU has a stopwatch option. Leon
Hello, Leon!
You wrote  on Tue, 7 Dec 2004 11:44:07 -0000:

 ??>> When I initialize Timer0/1, how can I check amount of time spent by
 ??>> timer ticking, for example, if timer is configured for 10ms, how can I
 ??>> verify that 10ms really have gone.  I suppose, I can attach probe of
 ??>> oscilloscope to pin1 of ATmega162 (according to datasheet it's OC0),
 ??>> but I don't see anything. Here is my code:

 LH> I'd use the simulator. The CPU has a stopwatch option.
Could you please explain how to use this feature of simulator? I guess, I 
need to set up breakpoint for function I'm going to check, then run, after 
reaching breakpoint zero'ing stopwatch option, then run again? Hm...

With best regards, Roman Mashak.  E-mail: mrv@tusur.ru 


> > LH> I'd use the simulator. The CPU has a stopwatch option. > Could you please explain how to use this feature of simulator? I guess, I > need to set up breakpoint for function I'm going to check, then run, after > reaching breakpoint zero'ing stopwatch option, then run again? Hm...
I'm using AVR Studio 4.10. In Debug mode, select the I/O Workspace tab and open Processor. You should see a Stop Watch at the bottom. Right click on it and you will find lots of options. I run to a breakpoint, reset it, then run again to the breakpoint, or a second breakpoint, to get accurate timings. You need to set the correct clock rate for the simulator, of course. It should do what you want. You could use a 'scope as well, just to make sure. Leon -- Leon Heller, G1HSM http://www.geocities.com/leon_heller http://www.kasamba.com/viewExpert.asp?conMemID=105725&Catid=1111&banID=2100
Hello, Leon!
You wrote  on Tue, 7 Dec 2004 16:39:28 -0000:

 LH> I'm using AVR Studio 4.10.
i'm using 4.8 build 310
 LH> In Debug mode, select the I/O Workspace tab and open Processor. You
 LH> should see a Stop Watch at the bottom. Right click on it  and you will
 LH> find lots of options. I run to a breakpoint, reset it, then run again
 LH> to the breakpoint, or a second breakpoint, to get accurate timings. You
 LH> need to set the correct clock rate for the simulator, of course. It
 LH> should do what you want. You could use a 'scope as well, just to make
 LH> sure.
I've done everything you said, and got the following effect: after I reached 
the breakpoint 'stopwatch' value is changed and quickly resets to 0, so I 
have no time to see the value.

And I didn't find where to change simulator frequency, though I see its 
value in Processor window.
 LH> Leon

With best regards, Roman Mashak.  E-mail: mrv@tusur.ru 


Hello, Leon!
You wrote  on Tue, 7 Dec 2004 16:39:28 -0000:

 LH> In Debug mode, select the I/O Workspace tab and open Processor. You
 LH> should see a Stop Watch at the bottom. Right click on it  and you will
 LH> find lots of options. I run to a breakpoint, reset it, then run again
 LH> to the breakpoint, or a second breakpoint, to get accurate timings. You
 LH> need to set the correct clock rate for the simulator, of course. It
 LH> should do what you want. You could use a 'scope as well, just to make
 LH> sure.
OK, I set up frequency in simulator correctly and run the code, but I get 
some strange values in 'stop watch' field,, they are not what I expect. I'm 
doing the following steps:

1) set breakpoint
2) run (F5)
2) upon reaching breakpoint I zero'd the 'stop-watch' value (right click and 
choose reset)
3) press F5 again
4) see 'stop watch' value

With best regards, Roman Mashak.  E-mail: mrv@tusur.ru 



Memfault Beyond the Launch