CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Should I set analog pins low when not in use?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Hampton



Joined: 08 Jun 2006
Posts: 12

View user's profile Send private message

Should I set analog pins low when not in use?
PostPosted: Thu Jun 15, 2006 2:04 pm     Reply with quote

In my program I take an ADC sample every so often. Using a PIC18LF2525. Is it advantageous to turn off the adc and set the pins low in between samples? Here's the pseudo code for what I'm trying to do:

Code:
while(1)
{
  setup_adc_ports(AN0|VSS_VDD);
  setup_adc(ADC_CLOCK_DIV_32|ADC_TAD_MUL_20);
  set_adc_channel(0);
  delay_us(4);
  read_adc();
  setup_adc_ports(ANALOG_OFF);
  output_low(PIN_A0);
 
  sleep();
}

If I set pin A0 as an output while the PIC is sleeping do I need to make it an input when I enable the adc, or does the setup_adc_ports() function do that internally?
Ttelmah
Guest







PostPosted: Thu Jun 15, 2006 2:53 pm     Reply with quote

The signal driving the ADC inputs, needs a low impedance if the value is to be 'right'. If you set the pin low, you will be shorting that signal to ground, possibly leading to overheating, and certainly leading to wasted power.
You would need to set the signal line _back_ to being an input, or it won't work at all, but you need to work out if you really want to do this at all...
This type of approach is used, on signals where (for example), a capacitor is charged by an external source, and discharged by the processor gate.
The approach would then be:
Code:

while(1)
{
  setup_adc_ports(AN0|VSS_VDD);
  setup_adc(ADC_CLOCK_DIV_32|ADC_TAD_MUL_20);
  output_float(PIN_A0);
  set_adc_channel(0);
  //You need more than 4uSc delay - typically 10uSec minimum,
  //check the data sheet...
  delay_us(4);
  read_adc();
  setup_adc_ports(ANALOG_OFF);
  output_low(PIN_A0);
 
  sleep();
}

Notice the 'output_float', which turns off the pin drive, and the comment about the delay.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group