View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 07, 2010 4:50 pm |
|
|
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
|
|
Posted: Mon Jun 07, 2010 5:20 pm |
|
|
Thanks so much!!! |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Mon Jun 07, 2010 5:37 pm |
|
|
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
|
|
Posted: Mon Jun 07, 2010 5:56 pm |
|
|
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
|
|
Posted: Mon Jun 07, 2010 7:02 pm |
|
|
It's possible. Try a new PIC. |
|
|
picj1984
Joined: 01 Mar 2010 Posts: 73
|
|
Posted: Tue Jun 08, 2010 4:11 pm |
|
|
I had a solder bridge on a3. Everything works perfect now, thanks again. |
|
|
|