Sync A/D with digital

Hi , haven’t written any code yet , but thinking about a project where I use a PWM output to power a device .
i also want also read a 2 voltages at the time when the PWM pulse is high.

I know little about timing , but is it possible to do this ? And/or is the A/D sample time likely to be too long.

I can filter and produce smooth voltages to measure , but thought this might be a bit more elegant.

I can filter and produce smooth voltages to measure , but thought this might be a bit more elegant.

That's probably a better idea... Perhaps you should give us a few more details about what you're trying to do.

The "normal" PWM from the Arduino C++ library runs in the background so your program doesn't know when it's high or low. ...You could run the PWM back-into a digital input and read it (perhaps triggering an interrupt) but that's a rather un-elegant solution. A better solution would be to write your own assembly code so you can control everything.

There is only one analog-to-digital converter that's multiplexed to multiple input pins, so you can only read one analog input at a time. It's not real-fast, but the default PWM is slower so you should be able to take two readings while the PWM is high.

hammy:
Hi , haven’t written any code yet , but thinking about a project where I use a PWM output to power a device .
i also want also read a 2 voltages at the time when the PWM pulse is high

That should be perfectly possible provided the PWM HIGH is wide enough.

You could jumper the PWM pin to an external interrupt pin and then start the ADC readings when the PWM pin goes HIGH.

I came across a program that used the ADC when the PWM was LOW to detect the back-emf from an electric motor. IIRC it took several ADC samples during the LOW.

…R

Thx , few things to think about there.

I’m looking to characterise a sensor by calculating the current through it ( voltage either side of a series resistor), whilst I vary the voltage ( PWM) which warms it up.