PDA

View Full Version : 16F877 Wackiness



Dino308gt4
- 13th October 2009, 15:30
I've got a strange problem with a PIC. When I set a pin high, say PORTB.7, then try to bring it low after a second or two, the pin will stay high. This is the first time I've seen this after a few years of using PICs.

This happens with PORTA and B. Maybe the others. The strange part is that the pins will work fine for a while, then stay high. This PIC was working ok for a few months, now this.

I've placed the PIC in a basic circuit to test it. (The same basic circuit I've been using for years)

Here's the code I'm testing with. Has anyone ever had this happen?



mainloop: High PORTB.7 ' Turn on LED connected to PORTB.7
Pause 1000 ' Delay for one second

Low PORTB.7 ' Turn off LED connected to PORTB.7
Pause 1000 ' Delay for one second

Goto mainloop ' Go back to loop and blink LED forever
End

' PORTB.7 stays high.
' If I re-program it a few times, it comes back for a while.

Melanie
- 13th October 2009, 18:52
I have seen PortB.7 on an 18F2420 when used as an INPUT read LOW (internally) and stay low despite external pull-up Resistors, Car Jacks and Cranes pulling the pin up (externally a scope shows the pin correctly as HIGH). Restarting the PIC causes the pin to read HIGH (as it should) but once pulled low it locks LOW until you restart again. Erasing and Reprogramming the PIC (with exactly the same program) clears the problem. This anomally has appeared on about 70-80 PICs out of about 1500 for this product (but only in the last two years) and that pin is used in less than 1% of total. I've not had time to investigate further as the particular product it goes into is pretty much at end-of-life.

I mention the above, because the 18F2420 is part of the family progression of the 16F876/877.

Try Erasing and Reprogramming the PIC.

Also have you remembered to set TRISB.7 for OUTPUT?

Dino308gt4
- 13th October 2009, 21:07
That's good to know that I'm not the only one to experience this. I've ordered a few new PICs.

I'll reprogram and set TRISB.7 = 1 as well.

Thank you.

Dino308gt4
- 13th October 2009, 21:35
I mean TRISB.7 = 0

Dino308gt4
- 14th October 2009, 02:35
I found the problem. My 9V battery was low. I swapped it for a fresh one and that fixed it. I can duplicate the problem by swapping in the old one.

Now my next question. What should I use to power my ciruit? I'm using a 7805, and I'm driving a couple of servos, so I kill the 9V batteries quickly.

I looked at a few 9V AC to DC power supplies that I had lying around, but not enough amps I guess. The servos don't move like they should. A fresh 9V drives them at at first but run out quickly.

mackrackit
- 14th October 2009, 09:33
I found the problem. My 9V battery was low. I swapped it for a fresh one and that fixed it. I can duplicate the problem by swapping in the old one.

Now my next question. What should I use to power my ciruit? I'm using a 7805, and I'm driving a couple of servos, so I kill the 9V batteries quickly.

I looked at a few 9V AC to DC power supplies that I had lying around, but not enough amps I guess. The servos don't move like they should. A fresh 9V drives them at at first but run out quickly.
So many options...
A 9 volt Wall Wart with a 500ma output will do just about everything the 7805 will handle. I keep a few 12 Wall Warts around for a quickie. A capacitor across the rails is sometimes needed as some of the Warts are pretty dirty.

A battery pack with 4 AA rechargeable and no regulator. Non rechargeable have to high voltage to run straight.

If you are going to be doing this often (working on PICs and things) a good bench top power supply is the answer.

Whatever you use, be sure to have a a fuse, smaller the better, as near to the source as possible.

financecatalyst
- 14th October 2009, 20:53
Hi
I have jumped on to use a 16F877A, Its the first time I am trying to use an external oscillator : Can you please give me the values you have used for the capacitors which are Grounding the Osc1 & Osc2. I have an 2 Pin ceramic 4MHz Oscillator connect between Osc1 & Osc 2
Thanks

Dino308gt4
- 14th October 2009, 21:32
Hi
I have jumped on to use a 16F877A, Its the first time I am trying to use an external oscillator : Can you please give me the values you have used for the capacitors which are Grounding the Osc1 & Osc2. I have an 2 Pin ceramic 4MHz Oscillator connect between Osc1 & Osc 2
Thanks

I use a pair of 22pf caps.

financecatalyst
- 15th October 2009, 00:44
Thanks for the input. I have followed and something very strange is happening :

I am using an external oscillator 4MHz. My program simply toggles one pin every 30ms.
Problem is that I see sometimes the toggling if I touch the PIC,leg of the capacitor (earth) or touch the bench the circuit is left on and sometimes it works fine and sometimes the led is just on constantly.

I have never ever seen this happening with any PIC I have used till now. What could be the reason for this??? Any advise ???? :o