I want to count pulses generated from a PWM pin on my Photon, so I’m feeding the PWM out to a second GPIO, and attaching an interrupt to that second pin. When the interrupt is triggered, it updates a counter.
This seems to work, other than I’m getting twice as many interrupts as I’d expect when setting attachInterrupt to RISING or FALLING (or at least my service routine’s running twice as many times as I’d expect). So, for example, if I’m using 1000 Hz to set the PWM output, the interrupt seems to be triggered 2000 times per second for RISING or FALLING mode. Seems to be exactly 2000 times, so not a standard noise issue. If I switch interrupt mode to CHANGE, then… I still get 2000 interrupts per second, which is correct, but I’d expect 4000 if it were consistent with RISING and FALLING modes.
The PWM signal looks lovely on my oscilloscope, not noisy.
I’ve tried using two different GPIOs (5 and 1) for this pulse-counting scheme, same results.
Thanks in advance for any help!