Go Down

Topic: analogRead output voltage of op amp (Read 734 times) previous topic - next topic

biomed27

Hi,

I am attempting to amplify a small voltage with analogWrite to the op amp input and then read the amplified voltage with analogRead. However, the voltage read is completely wrong every time. The basic setup is a 2ms 10V pulse at 1hz, so I programmed the arduino to analogWrite the voltage necessary to obtain 10V for 2ms utilizing the op amp given the resistor configuration and then write 0 for 998ms. With the voltmeter, everything looks good but I want to be able to record the output voltage as well. Any ideas as to why I cannot obtain the correct reading for the output voltage?

thank you

Grumpy_Mike

Quote
Any ideas as to why I cannot obtain the correct reading for the output voltage?

Because analogWrite does not as it's name might suggest write out an analogue value. It outputs a PWM signal. If you want to turn that into an analogue value then you have to smooth it.
For more on PWM see:-
http://www.thebox.myzen.co.uk/Tutorial/PWM.html

CrossRoads

Can you post your schematic? How is the 0-10V being converted down to 0-5V for the analogRead()?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

jack wp

Interesting. Waiting on that schematic.
(just to get on the mailing list).
Good luck, Jack

James C4S


(just to get on the mailing list).

Next time, just click the "Notify" button to subscribe to a thread.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

jack wp

Oh, thanks James, I didn't know that.
Good luck, Jack

biomed27

Im just using a simple low pass filter to convert PWM to analog voltage, as Grumpy_Mike suggested. That voltage, ranging from 0-3V, is fed to an amplifier to be scaled up to 0-30V output. Now my problem is that I want to be able to analogRead the voltage, using a voltage divider, along the unknown resistor during the 2 ms pulse. However, I only get an accurate reading with pulses of 20 ms or greater at 1Hz. Any ideas? I tried different RC configurations to vary the the frequency, but this concept is not yet clear to me.

dc42

The default PWM frequency is 490Hz, which is much too low for generating a variable-voltage 2ms pulse. You need to to increase the PWM frequency and then reduce the value of your smoothing capacitor. See http://playground.arduino.cc/Main/TimerPWMCheatsheet.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Grumpy_Mike

Quote
I tried different RC configurations to vary the the frequency,

The penalty in using a low pass filter to smooth PWM is that the response time of changes in PWM value to actual voltage value is going to be slow. The better the filter is at smoothing the voltage the slower it allows that voltage to change.
One way around this is to make the difference between the PWM frequency and the frequency you want to change the voltage at bigger. Which is why dc42 advised you to increase the PWM frequency. That means for any given filter the voltage will be smoother. However your problem seems to be you want to change the voltage quickly.
Quote
However, I only get an accurate reading with pulses of 20 ms or greater

and you want:-
Quote
during the 2 ms pulse

That means the break frequency of your filter needs to be 10 times higher than it is now. And in order to maintain the same sort of smoothing the PWM frequency needs also to be at least 10 times higher than it is now.

Go Up