Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I have to generate values between 0V and 0.8V 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.05V, 0.1V, 0.15V ...)

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 ideas?

share|improve this question

4 Answers 4

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.

share|improve this answer

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

share|improve this answer
    
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? –  user26136 Jul 8 '13 at 12:12
    
@user26136 if CDA = micrcontroller's D-A, and CAD = microcontroller's A-D then yes!. I'd recommend also looking into calibration application notes –  echad Jul 8 '13 at 12:17
    
Haha yes, it is. –  user26136 Jul 8 '13 at 12:36

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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