PyBoard Timer Question
Posted: Mon Jun 03, 2019 3:31 am
Hi all,
I need some advice when it comes to using timers.
I want to read with an ADC and at every n’th (say 5) sample toggle a different GPIO. This is to produce a square wave and get the resulting wave via ADC after induction between 2 coils.
See example https://github.com/KipCrossing/OpenEM/b ... finder.gif.
I would like to be able to measure the phase from toggle. I’m wondering what is the best way to do this.
I can't seem to be able to achieve this with one timer because the ADC reads once every cycle. Is it possible to have 2 counters for the one timer; one for the ADC and the other for a PWM channel (could be a silly question)? My other idea is to take an ADC sample at every tick, set by the prescaler, and toggle the GPIO at every period (also, could be a silly suggestion)
I noticed that there is a way to synchronize timers with the STM module but I have a knowledge gap here and would need a good example to help me through the process.
These are the pins I'm planning to use (but can change):
Some guidance would be much appreciated.
Kip
I need some advice when it comes to using timers.
I want to read with an ADC and at every n’th (say 5) sample toggle a different GPIO. This is to produce a square wave and get the resulting wave via ADC after induction between 2 coils.
See example https://github.com/KipCrossing/OpenEM/b ... finder.gif.
I would like to be able to measure the phase from toggle. I’m wondering what is the best way to do this.
I can't seem to be able to achieve this with one timer because the ADC reads once every cycle. Is it possible to have 2 counters for the one timer; one for the ADC and the other for a PWM channel (could be a silly question)? My other idea is to take an ADC sample at every tick, set by the prescaler, and toggle the GPIO at every period (also, could be a silly suggestion)
I noticed that there is a way to synchronize timers with the STM module but I have a knowledge gap here and would need a good example to help me through the process.
These are the pins I'm planning to use (but can change):
Code: Select all
tim2 = Timer(2, prescaler=245, period=9)
ch1 = tim2.channel(1, Timer.PWM, pin=Pin.board.X1)
ch2 = tim2.channel(2, Timer.PWM_INVERTED, pin=Pin.board.X2)
adc1 = pyb.ADC(pyb.Pin.board.X3)
adc2 = pyb.ADC(pyb.Pin.board.X4)
Kip