Paul Duffy wrote: > Hi > > I am using the 16F684 and want to read 2 different A/D inputs to set 2 different time delays in my widget. I have 2 potentiometers, set up as voltage dividers, connected to the A/D inputs. My attempts to read the A/D are failing. Here is the relevant code snippet: > ..... > ..... > off = 0; > on = 0; > ansel = 0b0000011; //select AN0, AN1 (pins 12, 13) as A/D inputs > adcon1 = 0b01010000; //select 16*Tosc clock - gives TAD of 4uS > adcon0 = 0b00000001; //turn on A/D, select AN0 as input, don't start conversion > > while(1) //Main Loop - continuously update porta and portc. > { > porta = off; //display via leds connected to available port pins > portc = on; //display via leds connected to available port pins > > adcon0 = 0b00000001; //turn on A/D, select AN0 as input, don't start conversion > delay_ms(10); //delay each time through loop, > set_bit(adcon0,1); //start a/d conversion > while (!test_bit(adcon0,1)); //wait for completion > on = adresh; //store on_time - AN0 > if(on==0)on = on+1; //ensures on_time !=0 > > adcon0 = 0b00000101; //Change the input to AN1, don't start conversion > delay_ms(10); //delay each time through loop, > set_bit(adcon0,1); //start a/d conversion > while (!test_bit(adcon0,1)); //wait for completion > off = adresh; //store off_time - AN1 > if(off==0)off = off+1; //ensures off_time !=0 > } > > As it is, this does not work at all. I see no change on the leds connected to portc or porta when I change the potentiometers. If I remove one of the "adcon0=..." statements, then one of the potentiometers is read and displayed in both ports. Depending on which of the 2 "adcon0=..." statements I delete, I can read either potentiometer. How do I switch between the a/d inputs so that I can read both potentiometers? > > Thanks in advance for any help. > > Paul Duffy > > set_bit(adcon0,1); //start a/d conversion > while (!test_bit(adcon0,1)); //wait for completion You have not "inverted" the test there ? It shouldn't be "while (test_bit(adcon0,1));" ? I might might have got the logic levels wrong though... -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist