Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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
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.
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.
gramo said:So what’s the most efficient/accurate impedance for ADC samples with PIC’s?
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)?
gramo said:So the two resistors form a parallel circuit for impedance as the PIC's capacitors charge/discharge through separate resistors?