[SOLVED] PIC working in unusual way!

Status
Not open for further replies.

Mrunal Ahirrao

Full Member level 2
Joined
Nov 26, 2012
Messages
133
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Location
India
Visit site
Activity points
2,213
View attachment 1.jpgHi all! I am trying to make PIC to work,but its working in unusual way! I have used PICs many times and have a good experience on it, but from today, I am not able to make PIC to work as usual. The problem I am facing is, I am actually developing water level controller using PIC16F628A and I have used three float sensors for it. But one sensor which is connected to Mcu's pin is behaving unusually. actually the logic is to make RB7 pin to '0' when RB1 is '0' but instead the RB7 flips to '0' just when I touch with my hand to the RB1 pin! Any help would be appreciated. I have tried changing with different ICs but faced same problem. Below is my Code and above is my PCB design.
Code:
/


sbit OLow at RB0_bit;
sbit ILow at RA2_bit;
sbit BM at RB7_bit;
sbit OHigh at RB2_bit;
unsigned short SUBS;





void main() {
TRISA=0b00100100;
TRISB=0b00000111;
CMCON =0x07;
//ANSEL=0;
//OSCCAL=0b11111100;
OPTION_REG=0b00110000;
BM=0;
//SUBSW=0;
SUBS=1;
do{
if(SUBS==1&&OLow==0)
{
delay_ms(30000); //Rechecking whether Olow==1
if(BM==0&&OLow==0){
delay_ms(30000);
if(BM==0&&OLow==0){
delay_ms(30000);
if(BM==0&&OLow==0){
delay_ms(30000);
if(BM==0&&OLow==0){
delay_ms(30000);//Recheck completed
delay_us(200);
if(ILow==1)
{
BM=1;
SUBS=0;
}
//SUBST();
}
}
}
}
}

//delay_us(200);

if(ILow==0)
{
BM=0;
SUBS=1;
}

if(OHigh==1)
{
BM=0;
SUBS=1;
}
}while(1);
}
 
Last edited:

The simple debug method is to use led on pin7 and a switch on pin1 to simulate the scenario.
 

hello,


Did you put pull-up resistors to Vdd to fix the voltage (at logical level 1) when not connected to the Zero by the switch.
you can use 2.7K up to 10K Resistor value.
internal pull up for PORT B are too high ..abd must be validate by software
 

The simple debug method is to use led on pin7 and a switch on pin1 to simulate the scenario.
I have used this method but its behaving same. the LED is getting off just when I touch the RA2 pin with my hand

- - - Updated - - -

I have used internal pullups and I have also checked voltage on that pin, it was 4.25V when I didn't touched with my hand and its, 4.18V when I touched that pin with hand. and how We can validate by software regarding internal pull ups?

- - - Updated - - -

And eventhough I changed the pin for that function in program it behaves same, only the pin that function behaves same!
 

did you check if you have earth leckageproblem..with AC power supply.
Water level.. is the recipe conneced to the earth (Ground) ?
 

Could you post a schematic of your circuit?

From what I understand of your PCB, RB1 is floating, there is no external pullup, only a couple of connectors for LEDs and sensors?

What value has the resistor in series with the Vdd supply to the PIC?
Is this a single layer PCB?

Have you got a datasheet of your sensors?
 

Check once again your power supply connection.

Check once with Blinking LED code.

Which programer you are using?
 

Hi,

avoid floating (digital) inputs.

and you have to take care of the "absolute maximum ratings". Especially with the sensor connection to "unknown" voltage levels. I recommend additional protection diodes.


Klaus
 

hmm, is it me or the code is missing any relation with rb1? i only see rb0, rb2 and rb7 in action. it seems you control rb7 with Ilow? which is ra2 pin? have you tried to simulate the code on mplab or any other tool you have on hand with correct result?
 

did you check if you have earth leckageproblem..with AC power supply.
Water level.. is the recipe conneced to the earth (Ground) ?
Earth is good and as a sensor its magnetic float sensor!

- - - Updated - - -

Actually I am using internal pullups and its a 1N4148 diode which in series with VDD and not a resistor! and yes its single layer PCB.

- - - Updated - - -

Check once again your power supply connection.

Check once with Blinking LED code.

Which programer you are using?

I have checked! and I am using JDM programmer and software is PIC PGM

- - - Updated - - -

Hi,

avoid floating (digital) inputs.

and you have to take care of the "absolute maximum ratings". Especially with the sensor connection to "unknown" voltage levels. I recommend additional protection diodes.


Klaus

actually none of them will be floating inputs they are internally pulled up and regarding "absolute maximum ratings", its correct I have checked. And sensor I am using is simple float switch which senses water level and sends logic "0" when water level is low.

- - - Updated - - -

actually before RA2 was for ILow I used RB1 for ILow so the code is updated one sorry for inconvenience, and yes you got what I meant to say! and one more thing I saw that when I put my multimeter probe on that ILow pin and then touch with hand it works correctly! means its not making RB7 to "0". I am using MikroC for PIC. and I have simulated it and it works correctly.
 
Last edited by a moderator:

One possibility, you do actually have the 5v connected to the power pin of the PIC? If you don't you could be powering the PIC via one of its inputs which would explain its strange behavior. Measure the 5V with a load. Also the 0V goes to the PIC via a resistor? check this. Why would you want to connect the ground of the PIC via a resistor? If you were to show the circuit it would be a lot easier to help you.
 
Last edited:

What is result for blinking LED code?? did you get same on time and off time

There is any oscillator settings or configuration bits in PIC PGM????
 

If you are using a diode on the Vdd to the PIC you need to add decoupling capacitor(s) on the inside of the diode. 100nF in parallel with 1-10uF should be good.
 

Yes I have connected 5V to VDD and I have measured its correct 5V. And I have not connected ground of PIC via a resistor, its a jumper.

- - - Updated - - -

Looks like an EMI noise issue. Try grounding. Direct or with a cap..
EMI? so how should I ground? where should I ground?to pin which is giving error? and will 0.1 uf cap would suffice?

- - - Updated - - -

What is result for blinking LED code?? did you get same on time and off time

There is any oscillator settings or configuration bits in PIC PGM????

LED was blinking at time. and yes there configuration bits in PIC PGM which I have already defined during creating project in mIkroC. They are:
Oscillator=HS
Watchdog timer=off
Power up timer=enabled
Master clear enable=disabled
Brown out detect=enabled
Low voltage program=disabled
Data EE read protect= disabled
Code Protect=disabled
and these config bits are also written to Chip during programming.

- - - Updated - - -

If you are using a diode on the Vdd to the PIC you need to add decoupling capacitor(s) on the inside of the diode. 100nF in parallel with 1-10uF should be good.
yea this is something I was unknown about. I will try.
 

Check once again The same oscillator selection in your code and programmer configuration and your hardware...
 

Ok I will... thank you.. And I have followed Sunnyskyguy's Idea its working it seems! but is problem solved? so we shall consider this unusual behaviour of PIC was due to EMI?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…