Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Microcontroller as ADC

Status
Not open for further replies.

microcare

New Member
Hi guys can u plz post the ckt of microcontroller used as an ADC ?

If possible the code as well ..

plz help its urgent ...
 
okay, relax! on which micro controller are you working..?

i suppose it is a 8051 cause it doesn't have an ADC .. right?
 
If you’re going down the PIC Micro road, maybe this could help

**broken link removed**

Click here to watch this circuit in action

This circuit is designed to take 2 ADC samples and display them on an LCD, heres the program;

Code:
Device 16F877
Declare XTAL 4

DECLARE ADIN_RES 10                 ' 10-bit result required
DECLARE ADIN_TAD FRC              ' RC OSC chosen
DECLARE ADIN_STIME 50             ' Allow 50us sample time

Declare LCD_TYPE 0                     ' Type of LCD Used is Alpha
Declare LCD_DTPIN PORTB.4         ' The control bits B4,B5,B6,B7
Declare LCD_RSPIN PORTB.2         ' RS pin on B2
Declare LCD_ENPIN PORTB.3         ' E pin on B3
Declare LCD_INTERFACE 4             ' Interface method is 4 bit

PORTB_PULLUPS True

Dim Result1 As Float
Dim Result2 As Float

Dim Last_Result1 As Float
Dim Last_Result2 As Float

Symbol Input1 = PORTA.0
Symbol Input2 = PORTA.1

TRISA = %00000011                     ' Configure AN0 (PORTA.0+1) as an input

ADCON1 = %10000000                 ' Set analogue input, Vref is Vdd

Main:

Result1 = ADIN 0                             ' Grab A0's digital value
Delayus 1                                       ' Allow internal capacitors to charge
Result2 = ADIN 1                             ' Grab A1's digital value

Result1 = Result1 * 5 / 1023              ' Scale it to volts
Result2 = Result2 * 5 / 1023                 '

If Last_Result1 <> Result1 Then       ' Check if value has changed
    Print At 1, 1, Dec2 Result1, "V "       ' If it has, display new data
    Last_Result1 = Result1                     ' and update last value
EndIf

If Last_Result2 <> Result2 Then        ' Check if value has changed
    Print At 2, 1, Dec2 Result2, "V "        ' If it has, display new data
    Last_Result2 = Result2                      ' and update last value
EndIf

Goto Main                                        ' Loop for ever

The output on the LCD would look like this (keep in mind that the voltages are for every changing in the above circuit)

**broken link removed**

If your using voltages over 5V, the logic device must be protected from them with a simple voltage divider similar to this;

**broken link removed**

Now the voltage will be reduced by 50% and you can easily sample this and multiply the sample result by two too scale it back up.

10 Bit ADC has a resolution of 0.0048 Volts, its more than enough for many applications.
 
microcare said:
im working on 89c051

see that's what i was expecting.. if you really want to use the 89c51.. well, you can build a ADC out of a R/2R network DAC, 2 opamps and a uC..

The idea is to let the micro generate numbers from 0 to 255, feed them to the R/2R DAC, generating voltages from 0 to 5v, and at each step compare the o/p with your voltage to be measured using the second op-amp (configured as a comparator).

you will get a '1' out of the second op-amo when your counter reach the measured voltage. here, stop counting, and the last counted number (btw 0 and 255) is the digital value propotional to the analog input.
 
see that's what i was expecting.. if you really want to use the 89c51.. well, you can build a ADC out of a R/2R network DAC, 2 opamps and a uC..

The idea is to let the micro generate numbers from 0 to 255, feed them to the R/2R DAC, generating voltages from 0 to 5v, and at each step compare the o/p with your voltage to be measured using the second op-amp (configured as a comparator).

you will get a '1' out of the second op-amo when your counter reach the measured voltage. here, stop counting, and the last counted number (btw 0 and 255) is the digital value propotional to the analog input.

OR
Buy a ready made ADC chip
 
hi gramo,

Is the 2*100k resistive divider input to the 16F877 ADC a mis-type.
Considering the specified maximum adc input impedance of 10K.

Eric
 
ericgibbs said:
hi gramo,

Is the 2*100k resistive divider input to the 16F877 ADC a mis-type.
Considering the specified maximum adc input impedance of 10K.

It's certainly a mistake, maximum source impedance should be something like 2.5K - otherwise accuracy can suffer, and reading speed is greatly comprimised.
 
gramo said:
So what’s the most efficient/accurate impedance for ADC samples with PIC’s?

Keep the source impedance less than 2.5K as the datasheet says, the delay is caused by the charging time of the internal capacitor for the sample and hold.

For an experiment, set up two analogue inputs, and read and display them both in a continuous loop - easy in your BASIC compiler. Take one pin to 5V and one to 0V, the first should read 255 and the second zero.

Now connect the pins via 100K resistors, and see what readings you get - they won't be correct any more, add a time delay after each reading, adjust the delay until both read correctly again. Try it with 1Meg and 10K resistors, and meausre the difference! - post your results here, it could be informative.
 
I'd be curious as well.
 
Guys,

let's say I want to sample voltages in a range of 40V using pic. I need to reduce the voltage to 5 volts max. You were using voltage dividers, but is there another way of doing that without making a path between Vdd and Vss? Also, according to pic datasheet, the resistance of the source should be less then 2.5k in order to sample it properly, in the case of gramo's post, is the resistance 1k||1k = 0.5k (grounding Vdd like large signal analysis for xtors)?

Thank You.
 
BOBKA said:
Guys,

let's say I want to sample voltages in a range of 40V using pic. I need to reduce the voltage to 5 volts max. You were using voltage dividers, but is there another way of doing that without making a path between Vdd and Vss? Also, according to pic datasheet, the resistance of the source should be less then 2.5k in order to sample it properly, in the case of gramo's post, is the resistance 1k||1k = 0.5k (grounding Vdd like large signal analysis for xtors)?

What's wrong with a potential divider?, it's how your meter works, it's how your scope works - there's really no better solution!.

The impedance problem is simple - check my PIC tutorials for an example, use an opamp buffer to convert the impedance to be suitable for the PIC.
 
gramo said:
So the two resistors form a parallel circuit for impedance as the PIC's capacitors charge/discharge through separate resistors?

Not really, it's only a crude approximation - when the input is grounded, then the two resistors are in parallel to discharge the sample and hold capacitor. But if the input is floating then it's only the one resistor. With input voltages it varies depending on the voltage and source impedance feeding the potential divider.
 
Nigel: Using voltage divider will introduce resistance to the system, and thus the system might behave in a wrong way. I will probably make a sample-and-hold block, then do the voltage divider at it's output and sample this output using pic's adc. Or I might just create a source follower, then voltage divide it and then sample this voltage using pic's adc.

In my case I just want to avoid introducing additional resistors (such as voltage dividers) to the ckt.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top