8
\$\begingroup\$

I have to generate values between 0 V and 0.8 V for a circuit and take the value of the voltage output from the system and analyze the data. Can I generate voltage values automatically using a microcontroller? (For example: 0.05 V, 0.1 V, 0.15 V ...)

If the answer is yes, which microcontroller should I use and what techniques would you recommend?

If the answer is no, can you suggest any other means?

\$\endgroup\$
8
\$\begingroup\$

Yes, all microcontrollers have some way to produce voltage signals controlled by the firmware. The brute force method is for the micro to include a digital to analog converter (D/A). The firmware writes a number to the D/A and it produces a voltage proportional to that number.

One important spec of D/As is how many bits the number has. This determines its resolution. The D/A can produce 2N different values when there are N bits in the number. For example, a 8 bit D/A can produce 256 different voltage levels. Note that a ordinary digital output pin can be thought of as a 1 bit D/A. The number has two states, 0 and 1, and the output voltage is either high or low.

Most micros don't come with multi-bit D/As built in because there is little demand for this. Usually we try to convert analog values to digital as early in the process as possible, do the manipulations digitally, then control things with pulses. It is unusual to want a micro to produce a analog voltage. Even in applications like audio that you may think of as being inherently about a analog signal, things are often handled digitally or with pulses at the end. That's basically what a class D amplifier is.

If you don't want to use one of the limited set of micros that have a D/A built in, you can add one externally. There are many D/As available that the micro can drive over a SPI bus, for example.

However, unless you need high speed output, low pass filtering the PWM output of a micro results in a nice analog signal. Micros are good at producing well controlled sequences of pulses, and many have hardware built in for this purpose. For example, consider a digital output that can be changed every 1 µs (at 1 MHz rate). Suppose you grouped the 1 µs time slices into blocks of 1023. For each block, you can have anywhere from 0 to 1023 of the slices being high. If you were to average this, you'd get a analog value with 1024 possible levels, which is what you'd get from a 10 bit D/A. The raw signal will contain the average value you want, plus high frequencies starting at 1 MHz / 1023 = 978 Hz. By applying a few poles of low pass filtering (one resistor and capacitor per pole), you can keep the low frequency average signal and get rid of 978 Hz and higher components.

This type of A/D has some nice properties in that it is very linear, monotonic, and no power of two glitch outputs. The only drawback is usually bandwidth. For a few simple resistors and capacitors forming the low pass filter, you probably can't get a analog signal faster then a few 10s of Hz.

Note that using 1023 slices per block was a arbitary choice you made. If you want more resolution, make the blocks bigger, but then the filtered output will have to change slower. However, lots of micros can do the PWM generation in hardware with much faster than a 1 MHz slice rate.

I would try to see if the PWM method can be made to work before going to a external D/A.

\$\endgroup\$
1
3
\$\begingroup\$

What you're trying to design is a Data Acquisition System

If it has a Digital-to-Analog (DAC) converter then you can do it. Otherwise get an external DAC and have the microcontroller communicate to it via whatever it can (I2C, SPI, UART, etc..)

Noticed you tagged microchip, they do have microcontrollers with a DAC from simple ones (pic12f752, pic16f753,782) to advance ones (dsPIC33fj16GS504,502,302) and several more. you can find them through here http://www.microchip.com/maps/microcontroller.aspx

\$\endgroup\$
3
  • \$\begingroup\$ Then I could use the 12F752 for example, use his CDA to generate a voltage, and use a CAD to take the values of the system and analyze, right? \$\endgroup\$
    – user26136
    Jul 8 '13 at 12:12
  • \$\begingroup\$ @user26136 if CDA = micrcontroller's D-A, and CAD = microcontroller's A-D then yes!. I'd recommend also looking into calibration application notes \$\endgroup\$
    – Iancovici
    Jul 8 '13 at 12:17
  • \$\begingroup\$ Haha yes, it is. \$\endgroup\$
    – user26136
    Jul 8 '13 at 12:36
1
\$\begingroup\$

Depending on the current drawn by the system, you may be able to do this with a resistor ladder as a DAC: http://en.wikipedia.org/wiki/Resistor_ladder

If you want a small number of specific voltage values, you could even design the resistor ladder to emit those exactly rather than the normal system of 2^n evenly spaced values.

If it draws non-trivial current, you will want an op-amp on the output configured as a buffer. Make sure your op-amp operates with suitable linearity near 0V; you might need a negative power supply for this.

\$\endgroup\$
1
\$\begingroup\$

In addition to the other answers, most microcontrollers have a PWM function (and if not, you can always bit-bang one). If you feed PWM into a simple RC filter, you can make a primitive DAC without many additional components or cost.

\$\endgroup\$
1
\$\begingroup\$

If you're okay with PWM, then Arduino's Analog output would do the job just fine. You may also consider adding a low pass filter, since the pulses can be very noisy.

If you need a cleaner solution, find microcontrollers that come with DAC modules. Some of the MSP430 microcontrollers have DAC (see page 23) which you can use. You need to look into their datasheets.

If you find yourself constrained to a microcontroller without DAC, you can consider getting a DAC chip. This chips can be controlled easily via SPI or I2C, and they are cheap. Here's a 12 bit DAC which costs a little over a dollar.

Hope this helps.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.