PIC 16F877A Port unstable - Page 1
Forum section: electronics / projects

author: mukulkhairatkar
author_rank: Contributor
timestamp: June 23, 2010, 06:53:18 am
content: Guys,I am fairly new to Hardware design and PIC programming currently working on PIC 16F877A. I have initialized PORTA and PORTB in input mode and PORTC and PORTE in output mode. Based on logic present the input port, I am setting logic on output port. In idle condition output ports remain zero. But sometimes it jumps to logic 1 and then back to zero. This behavior is pretty random and I am not able to understand the problem. Do you have any suggestion or possibilities I can try to stop this unwanted oscillation?I am using simple while loop to run the operation and if/else statements to compare input port logic.any help is appreciated... Thanks in advanceMAK

author: Unknown
author_rank: Unknown
timestamp: June 23, 2010, 07:14:34 am
content: I'm not that familiar with PIC, but I'll give some general suggestions. Are there pull-up/down resistors on the inputs (or did you enable the internal pull-ups)? Otherwise, noise might couple into the inputs, never let a CMOS input float. Did you decouple the power supply with a ceramic capacitor between power and ground close to each power pin? Did you connect all power and ground pins (not sure if the device you're using has multiple)?

author: scrat
author_rank: Frequent Contributor
timestamp: June 23, 2010, 08:22:10 am
content: I think it is a simple but subtle matter (but maybe you've already checked it)...It remembers to me when at school we were using CMOS logic ports and a BJT to drive a small lamp... It turned into something like a proximity sensor, since when someone got near the open input the lamp turned on. It was simply because of noise coupling with the open input of the CMOS port (and our body antenna effect).MOS devices have high input impedance, so any small power signal can create a relatively high voltage at their gate.If you tie your PIC inputs to GND or Vcc through a low value resistor (or a short) then you are sure to give your input a "0" or a "1", while if you live them floating you dont' know what their input voltage is.Take also a look at your PIC's datasheet, there you can find the schematics of all I/O ports configurations (pull-ups or other).

author: mukulkhairatkar
author_rank: Contributor
timestamp: June 23, 2010, 09:27:35 pm
content: Thank you for your help.Yes I do have all input pins active pulled up. I have only one ceramic capacitor across PIC 16F877A power pins. I did hook up oscilloscope on input pins to see any noise spike, but could't find any. Irrespective of that my output port tuns on and back to off for fraction of a second.One thing for sure that this behavior is random, there is no specific pattern, which I believe is related to noise and not a software error.I do have LM311 voltage comparator on the board which is one of the input for PORTA (Digital input not analog), Do you have any idea about how to interface this input? I highly doubt on this interface.ThanksMAK

author: ArtemisGoldfish
author_rank: Regular Contributor
timestamp: June 24, 2010, 12:39:46 am
content: Quote from: mukulkhairatkar on June 23, 2010, 06:53:18 amDoes your power supply have a pretty clean output? Like, little ripple and whatnot? I imagine that could be a problem, but it *probably* isn't. Is there any specific port that jumps around? Or is it fairly random?

author: marianoapp
author_rank: Regular Contributor
timestamp: June 24, 2010, 03:23:27 am
content: do you have the MCRL pin pulled up? if you leave it floating the pic could reset itself randomly (it happened to me a couple of times)

author: mukulkhairatkar
author_rank: Contributor
timestamp: June 24, 2010, 05:08:51 am
content: Nope. My power supply is clean, in fact I am using Linear regulator and not a switching one. It just output port PORTC and PORTE rest of the ports are fine.My MCLR pin is also pulled up with a 100uf capacitor across it.I have put up some decoupling capacitors which were absent but still the problem persists. I just doubt how much decoupling do i need to completely isolate noise out my board. I am still wondering is it just noise or just something else.MAK

author: Unknown
author_rank: Unknown
timestamp: June 24, 2010, 05:40:46 am
content: Why would you want 100uF on your reset pin (which is MCLR on the PIC if I understand correctly)? It doesn't have to wait that long to start, does it? Something like 100nF should be plenty. And you did bypass the capacitor with 4-10k or so of resistance, didn't you? Doesn't the PIC you're using have some proper power up timer so you don't need the capacitor at all?Did you rule out software bugs? If you program the software to just output a constant value on each pin, do they remain constant? Try to flash a LED on reset (long enough to be visible) so you can see if the micro is resetting. The micro won't draw a lot of current, so you don't need a lot of decoupling capacitance if your power source is stable, lead length is more important than capacitance (100nF ceramic should be fine, plus some small electrolytics before and after the regulator). Try powering it from a 9V battery to rule out conducted power supply noise. How did you build the circuit, on a solder less breadboard with long wires everywhere? Are there any noise sources like fluorescent lights close by? Try turning these on and off to see if it makes any difference (make the problem go away or trigger it).

author: mukulkhairatkar
author_rank: Contributor
timestamp: June 24, 2010, 05:44:11 pm
content: Initially, my capacitor was 100nf, and with trial and error I put up 100uf and found that the port oscillation was drastically reduced. The capacitor is bypassed with 1k resistor. The only thing MCLR requires is that it should be pulled up, I know its a delayed reset but it works.With the software, I tried different techniques of programming and putting up simple port initialization, which works but still port becomes unstable after a while.I changed my PIC chip (which is 40 pin DIP) and made significant difference. Still, the problem is not 100% solved.MAK

author: MAN
author_rank: Newbie
timestamp: June 25, 2010, 01:23:24 pm
content: What does it mean "pretty random" ?Check your software. If it enables WDT (Watch Dog Timer) and doesn't reset it while in loop, WDT reset will occure. But in this case signal changes (0->1) will be periodical.

author: mukulkhairatkar
author_rank: Contributor
timestamp: June 25, 2010, 04:23:50 pm
content: Pretty random means unpredictable, I am not able to get any pattern of PORT C and E jumping 0->1->0 for fraction of a second. My WDT is disabled.I am using if/else statements for reading inputs and setting out put ports...is that correct? or I should use any other technique??MAK

author: wd5gnr
author_rank: Regular Contributor
timestamp: June 26, 2010, 03:07:16 pm
content: I would give myself some indication of a reset. For example, toggle an unused output briefly and hook it to a scope on single sweep. Or if you don't have a scope, turn an LED on for 1/4 second on reset. I would guess that your program is resetting for some reason and the high you see is the pull up resistors while the chip switches from output -> input -> output.Happened to me before. You say the WDT is off, but other things can do a reset. Brown out, stack problems, unhandled interrupt. What language are you using?

author: scrat
author_rank: Frequent Contributor
timestamp: June 28, 2010, 05:22:28 pm
content: Why don't you post your code and configuration bits (in the case you set them using MPLAB config window) ?It would be much more easy to understand...

author: mukulkhairatkar
author_rank: Contributor
timestamp: July 02, 2010, 05:08:57 pm
content: Problem solved.There were three ground loops in my switch network causing uncertain hic-ups. I removed the loops and now the system is stableMAK

author: scrat
author_rank: Frequent Contributor
timestamp: July 02, 2010, 05:23:21 pm
content: Well done!