Trouble with the built in ADC on MaxI-WED

Started by toozie21, December 30, 2014, 05:09:18 am

Previous topic - Next topic


OK, this is going to be a stupid question, but I've spend a couple of hours on it and am sure I am doing something silly wrong.

I had wanted to sample on the AN4 and if the 10bit value was great greater than 310, turn on a relays, otherwise, turn it off.  I had no luck at it, so I turned my attention to the pot that was already setup on AN3 since it seems like it is working out of the box.

I modified the Olimex function to look like this, but still cannot get it to work.  Anyone see why?
// Processes A/D data from the potentiometer
static void ProcessIO(void)
{const unsigned int maxVal=310;
#if defined(__C30__) || defined(__C32__)
    // Convert potentiometer result into ASCII string
    uitoa((WORD)ADC1BUF0, AN0String);
    // AN0 should already be set up as an analog input
    ADCON0bits.GO = 1;

    // Wait until A/D conversion is done

// AD converter errata work around (ex: PIC18F87J10 A2)
#if !defined(__18F87J50) && !defined(_18F87J50) && !defined(__18F87J11) && !defined(_18F87J11)
BYTE temp = ADCON2;
ADCON2 |= 0x7; // Select Frc mode by setting ADCS0/ADCS1/ADCS2
ADCON2 = temp;

    // Convert 10-bit value into ASCII string
    //uitoa(*((WORD*)(&ADRESL)), AN0String);

unsigned int value = 0;
value = ADRESL;
value += (ADRESH <<8);
if(value >= 310) //310.303 = 1.0V
REL1 = 1;  //#defined elsewhere to set the relay; is proven to work
REL1 = 0;  //#defined elsewhere to set the relay; is proven to work

It has to be something silly as this isn't a hard thing to do, but I am not getting it on this board. Thanks.


If I declare the result of the ADC globally in an array, would I then be able to call it from the FHTTP_print that is going to the webpage to make sure that it is working right?  I guess I've been assuming that the pot is working right since it shows up fine on the webpage, but that is via a different function call.....


Alright, it looks like the issue was that I was basing my function off of the main processIO function, and that must not be working right.  If I base it off of the HTTPPrint function for the pot, then it works.  So if anyone else runs into this problem, try using the HTTPPrint version as a basis.