Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC Stability

Status
Not open for further replies.

rackley

New Member
I'm having problems with keeping my PIC stable. I've reduced my program down to just some basics: Interrupts, pushbutton inputs, and LCD output. It sometimes resets and sometimes just locks up. It can run anywhere from 10 minutes to 6 hours, but it always does it.

My power supply is rock solid as far as I can tell. What are the typical culprits to look for when your PIC starts rebooting/hanging?

Thanks,
Ray
 
1. Got enough capacitance on the voltage reg?
2. Got a ceramic cap on the Vdd/Vss pins?
3. bad code

Which PIC?
Enabling LVP and leaving the pins floating will cause unpredictable hangs and resets.
 
Hmm. LM2937 (500ma, 5v regulator), two 47uf 100v electrolytic caps on the +14v side right next to it, a 10uf 25v electrolytic on the +5v side right next to it, and a 0.1uf 50v ceramic cap right by the PIC power/gnd pins of the pic. Plus I have a diode to protect against reverse voltage hookup and a 16v TVS diode for transients on the +14v side. I don't have an ocilloscope but my cheap voltmeter reads 5.00v supply :D

My LCD is 45ma max draw (datasheet), plus the PIC. I'm driving just one transistor on/off with a 549ohm base resistor, so the power supply shouldn't be very taxed.

I *think* that should be good, but I'm not an electrical engineer so I'm not 100% sure. Bad code is possible but not likely as I've had this problem with both Proton and microBasic. I've programmed the simplest portb on/off routine to turn on/off an LED and it still hangs and/or resets.

PIC is 18F452.

LVP is disabled...

I'm also using a ceramic resonator @8mhz and not a crystal.
 
Howdy neighbor,

Have you wired your circuit on a breadboard? If so, what crystal frequency? Would you like me to look at your circuit (I live in Westland)?

Happy Holidays... Regards, Mike
 
What are the typical culprits to look for when your PIC starts rebooting/hanging?

I have never had a PIC hang although it may fail to boot if you have an unfiltered power supply. So far, all of my problems with PICs had been ultimately been traced to bad code.

What programming language are you using?

Have enabled the watchdog timer?

Did you enable reset on stack overflow/underflow?

How did you program your PIC? Was the voltage between 4.75-5.25V when programmed?

Like you, I am also using the PIC18F452.
 
What do you have on the reset pin?

Sure that transistor's collector current doesn't short out the supply?
 
The transistor emitter and collector switch the ground for an external load, so there's no way they could be shorting power. Right now they aren't hooked up to anything (this is all on a PCB, not a breadboard).

On the reset pin I have two connections - one to power with a 4.7k resistor which gives me 4.99v at run time. The other connection bypasses the resistor and goes to a 5-pin header which goes to my MAX232 interface for ICSP.

Programming language: mikroBasic. Good language to write in, but it has it's fair share of bugs. I wouldn't be overly shocked if there was a problem with the fuses or a bug in the compiler. I'm working on getting my programmer hooked back up so I can check my fuses, and then probably re-write and verify my bootloader & fuses, but I'm running into software problems (all new computer hardware and OS, reloaded a few days ago...another headache in itself :D )

WDT is off, stack overflow/underflow reset SHOULD be off, but like I said I need to get back in and reverify with the programmer.

Voltage was supplied by the programmer which I rarely use execpt to throw a bootloader on my chips. But I'll definitely monitor the voltage when I get everything hooked back up and re-flash it with the bootloader. It's supposed to get it's voltage from the USB port.

So far I have...check LVP (I think I have it turned on in order to do ICSP) and reset on stack over/underflow fuses and monitor voltage when flashing.
 
Bootloading also programs the chips and so you have to make sure the supply voltage is within limits when downloading firmware with the bootloader. I usually add a program checksum checker on bootup to see if there is a change in bits in the firmware. It did catch a case like this when I downloaded to a PIC18F452 with 5.5V supply.
 
The plot thickens. I'm convinced something in my circuit or PCB is jacked up somehow.

My LCD displays garbage characters now, although I can see it refresh certain areas and draw odd characters when I push buttons (pushing the buttons is supposed to draw text).

The PIC still does output port on/off switching every five seconds as it is supposed to, and I can hear the relay clicking like clockwork. (The relay is switched via transistor of course)

The LCD is on the other end of a ~2.5 foot ribbon cable and is meant to be part of a hand-held display/control unit. I could understand if the cable length would cause signal problems, but it seems to work fine for 200 or so hours and then it does this. This is the second time this has happened, with two revisions of prototype boards, and all new hardware on each. LCD output works fine for ~200 hours then gets messed up.

I've tried replacing the LCD and the new one shows garbage as well. I've reflashed the PIC and even replaced the PIC with a new one that was programmed (without bootloader) and verified sucessfully. Same garbage on the LCD. Removed my I2C stuff from my processor board, removed most of my inputs, removed most of my caps, and replaced my resonator. Same deal. There really isn't much left on my processor board execpt for one transistor output and a few ADC inputs. The only thing on the handheld part is a few pushbuttons, the LCD and a few resistors to control backlight and contrast, both of which are fine.

Is there anything that may cause this? Power supply problems of some sort? Data signal coming out of the PIC(s) corrupted by some means? It perplexes me that the relay output works perfectly, which means the PIC is indeed running OK, but the LCD output gets all garbled. And it's not an LCD problem because I replaced the LCD. :shock:

Thanks,
Ray
 
rackley said:
It perplexes me that the relay output works perfectly, which means the PIC is indeed running OK,

Yes. PIC is definitely working. Just make sure the PIC port pins for LCD do not float during operation. I do remember certain PIC port pins(RA4??) do float even in output mode.

rackley said:
but the LCD output gets all garbled. And it's not an LCD problem because I replaced the LCD. :shock:

So it is not hardware problem as you have replaced both PIC and LCD. But have you eliminated software communication problems, especially when you are using an exceptionally long LCD connecting cable?

Most connecting cables for LCD are short, within a few inches. A 2.5 feet cable might work, but would require the programmer to reduce the clock speed of the data transfer between the two.

To prove/disprove this just fit a 1MHz crystal/resonator and test the circuit. If it works then your problem is comunication timing.
 
This sounds like it may be a software bug.
Some things to check.
Do your interrupts save and restore everything they change. (TBLPTR INDF PROD etc)
Do you access the LCD or other hardware in both your main code and interrupt.
Look at each instruction in your main code and ask yourself what would happen if an interrupt came along now.
Do the same for any low priority interrupt routine.
What happens if a computed goto gets a wrong value.

You have stack over/under on - do you check the status of these bits on reset?
The LCD being garbled could be due to the pic doing a software reset. Can you tell if a software reset has occurred?

Can you reduce your code even further so that it only switches the relay?
Can you make it run without interrupts?
Can you try a small asm file to eliminate the complier?

Mike.
 
eblc1388 said:
rackley said:
It perplexes me that the relay output works perfectly, which means the PIC is indeed running OK,

Yes. PIC is definitely working. Just make sure the PIC port pins for LCD do not float during operation. I do remember certain PIC port pins(RA4??) do float even in output mode.

rackley said:
but the LCD output gets all garbled. And it's not an LCD problem because I replaced the LCD. :shock:

So it is not hardware problem as you have replaced both PIC and LCD. But have you eliminated software communication problems, especially when you are using an exceptionally long LCD connecting cable?

Most connecting cables for LCD are short, within a few inches. A 2.5 feet cable might work, but would require the programmer to reduce the clock speed of the data transfer between the two.

To prove/disprove this just fit a 1MHz crystal/resonator and test the circuit. If it works then your problem is comunication timing.

I'm using RA4 as a normal analog input, so that's not the culprit although it was a good guess. RA4 gets a lot of people :) So the pins shouldn't be floating, although I don't know how I could check that with my el-cheapo voltmeter.

As far as the communications timing.. does the speed of the PIC and LCD communications vary depending on the PIC's clock rate? I'll test a 4mhz resonator as that's the slowest I have in my parts bin right now. If that doesn't fix it I will also cut down the cable to a short length just for testing.

The part of the puzzle that doesn't quite fit is that I don't understand why it works for so long (the LCD that is, ignoring the PIC) without any hint of problems and then all of a sudden it will only print garbage and never print correctly. It's odd.. You would think it just wouldn't work in the first place.

Thanks for the ideas! I'll let you know how it goes.
Ray
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top