Different ADC values depending on read order #12568
-
Hello, I am using a W5100S-EVB-Pico board to monitor for differences in two PWM signals. I am currently testing the ADC PWM input, but I notice that the values it reads are very different inconsistency, depending on what order they are read. I am currently using the board to generate the PWM signal and feeding it to two ADC GPIO:
The results for the ADC reads are not consistent for one of the PWM inputs: One will read the same appropriate value every time, but the other value is constantly changing at each read. example ` I have tried this with several ADC pins with same result, so I think this is some kind of timing issue. Anyone have any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
What you get is just the behavior of If the current input value of the pin is different to pulse_level, the function first (*) waits until the pin input becomes equal to pulse_level, then (**) times the duration that the pin is equal to pulse_level. If the pin is already equal to pulse_level then timing starts straight away. That makes |
Beta Was this translation helpful? Give feedback.
What you get is just the behavior of
time_pulse_us()
. You will get a proper reading for a high pulse only if the level at the input is low when the function is called. Otherwise only the remainder of the high period is timed. See the documentation at https://docs.micropython.org/en/latest/library/machine.html#machine.time_pulse_us:If the current input value of the pin is different to pulse_level, the function first (*) waits until the pin input becomes equal to pulse_level, then (**) times the duration that the pin is equal to pulse_level. If the pin is already equal to pulse_level then timing starts straight away.
That makes
time_pulse_us()
hard to use. It may be better if the implement…