Hardware Reference
In-Depth Information
The pulse width can be calculated by the following equations:
Case 1
edge2 $ edge1
pulse width 5 ovcnt 3 2 16 1 diff
Case 2
edge2 , edge 1
pulse width 5 ( ovcnt 2 1) 3 2 16 1 diff
In case 2, the timer overflows at least once even if the pulse width is shorter than 2 16 - 1 clock
cycles. Therefore, we need to subtract 1 from the timer overflow count in order to get the
correct result. The pulse width is obtained by appending the difference of the two captured
edges to the TCNT overflow count. The logic flow of the program is shown in Figure 8.17.
Start
overflow
0
Set up to capture the rising edge
Disable all interrupts
No
C0F = 1?
Yes
Timer overflow interrupt
service routine
Clear timer overflow flag
Enable main timer overflow interrupt
Clear TOF flag
overflow
overflow + 1
Clear C0F flag
Save the first captured edge
Execute the RTI instruction
No
C0F = 1?
Yes
Compute the difference of two edges
No
Is second edge smaller?
Yes
overflow
overflow - 1
Combine the results
Stop
Figure 8.17 Logic flow for measuring pulse width of slow signals
 
Search WWH ::




Custom Search