View previous topic :: View next topic |
Author |
Message |
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
[SOLVED] : PIN C2 on PIC18f46k40 |
Posted: Mon Feb 25, 2019 2:55 am |
|
|
I have a problem with Pin C2 on this PIC. I can toggle the pin as an output, but when I use input_state it always returns 0. It got me stumped, probably some stupid init I am forgetting.
Here are the test code:
Pin C0 behaves as expected by duplicating the wave on Pin B3, however Pin C2 toggles but A3 doesn't. If I change A3 and B3 around in the code, same behaviour C2 does not duplicate on the output.
Code: | while(TRUE) {
output_high(PIN_C2);
output_high(PIN_C0);
delay_ms(2);
if (input_state(PIN_C0)) output_high(PIN_B3);
else output_low(PIN_B3);
if (input_state(PIN_C2)) output_high(PIN_A3);
else output_low(PIN_A3);
delay_ms(500);
output_low(PIN_C2);
output_low(PIN_C0);
delay_ms(2);
if (input_state(PIN_C0)) output_high(PIN_B3);
else output_low(PIN_B3);
if (input_state(PIN_C2)) output_high(PIN_A3);
else output_low(PIN_A3);
delay_ms(500);
} |
Regards
Edit: Compiler 5.076
Last edited by alan on Mon Feb 25, 2019 9:49 am; edited 1 time in total |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Mon Feb 25, 2019 3:40 am |
|
|
If I remove the setup_adc_ports everything works OK.
Seems to be a problem setting up E2 as an analog input, will investigate this.
So this setup works
Code: | setup_adc_ports(sAN17| sAN29);// | sAN34)
|
and this doesn't
Code: | setup_adc_ports(sAN17| sAN29) | sAN34);
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Mon Feb 25, 2019 3:50 am |
|
|
Try one simple thing. Set the input level to use TTL rather than Schmitt
levels. So:
set_input_level_c(0);
The default is to use Schmitt levels. Not this implies that if there is enough
load on the pin that it won't actually get to 0.8*Vdd, it'll be seen as low.
It may just be that the Schmitt buffer on this particular pin has a
slightly higher threshold than the others....
*****************************************
I see you posted while I was typing that the ADC ports are causing the
problem. You don't use the PortE setups as you are doing. These have
to be given as a second parameter to the setup.
So:
setup_adc_ports(sAN17| sAN29, sAN34);
sAN34, used as the first parameter is 0x400, which accesses sAN18.
This is PIN_C2.... |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Mon Feb 25, 2019 9:48 am |
|
|
Like I originally suspected a stupid init fault.
Syntax for the ADC setup are
Code: | setup_adc_ports(sAN17| sAN29) , sAN34); |
note the comma if you want to use PORT E analogs.
Helps if you pay attention when reading the header file |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Mon Feb 25, 2019 12:04 pm |
|
|
Yes, it is not exactly 'telegraphed' is it!... |
|
|
|