PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 19, 2009 5:04 pm |
|
|
I created the Vref voltages with a voltage divider made from 3 resistors,
and I connected it to the PIC as shown below.
Code: |
2.2K 2.0K 820 ohms
+5v ---/\/\/\/---o---/\/\/\/---o---/\/\/\/--- Ground
| |
| |
2.8v 0.8v
To pin RA3 To pin RA2
Vref+ Vref-
|
I have a 5K trimpot connected to pin A0 to provide the input analog
voltage. If I set the trimpot to 2.82v, I get this output from the program
below. (The compiler is doing the A/D conversions in 8-bit mode).
Quote: | 254
254
254
254
254 |
If I set the voltage on pin A0 to 0.83 volts, I get the following output:
Those readings are correct, for the given Vref circuit. This was tested
with vs. 4.093 of the compiler, on a PicDem2-Plus board.
Here is the test program:
Code: |
#include <16F877A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//=============================
void main()
{
int8 result;
setup_adc_ports(AN0_VREF_VREF);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
delay_us(20);
while(1)
{
result = read_adc();
printf("%u \n\r", result);
delay_ms(500);
}
} |
|
|