go_away

Author Topic: generating analog voltage using microcontroller  (Read 1419 times)

0 Members and 1 Guest are viewing this topic.

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
generating analog voltage using microcontroller
« on: June 02, 2011, 06:58:41 AM »
Hi

I need to generate an analog voltage using a microcontroller (16F877A)

I have two options -


1.)Use R-2R ladder and make a 10bit DAC

2.)generate 1kHz PWM signal--> send it through a 6 pole lowpass filter--> get analog voltage relevant to duty cycle.



Since I couldn't find any DAC ics, I'm stuck with above two options (they are the only methods I know of, are there any other methods?)

I have to order some DAC ICs but it will take about 3 weeks to reach me, so untill then I have to use some method to generate voltage.

What method do you think most reliable? that is more accurate and steady?

Thank you
I'm Me

Offline rbtying

  • Supreme Robot
  • *****
  • Posts: 452
  • Helpful? 31
Re: generating analog voltage using microcontroller
« Reply #1 on: June 02, 2011, 07:18:39 AM »
If you've got the available pins for it, the R-2R ladder is probably going to be more reliable (less fluctuation).  Realize that a 10-bit R-2R ladder will require 10 IO pins - 8-bit resolution is probably better, since then you can just use a single output port.  Otherwise, the PWM method should be a viable alternative, although more finicky, since the filter values matter significantly more than the resistors in the R-2R ladder.

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: generating analog voltage using microcontroller
« Reply #2 on: June 02, 2011, 07:25:25 AM »
resistors I have access is 5% tolerence.

so In R-2R ladder I have to use three 1k resistors to make one R-2R branch that means 1k and two !k resistors connected in series to make 2k. hope you get what I'm saying.
problem is as soon as I connect 2 resistors in series tolerence will become 10%. doesn't this going to affect accuracy more than in PWM method?

it is not a problem if there are resistor values wit R and 2R. like 1k and 2k
I'm Me

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,930
  • Helpful? 98
Re: generating analog voltage using microcontroller
« Reply #3 on: June 02, 2011, 05:45:07 PM »
Quote
I need to generate an analog voltage using a microcontroller (16F877A)
At what voltage?
How much current?


Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: generating analog voltage using microcontroller
« Reply #4 on: June 02, 2011, 05:47:35 PM »
voltage is 0 - 5V and few mA of current is enough. voltage if used as a reference voltage and followed by op amp bufferes
I'm Me

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: generating analog voltage using microcontroller
« Reply #5 on: June 02, 2011, 07:43:45 PM »
Since the resistors are in a ladder its a bit more of an accumulative error. So it depends on the acceptable output error - you wont achieve 'hi fi'  ;D

The ideal is to have as low a tolerance as you can afford - but you've already said 5%. You may also want to look at the 'single in line' packages if you want to make your board smaller (ie lots of resistors in one package) and the tolerances tend to be better across the package.

The PWM method is easier and cheaper !

I had the same problem with my own retro speech synthesiser where I had to re-create an audio waveform from the micro-controller.

Tried R-2R ladder but abandoned it for a PWM with a low pass filter (one R and one C in its most basic form). Less pins, less components, and no audible difference.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Daanii

  • Robot Overlord
  • ****
  • Posts: 138
  • Helpful? 3
Re: generating analog voltage using microcontroller
« Reply #6 on: June 02, 2011, 10:28:56 PM »
A digital potentiometer would work nicely to do what you want. But I suppose if you do not have any DAC ICs you will not have any digital potentiometers either.

My own guess is that the PWM will work better than the resistor ladder.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: generating analog voltage using microcontroller
« Reply #7 on: June 03, 2011, 04:54:17 PM »
Hi,

resistors I have access is 5% tolerence.
[...] problem is as soon as I connect 2 resistors in series tolerence will become 10%.
Not at all!
Assuming you have two 1k/5% resistors that are say +5%, i.e. 1050 Ohm each and you put them in series, you'd get 2100 Ohm which is still 5%
And that's the worst case scenario, the two resistors may just as likely be one +5% and one -5%, in which case the resultant series connection will be 0%
Actually, the more resistors you connect together, the more precise the end result.

Most 5% tolerance resistors are much closer than 5% (which is the guaranteed limit) and if you use metal film types that all come from the same production batch, they'll all be close in value, probably within better than 1%, so the R-2R will be pretty OK for a discrete build.


it is not a problem if there are resistor values wit R and 2R. like 1k and 2k
1k0 and 2k0 are standard values, but you'll get better precision using only one value - as explained above.


If speed isn't important, you can use an on-chip A/D-C together with a cap (plus a digital I/O pin to charge/discharge the cap) and a high impedance buffer, to get an output with the resolution determined by the A/D-C.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: generating analog voltage using microcontroller
« Reply #8 on: June 04, 2011, 07:09:23 AM »
Quote
Assuming you have two 1k/5% resistors that are say +5%, i.e. 1050 Ohm each and you put them in series, you'd get 2100 Ohm which is still 5%
And that's the worst case scenario, the two resistors may just as likely be one +5% and one -5%, in which case the resultant series connection will be 0%
Actually, the more resistors you connect together, the more precise the end result.

Most 5% tolerance resistors are much closer than 5% (which is the guaranteed limit) and if you use metal film types that all come from the same production batch, they'll all be close in value, probably within better than 1%, so the R-2R will be pretty OK for a discrete build.

my bad must have miscalculated :)

Quote
1k0 and 2k0 are standard values

never seen 2K. only near values I know is 1.8k and 2.2k

Quote
If speed isn't important, you can use an on-chip A/D-C together with a cap (plus a digital I/O pin to charge/discharge the cap) and a high impedance buffer, to get an output with the resolution determined by the A/D-C.
if i understand correctly this will kill lot of CPU time


I'm Me

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: generating analog voltage using microcontroller
« Reply #9 on: June 04, 2011, 12:27:45 PM »
Hi,


Quote
1k0 and 2k0 are standard values

never seen 2K. only near values I know is 1.8k and 2.2k
It's found in the E-24, the E-96 and the E-192 rows.
(You probably have access to the E-12 row alone, if you haven't seen 2k0).


Quote
If speed isn't important, you can use an on-chip A/D-C together with a cap (plus a digital I/O pin to charge/discharge the cap) and a high impedance buffer, to get an output with the resolution determined by the A/D-C.
if i understand correctly this will kill lot of CPU time
Not a lot and whether it's usable in a particular app should be determined with basis in what else needs to be done and whether you're able to make it in an interrupt routine.
'Most important is to keep leakage low - the more leakage, the more CPU time it needs to keep the voltage.

It works pretty well in one of the aps (an LED "characterizer") that I'm presently developing, but it's not time critical in any way.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: generating analog voltage using microcontroller
« Reply #10 on: June 04, 2011, 08:50:01 PM »
Quote
You probably have access to the E-12 row alone, if you haven't seen 2k0

probably  ;D

Quote
Not a lot and whether it's usable in a particular app should be determined with basis in what else needs to be done and whether you're able to make it in an interrupt routine.
'Most important is to keep leakage low - the more leakage, the more CPU time it needs to keep the voltage.

well we need to monitor the voltage and adjust it in a continues loop right? so if I have to do any other things(there are plenty, driving lcd, monitoring buttons,monitoring other voltages etc) even with an interrupt, voltage will vary as soon as I move away from charge-discharge loop. [I guess it might be able to turn charge discharge pin to a input just before jump away from loop hoping capacitor charge will not drop due to leakage]

I ordered some DAC samples from TI. hopefully they will arrive next week
I'm Me

 


Get Your Ad Here