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

pic 18LF series port a

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



Joined: 18 Apr 2006
Posts: 45

View user's profile Send private message

pic 18LF series port a
PostPosted: Mon Mar 05, 2018 11:55 am     Reply with quote

Hello i am using 18lf252 with 5V.
I have 5 digital sensors on porta.
Regardless of sensor output, reading from pin a2 is "1" so !input(pin_a2)=0 all the time.
All sensors are working. I checked pic pins with voltmeter.
Code:

#include <18lf252.H>
#fuses XT, NOWDT, NOPROTECT, NOBROWNOUT,PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

void main(){
int sensor;
SETUP_ADC_PORTS(NO_ANALOGS);
SETUP_ADC(ADC_OFF);
while(1){
      sensor=!input(pin_a5)+2*!input(pin_a4)+4*!input(pin_a3)+8*!input(pin_a2)+16*!input(pin_a1);
      printf("Sensor=%u\r",sensor);
      delay_ms(550);
      }
         }

version 5.065
is there a special situation with 18lf252 porta ?
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 05, 2018 12:08 pm     Reply with quote

I just downloaded a datasheet for it, nothing 'special' though you have disabled the ADC, which is good.

this code..
Quote:
sensor=!input(pin_a5)+2*!input(pin_a4)+4*!input(pin_a3)+8*!input(pin_a2)+16*!input(pin_a1);
printf("Sensor=%u\r",sensor);

..may be in error. Maybe it requires some brackets '()' to configure the data the way you want it to.

You might just read the port and print as hex format. As long as all 5 inputs have pulldowns shorting 1 pin to VDD should give you it's 'binary weight'. 1,2,4,8,16

jay
luckyluke



Joined: 18 Apr 2006
Posts: 45

View user's profile Send private message

PostPosted: Mon Mar 05, 2018 12:18 pm     Reply with quote

i tried with brackets no difference

same code works ok with 18f2520
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 05, 2018 1:50 pm     Reply with quote

Make a short test program that only checks that pin.
Put a scope or a voltmeter on that pin. Does it still fail ?

It could be the external circuit or it could be the PIC.
Does the external circuit supply the correct logic level voltages ?

Replace the external circuit with a different one. Does it still fail ?
Switch the external circuit to a different pin. Does it now work ?

If it's not the external circuit that is causing the problem, it's got to
be a defective PIC.
luckyluke



Joined: 18 Apr 2006
Posts: 45

View user's profile Send private message

PostPosted: Mon Mar 05, 2018 3:13 pm     Reply with quote

i tried sensor output with b0 and a0 result was same.

i cut sensor cable and directly gave - and + to a2 from circuit it worked and this connection works with a0 and b0 as well.

interestingly there is same sensor with same voltage levels (5v for 1 and 1,32 volt for 0) on a4 and there is no problem.

i thought somehow there is a problem with a2 sensor, i made a parallel cable from a4 sensor. result a2 is not working but a4 keep working.

if pic didnt like 1.32v for 0 how a4 works?
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 05, 2018 3:31 pm     Reply with quote

OK, let's do a 'basic PIC test'

Do NOT use your 'sensors' !

Connect a 10K resistor to the pin that is A.0
Do the same for the other port pins.

Code a simple program
Code:

main()
while(1) {
valuea=input_a();
printf("Port A value = %x\r",valuea);
delay_ms(1000);
}


Hopefully this compiles and you need to setup the PIC of course BUT everytime you apply +5 (VDD) to one of the input pins, it should show up on the PC terminal program screen.
Obviously you need some TTL<>USB adapter, but I assume you have all that working.

This basic test will confirm if the PIC is reading correctly.
You should also tell us what these 'sensors' are, make/model/part number.

Jay
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Mar 05, 2018 3:52 pm     Reply with quote

1.32V isn't a logic 0, and that's your problem. Just because it works with one of the PIC's pins doesn't mean that, by extension, it should work for others.

Take a look at page 267/332 of the PIC18(L)F252's data sheet, table 22.2 DC Characteristics. Parameter D030/D030A, Vil (input low voltage), absolute max 0.8V for 5V operation.

1.32V is "no man's land" in that it's not a logic low and it's not a logic high. By definition it's not either, so you can't say that its one or the other.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 05, 2018 4:29 pm     Reply with quote

Also, the two pins have different input buffer technologies. Pin A2 is a
TTL input, but pin A4 is a Schmitt Trigger input. The Vil voltages for these
two types of inputs are different, and can vary over temperature. Also,
the TTL input will have a linear response if you get above the correct
Vil voltage boundary.
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Mar 05, 2018 5:07 pm     Reply with quote

I figured it was probably a ST input but looking up Table 22.2 was the extent of the charity I felt like doing today.

Laughing
luckyluke



Joined: 18 Apr 2006
Posts: 45

View user's profile Send private message

PostPosted: Mon Mar 05, 2018 5:34 pm     Reply with quote

I have found the problem.
I am using carrier board for sensors and 1.3v caused by indicator led.
Since previous ones did their job i didn't check last party which has bad design.

I removed led now it is ok.
Thank you guys.
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