Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/10/08 14:04
Read: times


 
#158955 - Measuring A High Time
Responding to: ???'s previous message
The standard Timer0 may be put into a mode so that it counts its input clock by using the GATE0 bit in the TMOD SFR. In this mode the TIMER0 will count its clocks during the time the INT0 signal is at a high level.

You would then enable the EX0 interrupt in the IE SFR. This will cause an interrupt when the INT0 goes to a low level at the time your measurement interval ends. You will place code into the corresponding interrupt service routine to read the count accumulated in the TIMER0. This count represents how many timer clock periods the signal was high. For repetitive measurement the service routine may then reinitialize the TIMER0 to get ready for the next accumulation time when the INT0 signal returns high again.

To take care of the case where the INT0 signal may be high longer than the full count capability of the TIMER0 you will enable the ET0 interrupt in the IE SFR. This will trigger a different interrupt when the TIMER0 has overflowed. In the service routine for this interrupt you manage another one or two bytes of "software counter" in RAM locations. If these count once per overflow then they basically extend the 16-bit Timer0 to 24 bits or 32 bits of accumulated time that can be measured. If you use this scheme the extra bytes are combined with the 16 bits of TIMER0 in the first described interrupt routine. Keep in mind that the overflow counters need to be reset along with the TIMER0 when repetitive measurements are made.

There are some other things to consider when measuring pulse width using this technique.

1) The resolution of the measurement is limited to the period of the clock that feeds the TIMER0.

2) Due to the use of the interrupt service routines there is a going to be a limit to how short of time that can be permitted for when the INT0 signal can be low between the measurement intervals.

3) You need to carefully think about interrupt priorities between the two interrupts so as to minimize count problems when the two interrupts happen at nearly the same time.

4) In a measurement application like this it can very useful to keep the code in each of the interrupt routines as absolutely short and concise as possible. If you use C for much of your program then do consider writing the interrupt routines in assembly code.

Finally if you want to try to ever measure the low time of a signal you simply invert the input signal before feeding it to the INT0 pin.

If you want to measure both the high and low time of the same signal then invert the input signal and connect it into INT1 and setup another pair of interrupts as described here for TIMER1.

Michael Karas


List of 2 messages in thread
TopicAuthorDate
Timer0 question!            01/01/70 00:00      
   Measuring A High Time            01/01/70 00:00      

Back to Subject List