Is there any sanctioned way in Circuitpython to sample an ADC coincident another periodic action? For example, is there any way to output a PWM signal and start ADC sampling with analogbufio, with some assurance that the two will actually be phase-locked?
I'm teaching an instrumentation class, and my use case is a beam-block sensor where you pulse an LED and collect analog samples from a photodiode some distance away. The right way to do this is to collect two analog samples for each cycle of LED PWM: one during the "on" time and the other during the "off" time. Do this for a while, then subtract the "off" samples from the "on" samples and average.
Alternatively we can try a tight loop (software PWM) where we turn the LED on, sample, LED off, sample, etc. But it would be nicer to do it using proper PWM. I think there are similar use cases for things like synchronized ADC/DAC sampling and so on, basically any time you have two periodic processes that you want to link together.
Also, if it's not inappropriate to ask here, would this be relatively trivial in micropython using a PWM with associated timer interrupt? (I'm an embedded guy but don't have experience with either micro- or circuit-python, only C/C++)
Is there any sanctioned way in Circuitpython to sample an ADC coincident another periodic action? For example, is there any way to output a PWM signal and start ADC sampling with analogbufio, with some assurance that the two will actually be phase-locked?
I'm teaching an instrumentation class, and my use case is a beam-block sensor where you pulse an LED and collect analog samples from a photodiode some distance away. The right way to do this is to collect two analog samples for each cycle of LED PWM: one during the "on" time and the other during the "off" time. Do this for a while, then subtract the "off" samples from the "on" samples and average.
Alternatively we can try a tight loop (software PWM) where we turn the LED on, sample, LED off, sample, etc. But it would be nicer to do it using proper PWM. I think there are similar use cases for things like synchronized ADC/DAC sampling and so on, basically any time you have two periodic processes that you want to link together.
Also, if it's not inappropriate to ask here, would this be relatively trivial in micropython using a PWM with associated timer interrupt? (I'm an embedded guy but don't have experience with either micro- or circuit-python, only C/C++)