Stoping of timer0 and measuring elapsed time in Atmega32

Status
Not open for further replies.

Haricharan

New Member
Is there any method Of directly stopping timer0 in Atmega32 Through hardware and read the timercounter0.. AVR book by Mazidi suggests through int0. Ie on interrupt stop the clock and. Read the count register. Any other method ? Friends suggest if any
Thanks in advance
B.J.Hari charan
 
What happens if you set the clock source to None. I.E. clear bits 0 to 2 of TCCR0.

Mike.
 
Is there any method Of directly stopping timer0 in Atmega32 Through hardware and read the timercounter0
I would suggest You to use the ICP Method.

When the Method is activated and an edge ( adjustible ) appears on the ICP Pin, the actual TCNT value will be copied into the ICP Register without any delay.
In an ICP Interrupt routine it can be read out and stored for further processing. You also can read it out in Main Routine when the loop time is short enough.

The TCNT0 count along while doing this.
I think that is one of the most exact time measureing methods.

When change the ICP interrupt sensing in the ICP Interrupt routine You can measure pulse length and pause length - when You need that.

To get a value between 2 Pulses You can subtract the previous result from the actual, without manipulation of the TCNT register.

Be a little careful - The timer 0 is only an 8 Bit counter that only can count up to 255 then it begins again at 0.
When the TCNT period is to short You can use the TIMER 1 that is an 16Bit Counter.
Another Method to avoid overruns is to Count up a Variable in the Timer Overflow Interrupt.
Yet another Method is to cascade 2 Counters - First Counter give Out a Pulse on Overrun.
The second Counter count up with this pulses ( Hardware Bridge between 2 Pins ). By usage of this Method You get an 24Bit Counter ( The Idea is from a project in the ELECTOR Magazine ).
 
Take a look into the Datasheet at Page 93.
There is:
When a change of the logic level (an event) occurs on the Input Capture pin (ICP1), alternativelyon the Analog Comparator output (ACO), and this change confirms to the setting of the edgedetector, a capture will be triggered. When a capture is triggered, the 16-bit value of the counter(TCNT1) is written to the Input Capture Register (ICR1). The Input Capture Flag (ICF1) is set atthe same system clock as the TCNT1 value is copied into ICR1 Register. If enabled(TICIE1 = 1), the Input Capture Flag generates an Input Capture interrupt. The ICF1 Flag isautomatically cleared when the interrupt is executed. Alternatively the ICF1 Flag can be clearedby software by writing a logical one to its I/O bit location.Reading the 16-bit value in the Input Capture Register (ICR1) is done by first reading the lowbyte (ICR1L) and then the high byte (ICR1H). When the low byte is read the high byte is copiedinto the high byte temporary register (TEMP). When the CPU reads the ICR1H I/O location it willaccess the TEMP Register.The ICR1 Register can only be written when using a Waveform Generation mode that utilizesthe ICR1 Register for defining the counter’s TOP value. In these cases the Waveform Genera-tion mode (WGM13:0) bits must be set before the TOP value can be written to the ICR1Register. When writing the ICR1 Register the high byte must be written to the ICR1H I/O locationbefore the low byte is written to ICR1L.
 
ICP = Input Capture. This allows an external trigger to "capture" (i.e. take a snapshot) of the current timer value. On an input capture interrupt event, the timer value at the time of the event is "captured" and stored in the ICR1H:L register pair.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…