|
Hi Sebastian,
You can measure the Duty cycle of your external PWM signal by using 'Capture' input in the 'Counter' component.
1) Use 2 Counter components, Counter1 and Counter2
2) Configure Counter1's Capture Mode to 'Rising Edge' and Counter2's Capture Mode to 'Falling Edge'.
3) Connect the same external signal whose PWM is to be measured to both the 'Capture' inputs of the Counter Components.
4) A common clock (internal) of suitable frequency is connected to Counters' Count input.
5) Check the Interrupt 'On TC' box for both the components and connect the interrupt Components to the Interrupt Terminal of the Counters.
6) Also check Reload Counter 'On Capture'.
7) Now whenever there is an Interrupt on Rising Edge (in Counter1), Reload the Counter2 to 0 (assuming both the counters are in Up-Counters mode) in the ISR.
8) Whenever there is a Falling Edge (in Counter2), read the value. This value corresponds to the HIGH period of the given External Signal.
9) The total time period of the given external signal is the period between two Rising Edges (in Counter1).
10) The ratio of the values got in Step 8 and Step 9 gives the Duty Cycle of the PWM Signal.
Higher the Frequency of the clock used, better is the resolution of the value obtained.
Please let us know if this helps.
Regards,
dasg
|