DAC General question

Hello all,

I’ve been lurking for a bit, testing and learning on my Mega 2560 R3 and I’m ready to ask my first questions about my first significant project.

In the project I’m reading in 4 analog inputs 0-5V DC and the goal is adjust them (mostly downwards) and output them again, ideally as true analog not PWM. What’s complicating it for me is that I want the 4 analog outs to output continuously without drop-outs or significant spikes from interrupts. Steps are ok.

So I’ve researched how an ADC chip works and some ways to make a true analog output from the PWM on the mega 2560’s pins and have the following questions:

  1. What is the best approach to get the 4 true analog outputs: a) Dedicated DAC chips b) R + Cap filter c) R2R ladders (requires too many pins for 8 bit resolution x 4 outputs?) d) some other method I can’t think of

  2. How does a DAC work, particularly a quad output? I read up on ADCs and saw they have a mux in front of a cap and some internal logic to create a multi-channel ADC but re 1a above, would a quad output DAC solve my problem? Specifically, can it output 4 different analog signals simultaneously or only in-turn/only one on at a time?

Thanks everyone!

Got $5 ?

$5 12-bit DAC

You could get four of those and one of these

Specifically, can it output 4 different analog signals simultaneously or only in-turn/only one on at a time?

A multiplexed quad output DAC would latch the values and update them via multiplexing. I would rather have 4 dedicated individual DACS than on multiplexed quad output Dac.

Or you could use a digital potentiometer - they're not quite as accurate, but they're cheaper.

Or you could go the R-C filter route for the lowest cost. Interrupts do not cause glitches in PWM.

Most multichannel DACs can output all channels simultaneously.

Most multichannel DACs can output all channels simultaneously.

I think the multiplexed channels are read and latched sequentially and then updated sequentially but the outputs are available simultaneously because they have been latched.

raschemmel:
Got $5 ?

$5 12-bit DAC

digikey

I even applied some filters for you:
4-channel, PTH, I2C, 8-bit

raschemmel: Got $5 ?

$5 12-bit DAC

You could get four of those and one of these

A multiplexed quad output DAC would latch the values and update them via multiplexing. I would rather have 4 dedicated individual DACS than on multiplexed quad output Dac.

I had come across this before but I didn't know much about I2C and I need 4 channels of analog out. Reading it again it appears from the datasheet that the MCP4725 only has 3 bits for addressing on Pin A0, 2 of which are set by the factory, leaving only a single bit for us. Thus we can only use 2 of these on one I2C bus at the same time, if I'm understanding it all correctly.

The adafruit ADC I didn't see and depending on how noisy/repeatable the Mega's ADC turns out to be muxing it's heart out across 4 inputs, I may try that one.

Thanks you for your reply!

DrAzzy: Or you could use a digital potentiometer - they're not quite as accurate, but they're cheaper.

Or you could go the R-C filter route for the lowest cost. Interrupts do not cause glitches in PWM.

Most multichannel DACs can output all channels simultaneously.

I didn't even know a digital pot existed...cool. I will look at that.

R/C filter I found may do the trick after reading http://provideyourown.com/2011/analogwrite-convert-pwm-to-voltage/ and using the online converter at http://sim.okawa-denshi.jp/en/PWMtool.php earlier, just have to test it out on breadboard.

Thanks!

Reading it again it appears from the datasheet that the MCP4725 only has 3 bits for addressing on Pin A0, 2 of which are set by the factory, leaving only a single bit for us. Thus we can only use 2 of these on one I2C bus at the same time, if I'm understanding it all correctly.

I believe you are correct.

Check out the AD5754

RC LPF

Thus we can only use 2 of these on one I2C bus at the same time,

No there is a simple trick. Connect each pin A0 to a separate Arduino output. Set all these outputs HIGH. Then when you want to use one set the associated output LOW and use it at the address where A0 is LOW. After use set the address pin HIGH again. That way you can use as many devices as you like on the I2C bus.

No there is a simple trick. Connect each pin A0 to a separate Arduino output. Set all these outputs HIGH. Then when you want to use one set the associated output LOW and use it at the address where A0 is LOW. After use set the address pin HIGH again. That way you can use as many devices as you like on the I2C bus.

Why didn't we think of that ? (duh)

Grumpy_Mike: No there is a simple trick. Connect each pin A0 to a separate Arduino output. Set all these outputs HIGH. Then when you want to use one set the associated output LOW and use it at the address where A0 is LOW. After use set the address pin HIGH again. That way you can use as many devices as you like on the I2C bus.

what what what!

Awesome! I learned something new- tricking out the i2C bus!

I'm not sure I follow it exactly but I'm going to order up one of those adafruit 4725 DAC BOBs to test if this will work.

Thanks!

Mike is saying allocate 4 GPIOs as CS ( chip selects) that pull the MCP4725 A0 pin LOW.

You didn't tell us what what what! you are going to do with this voltage.

A simple RC filter makes a perfect 0-5volt, but you might have to buffer it if you want to control something. Same with the D/A converters. Tell us what you want to do with the voltage. That might change the advice. Leo..

I've been lurking for a bit,

maybe it's a secret.... ;)

The vital piece of information missing here is what the sampling rate needs to be on the output. That needs to be multiplied by four for four channels. It is not going to be too much greater than 2KHz.

raschemmel:
Mike is saying allocate 4 GPIOs as CS ( chip selects) that pull the MCP4725 A0 pin LOW.

I undertstand now. Brain was getting a little ragged by the end of the day yesterday. Somehow I got stuck thinking I needed to pass more info than just a simple hi/lo to pin A0.

Thanks!

Wawa: You didn't tell us what what what! you are going to do with this voltage.

A simple RC filter makes a perfect 0-5volt, but you might have to buffer it if you want to control something. Same with the D/A converters. Tell us what you want to do with the voltage. That might change the advice. Leo..

I'm taking a straight 0-5V DC from a car sensor, read/adjusting/regenerating on my Arduino and feeding the V into into another computer module on a car which I understand does filtering and is high impedance so it should only need small mA. The plan is to test that in next day or two with Voltmeter to check the current draw so it doesn't pull too much and short the MCP2475 which I read is capped at 24mA output.

Thanks!

Grumpy_Mike: The vital piece of information missing here is what the sampling rate needs to be on the output. That needs to be multiplied by four for four channels. It is not going to be too much greater than 2KHz.

By sampling rate do you mean update frequency for each DAC output?

2 of the 4 outputs don't update very often, maybe 5 times/sec is plenty. The other two maybe 100hz is fine.

What causes the 2khz cap you're thinking of?

Thanks!

If you are reading 4 analog inputs , how quickly do you need to sample them in order to output the adjusted values to the DACs ? Or, in electronics lingo, what is the acceptable propagation delay between sampling and outputing ? ie: Can you take a sample , make the adjustment send the new value to the appropriate DAC and then sample the next one ? or do you need to sample all 4 within some specific time frame. Does it matter at all how much time elapses between the sample and the adjusted output from the DAC ?

2 of the 4 outputs don't update very often, maybe 5 times/sec is plenty. The other two maybe 100hz is fine.

[u]Arduino UNO ADS Sample rate[/u]

For a 16 MHz Arduino the ADC clock is set to 16 MHz/128 = 125 KHz. Each conversion in AVR takes 13 ADC clocks so 125 KHz /13 = 9615 Hz. That is the maximum possible sampling rate, but the actual sampling rate in your application depends on the interval between successive conversions calls

[u]ADS1115[/u]

Max sample rate :860sps

ads1115

raschemmel:
If you are reading 4 analog inputs , how quickly do you need to sample them in order to output the adjusted values to the DACs ?
Or, in electronics lingo, what is the acceptable propagation delay between sampling and outputing ?
ie:
Can you take a sample , make the adjustment send the new value to the appropriate DAC and then sample the next one ? or do you need to sample all 4 within some specific time frame. Does it matter at all how much time elapses between the sample and the adjusted output from the DAC ?

Arduino UNO ADS Sample rate

ADS1115

Max sample rate :860sps

ads1115

Gotcha.

Earlier last week I ran some tests based on Nick Gammon’s excellent post about ADC conversion accuracy and rate at various prescalers here and determined that, for at least one input at 1000 samples, it was extremely fast on the mega2560.

I was able to use a lower prescaler and still get good accuracy- I believe his code clocked in at 8uS for 1000 samples at the 4 prescaler, IIRC. The tests I ran went from 128 down to 2 prescaler and only 2 was unusable. I’m not sure I’d run prescaler 4 without testing it more at higher temps but even at 128, I should be able to get plenty of samples per second for what I need.

Thanks for the clarification and bearing with me while I learn!