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

analog inputs sourcing too much current?

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 07, 2010 4:50 pm     Reply with quote

Quote:

setup_adc_ports(sAN0);
setup_adc_ports(sAN1);
setup_adc_ports(sAN2);
setup_adc_ports(sAN3);
setup_adc_ports(sAN4);
setup_adc_ports(sAN8);

This is not correct. The setup function is not cumulative. You need to
change it to use one call to the function, and Bitwise OR (with the |
operator) the sANx values together. Example:

Code:
setup_adc_ports(sAN0 | sAN1 | etc. );



The reason for the high current is explained in this section of the
16F886 data sheet:
Quote:

9.1.1 PORT CONFIGURATION

Note: Analog voltages on any pin that is defined
as a digital input may cause the input
buffer to conduct excess current.

Your code was only making sAN8 (the last one) into an analog input.
The rest of them were digital.
picj1984



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

PostPosted: Mon Jun 07, 2010 5:20 pm     Reply with quote

Thanks so much!!!
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Jun 07, 2010 5:37 pm     Reply with quote

And for correctness, analog (or any) inputs typically don't "source current".

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
picj1984



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

PostPosted: Mon Jun 07, 2010 5:56 pm     Reply with quote

Hey guys,

They all work now except for sAN3. It's still doing the same thing. Is it possible I did some physical damage to the PIC? (although I do have a 50 mA resettable fuse protecting the circuit).

Here is the new code
Code:

void main ()
{
 in_c2 = input_state(PIN_C2);
 if(in_c2 == lo)
  setup_ccp1(CCP_CAPTURE_RE);
 else if(in_c2 == hi)
  setup_ccp1(CCP_CAPTURE_FE);
 

 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);
 setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
 setup_timer_2(T2_DIV_BY_1,90,1);
 setup_ccp2(CCP_PWM);
 setup_adc_ports(sAN0 | sAN1 | sAN2 | sAN3 | sAN4 | sAN8);
 setup_adc(ADC_CLOCK_DIV_32);
 set_adc_channel(0);
 delay_us(10);
 reload = read_adc();
 enable_interrupts(INT_TIMER0);
 enable_interrupts(INT_TIMER1);
 enable_interrupts(INT_CCP1);
 enable_interrupts(GLOBAL);

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 07, 2010 7:02 pm     Reply with quote

It's possible. Try a new PIC.
picj1984



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

PostPosted: Tue Jun 08, 2010 4:11 pm     Reply with quote

I had a solder bridge on a3. Everything works perfect now, thanks again.
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