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

[SOLVED] : PIN C2 on PIC18f46k40

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



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

[SOLVED] : PIN C2 on PIC18f46k40
PostPosted: Mon Feb 25, 2019 2:55 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 25, 2019 3:40 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 25, 2019 3:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 25, 2019 9:48 am     Reply with quote

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 Embarassed
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Mon Feb 25, 2019 12:04 pm     Reply with quote

Yes, it is not exactly 'telegraphed' is it!... Smile
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