Note the slightly inaccurate frequency values. The actual PWM frequency is 60.00 Hz. The measurement error is due to a bug in isr(). When the capture interrupt occurs (as opposed to the overflow interrupts), isr() reads register VALx, but that is not the capture register. It should be reading CVALx. In the output above, raw count values 2490368 (0x260000) and 2555904 (0x270000) are exact multiples of 65536. This is happening because isr() is incrementing msw on each overflow, but never reading the capture register to get the lower 16 bits.
With isr() changed to read CVALx, where X=0-5, rather than VALx, the output looks as shown below, with 60.00 Hz. No other changes are necessary outside isr().
Board T4.0
No shields / modules used
Arduino IDE version 1.8.13
Teensyduino version
Operating system & version Windows 7 Pro
No other software or hardware
Arduino Sketch
You can see the issue via the existing example sketches. The ONLY change required in the library is in file FreqMeasureMultiIMXRT. .cpp, in function isr(), replace 6 instances of VALx with CVALx, where X=0-5.
Description
Capture values computed in isr() are inaccurate for T4.x due to a bug in FreqMeasureMultiIMXRT.cpp
Steps To Reproduce Problem
Build/Run example sketch Single_PWM_In_Serial_Output on T4.0, with no changes. You'll see output like this:
Note the slightly inaccurate frequency values. The actual PWM frequency is 60.00 Hz. The measurement error is due to a bug in isr(). When the capture interrupt occurs (as opposed to the overflow interrupts), isr() reads register VALx, but that is not the capture register. It should be reading CVALx. In the output above, raw count values 2490368 (0x260000) and 2555904 (0x270000) are exact multiples of 65536. This is happening because isr() is incrementing msw on each overflow, but never reading the capture register to get the lower 16 bits.
With isr() changed to read CVALx, where X=0-5, rather than VALx, the output looks as shown below, with 60.00 Hz. No other changes are necessary outside isr().
Likewise, if you run the 3-PWM example sketch with the current library, you'll see this
And after the fix you'll see this
Hardware & Software
Board T4.0 No shields / modules used Arduino IDE version 1.8.13 Teensyduino version Operating system & version Windows 7 Pro No other software or hardware
Arduino Sketch
You can see the issue via the existing example sketches. The ONLY change required in the library is in file FreqMeasureMultiIMXRT. .cpp, in function isr(), replace 6 instances of VALx with CVALx, where X=0-5.
Modified version of isr() shown below.
void FreqMeasureMulti::isr() { IMXRT_FLEXPWM_t *pflexpwm = freq_pwm_pin_info[_pin].pflexpwm; uint8_t sub_module = freq_pwm_pin_info[_pin].module & 3;
}