Hi, I'm relatively new to the world of embedded programming but have been making progress lately up until I tried to read 2 different A/D channels. My circuit is going to be a temperature control set to display on a Hitachi 44780 LCD along with a 10k pot for reading the temperature set-point. I'm using a pic16f684 configured to use the internal oscillator running at 8Mhz. I have the LCD connected to portc using a 4-bit operation for display. A 10K thermistor is connected to RA0 (pin 13) and a 10K pot connected to RA2 (pin 11). I've taken the approach of getting the individual pieces to work by themselves and am now trying to get them to work together. The LCD works fine, reading a temperature works as well as reading the pot (using the 8 most significant bits). My problem comes when I try to read both the thermistor and the pot in subsequent loops. If I turn off the switch (sw) and only read either the pot or the thermistor, it works. If I oscillate between the two, neither reads an analog value properly. I tried to add a delay after I set the ADCON0 bits for each read but that doesn't seem to have helped. At this point I am at a bit of a loss as to what needs to be done. I'm hoping its something simple that I have overlooked. I have attached the code below, any insight you can provide as to what I am doing wrong would be very much appreciated. Thanks, Jason /** Thermo2.c Jason Wambach PICC program for the pic16f684 to read temperature and display on an LCD. **/ #include #include __CONFIG(FCMDIS & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTEN & WDTDIS & INTIO); int i,j,k,n,Count,b,sw; unsigned int a; double Temp; // 1234567890123456 const char TopMessage[] = "Curr Temp: "; const char BotMessage[] = "Set Temp: "; #define E RC4 #define RS RC5 const int Twentyms = 1250; const int Fivems = 300; const int TwoHundredus = 10; //4bit LCD Write Operation LCDWrite(int LCDData, int RSValue) { PORTC = (LCDData >> 4) & 0x0F; RS = RSValue; E = 1; E = 0; PORTC = LCDData & 0x0F; RS = RSValue; E = 1; E = 0; if ((0 == (LCDData & 0xFC)) && (0 == RSValue)) { n = Fivems; } else { n = TwoHundredus; } for (k = 0; k < n; k++); } //Write formatted decimal to LCD TempDec(int i) { int t; if (i >= 100) { t = i / 100; LCDWrite('0' + t, 1); i = i % 100; } else { LCDWrite(' ', 1); } if (i >= 10) { t = i / 10; LCDWrite('0' + t, 1); i = i % 10; } else { LCDWrite('0', 1); } LCDWrite('0' + i, 1); } main() { PORTC = 0; CMCON0 = 7; TRISC = 0; TRISA0 = 1; TRISA2 = 1; ANSEL = 0b00000101; ADCON1 = 0b00010000; //Clock Fosc/8 or 2uS //LCD Initialization j = Twentyms; for (i = 0; i < j; i++); PORTC = 3; E = 1; E = 0; //Reset j = Fivems; for (i = 0; i < j; i++); E = 1; E = 0; //Reset 2 j = TwoHundredus; for (i = 0; i < j; i++); E = 1; E = 0; //Reset 3 j = TwoHundredus; for (i = 0; i < j; i++); PORTC = 2; E = 1; E = 0; j = TwoHundredus; for (i = 0; i < j; i++); LCDWrite(0b00101000,0); LCDWrite(0b00000001,0); //clear lcd LCDWrite(0b00000110,0); LCDWrite(0b00001110,0); a = 0; Count = 0; sw = 0; while (1 == 1) { if (sw) { ADCON0 = 0b10000001; //Selected RA0, Right justified j = Twentyms; //Delay for setup of A/D converter for (i = 0; i < j; i++); GODONE = 1; while (!GODONE); a = (ADRESH << 8) + ADRESL; //Temperature Calculation Temp = (1023.0 / (double)a) - 1.0; Temp = log(Temp); Temp = 32.5 - (Temp / 0.019129); Temp = (9f/5f)*Temp+32; a = (int)Temp; } else { ADCON0 = 0b00001001; //select RA2, Left justified result j = Twentyms; //Delay for setup of A/D converter for (i = 0; i < j; i++); GODONE = 1; while (!GODONE); b = ADRESH; //only care about 8 most significant bits } sw = sw ^ 1; //switch between channels every loop //Only update the LCD every 10 iterations if (Count == 0) { LCDWrite(0b00000001,0); //clear lcd for (i = 0; i< TopMessage[i] != 0; i++) { LCDWrite(TopMessage[i],1); //LCDWrite('0' + i, 1); } TempDec(a); //Format and display LCDWrite(0xDF, 1); //Degree symbol LCDWrite('F', 1); LCDWrite(0b11000000,0); //Move to 2nd line //2nd Line for (i = 0; BotMessage[i] != 0; i++) { LCDWrite(BotMessage[i],1); } TempDec(b); LCDWrite(0xDF, 1); LCDWrite('F', 1); Count++; } else { Count++; if (Count == 10) { Count = 0; } } //delay for (i = 0; i < 255; i++) { for (j = 0; j < 129; j++); } } } -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist