File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
examples/Peripherals/HardwareTimer
Frequency_Dutycycle_measurement Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,13 @@ void TIMINPUT_Capture_Rising_IT_callback(HardwareTimer*)
3838 LastPeriodCapture = CurrentCapture;
3939}
4040
41+ /* In case of timer rollover, frequency is to low to be measured set values to 0
42+ To reduce minimum frequency, it is possible to increase prescaler. But this is at a cost of precision. */
43+ void Rollover_IT_callback (HardwareTimer*)
44+ {
45+ FrequencyMeasured = 0 ;
46+ DutycycleMeasured = 0 ;
47+ }
4148
4249/* *
4350 @brief Input capture interrupt callback : Compute frequency and dutycycle of input signal
@@ -103,6 +110,7 @@ void setup()
103110 MyTim->setOverflow (0x10000 ); // Max Period value to have the largest possible time to detect rising edge and avoid timer rollover
104111 MyTim->attachInterrupt (channelRising, TIMINPUT_Capture_Rising_IT_callback);
105112 MyTim->attachInterrupt (channelFalling, TIMINPUT_Capture_Falling_IT_callback);
113+ MyTim->attachInterrupt (Rollover_IT_callback);
106114
107115 MyTim->resume ();
108116
Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ void InputCapture_IT_callback(HardwareTimer*)
2727 LastCapture = CurrentCapture;
2828}
2929
30+ /* In case of timer rollover, frequency is to low to be measured set value to 0
31+ To reduce minimum frequency, it is possible to increase prescaler. But this is at a cost of precision. */
32+ void Rollover_IT_callback (HardwareTimer*)
33+ {
34+ FrequencyMeasured = 0 ;
35+ }
3036
3137void setup ()
3238{
@@ -53,6 +59,7 @@ void setup()
5359 MyTim->setPrescaleFactor (PrescalerFactor);
5460 MyTim->setOverflow (0x10000 ); // Max Period value to have the largest possible time to detect rising edge and avoid timer rollover
5561 MyTim->attachInterrupt (channel, InputCapture_IT_callback);
62+ MyTim->attachInterrupt (Rollover_IT_callback);
5663 MyTim->resume ();
5764
5865 // Compute this scale factor only once
You can’t perform that action at this time.
0 commit comments