9

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?

Kevin Reid
  • 7,444
  • 1
  • 25
  • 44
user26136
  • 91
  • 1
  • 1
  • 2

5 Answers5

8

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.

Olin Lathrop
  • 310,974
  • 36
  • 428
  • 915
  • As a complete novice this was helpful to see the spectrum of filters available: http://www.analog.com/designtools/en/filterwizard/ – user391339 Feb 16 '18 at 23:24
3

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

Iancovici
  • 2,246
  • 17
  • 28
1

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.

bot3663369
  • 151
  • 3
1

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.

pjc50
  • 46,540
  • 4
  • 64
  • 126
1

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.

Phil Frost
  • 56,804
  • 17
  • 141
  • 262