AnalogOut

The AnalogOut Interface is used to set the voltage of an analog output pin.

Hello World!

» Import this program

#include "mbed.h"
 
AnalogOut signal(p18);
 
int main() {
    while(1) {
        for(float i=0.0; i<1.0; i+=0.1) {
            signal = i;
            wait(0.0001);
        }
    }
}

API

» Import latest build into a program

Public Member Functions

  AnalogOut (PinName pin)
  Create an AnalogOut connected to the specified pin.
void  write (float value)
  Set the output voltage, specified as a percentage (float)
void  write_u16 (unsigned short value)
  Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF].
float  read ()
  Return the current output voltage setting, measured as a percentage (float)
AnalogOut operator= (float percent)
  An operator shorthand for write()
  operator float ()
  An operator shorthand for read()

Interface

/media/uploads/chris/pinout-thumbnails.jpg
See the Pinout page for more details

Details

The AnalogOut Interface can be used to set the voltage on the analog output pin somwhere in the range of 0.0v to 3.3v. The 0.0v to 3.3v range of the !AnalogOut can be represented in software as a normalised floating point number from 0.0 to 1.0, or directly as volts or millivolts.




15 comments:

22 Sep 2010

This page is missing the link to the library API details.

22 Sep 2010

Hi Steve,

Thanks for pointing that out. Its now fixed!

Cheers, Chris

09 Dec 2010

How to change the settling time?

31 Dec 2010

Hi! My name is chiky. I have a question. I have a fan that works 12V. I get move it with mbed Vout (3.3 V). But I wanna control it giving differents voltage. For this, I though I could use the analogic out, however I set 3.3V in analogic out [out.write(1.0f)] but the ventilator doesn't move and I check with multimeter that the measure is 3.3V. I think that is because there is no enough amp. I wonder if I could solve this with an Electronic assembly to give more AMP. Or another solution. Thanks.

Sorry for the tirade!

31 Dec 2010

For increasing the current capabilities you must use a buffer. Remember that the mbed itself output is about 40mA .. for a FAN you need about 100mA for 1w type 12v fan. At 3,3V I think you might get only 2 speeds ( "spinning from time to time" and "stop" ). You must consider using a voltage conerter like AO for extending the range from 0-3,3 to 0-12 ( something like 4x ) and a repater (transistor) to be able to drive the fan properly. And also it might be easier to control the speed of the fan on a PWM output.

31 Dec 2010

thanks "not important" your help is important for me. Could you recomend me an AO to buy? As you say mbed would have only 2 speed and I need more precision to get differents speed.

20 Jan 2011

I solve my problem with a control for motors, I say because sb could have the same problem. Bye

16 Jun 2011

user chiky manzanares wrote:

I solve my problem with a control for motors, I say because sb could have the same problem. Bye

Hi, I have a similar problem as you had before. I got a 5V 0.16A DC motor, and I don't know how to drive it. Can you give me some advice? THX

16 Jun 2011

user zhengyuan shen wrote:

user chiky manzanares wrote:

I solve my problem with a control for motors, I say because sb could have the same problem. Bye

Hi, I have a similar problem as you had before. I got a 5V 0.16A DC motor, and I don't know how to drive it. Can you give me some advice? THX

I think maybe you can use transistor

Here is my "prototype" for driving a small electric motor using one of the Mbed's digital out pins (actually a PWM pin, but that's not important).

The Mbed can only source about 40mA from a single pin, so in order to drive an electric motor, one needs to use a transistor... The only transistor I had lying around were some BC337's, which are pretty normal NPN transistors, but the maximum current they can drive is 800mA... so I used this tool to find out what value resistor I needed on the Base... as the 5v electric motor I use had a resistance of 2.2ohms, I decided to use 400ohm resistor... which, if I've understood everything, will mean the maximum current through the transistor will be 654.5mA... Hooray! That gives me a 145.5mA tolerance for variance in the components :)

See below for a screenshot :)

/media/uploads/bloodline/mycircuit.jpg

-Edit- I've modeled the electric motor as a 2.2ohm resistor with a flyback diode, which I included in my design to protect the transistor from any reverse current off the motor (which I know happens with solenoids... not sure about motors).

http://mbed.org/forum/electronics/topic/2392/

10 Nov 2011

I have noticed that the AnalogOut isn't behaving as expected. In the above example program, each step increase should increase the voltage by 0.33V. Connecting it to a oscilloscope, we should be able to see this in action. The 1st step from 0V to 0.33V is detected but the consecutive steps are in error. It seems that the steps are decreasing in value exponentially. The last step causes the output value to be at 550mV instead of the expected 3.3V.

Is there an explanation for this?

10 Nov 2011

I havent used the analog out yet, so assuming the software library is OK.

How do you measure that value? Perhaps you are loading the output. Is there a protective diode in your circuit that starts conducting and limits the voltage to 550mV? Curve could be exponentially in that case.

14 Nov 2011

I am measuring the value using the oscilloscope.

The only thing the AnalogOut is connected to is a resistor. I will be testing the AnalogOut without connecting it to anything today.

Edited: It has worked as expected.

19 Jul 2012

Hi! I was wondering if I can use this one AnalogOut pin for four dc motors, which i want to control separately. Does anybody know if this works? Thanks.

19 Jul 2012

I haven't tried this but you could use an analogue switch from the DAC output to a sample an hold type circuit, e.g. a capacitor with a fet input op amp for each motor input. This would have to be refreshed at a rate faster than any signal decay. But why noy add on a low cost SPI DAC? Microchip do some good 12 bit ones and from my experience will be less noisy.

19 Jul 2012

Or can't you use PWM outputs (via motor driver-ICs, or your own H-bridge) to control those motors?

Posting comments for this page has been disabled