Reading pwm signal on imp005

hello, im trying to read a 1 kHz pwm signal on imp005. Im using pin state change callbacks in order to do so (measuring low time in microseconds and high time in microseconds depending on the pin’s current state). However, the majority of rising/falling edges are not detected by the pin which is weird. Are imps even supposed to read signals like these, because my initial observation is that they aren’t made to function for millisecond precision applications. Any help would be appreciated as I am unfamiliar with imps.

Squirrel callbacks are not suited to timing measurements - there is variable latency between the hardware event and your function being called. Depending on your goal, you might try taking the imp offline with server.disconnect() during your measurements, and then averaging.

Another approach might be to use a UART with the TIMING_ENABLED flag:

1 Like

Thanks for your answer, would reading the signal from UART still enable me from calculating duty cycle and frequency?

You’d have to experiment, I think it would give you frequency but not duty if the UART trick only works on a falling edge. Perhaps a hardware monostable would give you the other edge.

If you switched to a different imp type with ADC pins, you could also use a low pass filter to measure duty.

This topic was automatically closed after 60 days. New replies are no longer allowed.