View previous topic :: View next topic |
Author |
Message |
luckyluke
Joined: 18 Apr 2006 Posts: 45
|
pic 18LF series port a |
Posted: Mon Mar 05, 2018 11:55 am |
|
|
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
|
|
Posted: Mon Mar 05, 2018 12:08 pm |
|
|
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
|
|
Posted: Mon Mar 05, 2018 12:18 pm |
|
|
i tried with brackets no difference
same code works ok with 18f2520 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 05, 2018 1:50 pm |
|
|
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
|
|
Posted: Mon Mar 05, 2018 3:13 pm |
|
|
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
|
|
Posted: Mon Mar 05, 2018 3:31 pm |
|
|
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
|
|
Posted: Mon Mar 05, 2018 3:52 pm |
|
|
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
|
|
Posted: Mon Mar 05, 2018 4:29 pm |
|
|
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
|
|
Posted: Mon Mar 05, 2018 5:07 pm |
|
|
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.
|
|
|
luckyluke
Joined: 18 Apr 2006 Posts: 45
|
|
Posted: Mon Mar 05, 2018 5:34 pm |
|
|
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. |
|
|
|