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*)
38
38
LastPeriodCapture = CurrentCapture;
39
39
}
40
40
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
+ }
41
48
42
49
/* *
43
50
@brief Input capture interrupt callback : Compute frequency and dutycycle of input signal
@@ -103,6 +110,7 @@ void setup()
103
110
MyTim->setOverflow (0x10000 ); // Max Period value to have the largest possible time to detect rising edge and avoid timer rollover
104
111
MyTim->attachInterrupt (channelRising, TIMINPUT_Capture_Rising_IT_callback);
105
112
MyTim->attachInterrupt (channelFalling, TIMINPUT_Capture_Falling_IT_callback);
113
+ MyTim->attachInterrupt (Rollover_IT_callback);
106
114
107
115
MyTim->resume ();
108
116
Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ void InputCapture_IT_callback(HardwareTimer*)
27
27
LastCapture = CurrentCapture;
28
28
}
29
29
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
+ }
30
36
31
37
void setup ()
32
38
{
@@ -53,6 +59,7 @@ void setup()
53
59
MyTim->setPrescaleFactor (PrescalerFactor);
54
60
MyTim->setOverflow (0x10000 ); // Max Period value to have the largest possible time to detect rising edge and avoid timer rollover
55
61
MyTim->attachInterrupt (channel, InputCapture_IT_callback);
62
+ MyTim->attachInterrupt (Rollover_IT_callback);
56
63
MyTim->resume ();
57
64
58
65
// Compute this scale factor only once
You can’t perform that action at this time.
0 commit comments