>Why do you want to turn off the A/D? will you not use it again or are >you trying to save power? Saving power wouldn't hurt (battery powered robot), but the real reason for asking is just to write good code and understand the A/D better. >I've never done it this way. Ah... that probably means I don't need/want to. Are you saying you normally just leave it on (unless it won't be used again for a while)? - Bri >> As long as I account for capacitor charge time, can I turn the A/D off >> and on at will? Right now I just leave it on... >> >> The first line in AD_RA0() leaves the A/D enabled for the life of the >app. >> The second line does a delay for A/D capacitor charge time before ADGO. >> I've placed a comment where I wonder if I could/should turn the A/D off. >> >> - Bri >> >> >> void AD_init(void) >> { >> OPTION =3D 0x87; // Set TMR0 prescaler, and 1:256 >> ADCON1 =3D 0x02; // Left justify result, 3 analog channels >> } >> >> unsigned char AD_RA0(void) >> { >> ADCON0 =3D 0x41; // Fosc/8, A/D enabled >> DelayUs(20); // Allow time for A/D capacitor to charge >> ADGO =3D 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) >> } > >I see no reason you couldn't turn it off as long as you observer all the >rules when turning it back on again. I've never done it this way. Why do >you want to turn off the A/D? will you not use it again or are you trying >to save power? > > >******************************************************************** >Olin Lathrop, embedded systems consultant in Littleton Massachusetts >(978) 742-9014, olin@embedinc.com, http://www.embedinc.com > 9 -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu