Author Topic: PIC 16F877A Port unstable  (Read 10670 times)

0 Members and 1 Guest are viewing this topic.

Offline mukulkhairatkarTopic starter

  • Contributor
  • Posts: 13
PIC 16F877A Port unstable
« on: June 23, 2010, 06:53:18 am »
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 advance

MAK
 

alm

  • Guest
Re: PIC 16F877A Port unstable
« Reply #1 on: June 23, 2010, 07:14:34 am »
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)?
 

Offline scrat

  • Frequent Contributor
  • **
  • Posts: 608
  • Country: it
Re: PIC 16F877A Port unstable
« Reply #2 on: June 23, 2010, 08:22:10 am »
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).
One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. - Elbert Hubbard
 

Offline mukulkhairatkarTopic starter

  • Contributor
  • Posts: 13
Re: PIC 16F877A Port unstable
« Reply #3 on: June 23, 2010, 09:27:35 pm »
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.

Thanks

MAK
« Last Edit: June 23, 2010, 09:30:09 pm by mukulkhairatkar »
 

Offline ArtemisGoldfish

  • Regular Contributor
  • *
  • Posts: 58
Re: PIC 16F877A Port unstable
« Reply #4 on: June 24, 2010, 12:39:46 am »
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 advance

MAK

Does 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?
John, Hardware Technician, F5 Networks
 

Offline marianoapp

  • Regular Contributor
  • *
  • Posts: 67
Re: PIC 16F877A Port unstable
« Reply #5 on: June 24, 2010, 03:23:27 am »
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)
 

Offline mukulkhairatkarTopic starter

  • Contributor
  • Posts: 13
Re: PIC 16F877A Port unstable
« Reply #6 on: June 24, 2010, 05:08:51 am »
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
 

alm

  • Guest
Re: PIC 16F877A Port unstable
« Reply #7 on: June 24, 2010, 05:40:46 am »
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).
 

Offline mukulkhairatkarTopic starter

  • Contributor
  • Posts: 13
Re: PIC 16F877A Port unstable
« Reply #8 on: June 24, 2010, 05:44:11 pm »
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
 

Offline MAN

  • Newbie
  • Posts: 6
Re: PIC 16F877A Port unstable
« Reply #9 on: June 25, 2010, 01:23:24 pm »
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.
 

Offline mukulkhairatkarTopic starter

  • Contributor
  • Posts: 13
Re: PIC 16F877A Port unstable
« Reply #10 on: June 25, 2010, 04:23:50 pm »
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
 

Offline wd5gnr

  • Regular Contributor
  • *
  • Posts: 179
Re: PIC 16F877A Port unstable
« Reply #11 on: June 26, 2010, 03:07:16 pm »
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?
 

Offline scrat

  • Frequent Contributor
  • **
  • Posts: 608
  • Country: it
Re: PIC 16F877A Port unstable
« Reply #12 on: June 28, 2010, 05:22:28 pm »
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...
One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. - Elbert Hubbard
 

Offline mukulkhairatkarTopic starter

  • Contributor
  • Posts: 13
Re: PIC 16F877A Port unstable
« Reply #13 on: July 02, 2010, 05:08:57 pm »
Problem solved.

There were three ground loops in my switch network causing uncertain hic-ups. I removed the loops and now the system is stable

MAK
 

Offline scrat

  • Frequent Contributor
  • **
  • Posts: 608
  • Country: it
Re: PIC 16F877A Port unstable
« Reply #14 on: July 02, 2010, 05:23:21 pm »
Well done! 8)
One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. - Elbert Hubbard
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf