piclist 2001\04\03\022555a
>
Thread:
Trouble w/multiple AD inputs (F877)
massmind.org/techref/microchip/ios.htm?key=input
BY
:
Brian Reed email (remove spam text)
I've been using one A/D input for months and have now expanded
to 3. I must really have something goofy in my code, because the
channels interact with each other. Normally I'd do more testing
before asking here, but I'm going to try and run it at the SME robot
competion this Saturday (near Pittsburgh), so I wanted to ask if my
error is obvious...
This is what use to work, with the ICD demo board and the pot on RA0:
void AD_init(void)
{
OPTION = 0x87; // Set TMR0 prescaler, and 1:256
ADCON1 = 0x0E; // Left justify result, 1 analog channel
}
and
unsigned char AD_RA0(void)
{
ADCON0 = 0x41; // Fosc/8, A/D enabled
ADGO = 1; // Set the bit to start the conversion
while (ADGO) // Wait for the conversion to complete
continue; //
return ADRESH; // Return the AD value (just the top 8 bits)
}
Problem is, now that I've taken ADCON1 to 0x02 (for 5 D/A inputs and
3 digital I/Os, with Vdd&Vss as Vref's), the output of AD_RA0() does not
vary through the full range, and is greatly affected by input on RA1.
Yipes! Only when I turn RA0 and RA1 all the way up do I get a full-scale
A/D reading on RA0.
Here's the current code - likely this has the problem --->
/// PICLIST: note the change in ADCON1
void AD_init(void)
{
OPTION = 0x87; // Set TMR0 prescaler, and 1:256
ADCON1 = 0x02; // Left justify result, 3 analog channels
}
/// PICLIST: note the only difference between AD_RAx() routines is ADCON0
unsigned char AD_RA1(void)
{
ADCON0 = 0x49; // Fosc/8, A/D enabled
ADGO = 1; // Set the bit to start the conversion
while (ADGO) // Wait for the conversion to complete
continue; //
//// could/should disable A/D here? (w/ADCON0)
return ADRESH; // Return the AD value (just the top 8 bits)
}
unsigned char AD_RA2(void)
{
ADCON0 = 0x51; // Fosc/8, A/D enabled
ADGO = 1; // Set the bit to start the conversion
while (ADGO) // Wait for the conversion to complete
continue; //
//// could/should disable A/D here? (w/ADCON0)
return ADRESH; // Return the AD value (just the top 8 bits)
}
while (1) {
uctmp1 = AD_RA1(); // sensor
uctmp2 = AD_RA2(); // sensor
PORTC = AD_RA0(); // Turn on LEDs per POT on ICD demo board
}
Thanks,
- Bri
--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
<200104030147100810.10151BC2@femail14.sdc1.sfba.home.com> quoted-printable
In reply to: <4.3.2.7.2.20010403003504.00cf3da0@postoffice2.mail.cornell.edu>
See also: massmind.org/techref/microchip/ios.htm?key=input
month overview.
new search...