![]() |
PIC16F877 not executing?
I realize this is kind of a long shot, but I've got the PIC in a breadboard that worked perfectly fine yesterday, using the same code that worked yesterday. I pulled out a soldered contact carrying the power supply, and didn't bother to fix it until today. But after fixing it, I don't think the code is executing. For some unknown reason, the debugger is giving me an MCLR error which I can't seem to solve, but the ICD works. It downloads the code without a problem, but when I try and run it, nothing happens. When my original code (which is supposed to control the robot based on an ultrasonic sensor) did nothing, I figured perhaps I made a mistake, so I wrote something to make an LED blink, which didn't do anything either. I checked the pins with a voltmeter, just to make sure, and didn't see any change. Also, I checked the power rails, and those are fine (+5 volts). Just for kicks, I plugged the motor controller into +5 volts, and it worked fine. I checked multiple times for loose wires, and found none.
If I fried the PIC, the code wouldn't download would it? Is this a symptom of some other error? I thought the most likely thing would be that I just wasn't plugging things in the right places, on the breadboard, but I've checked that more times than I can count, and tried placing them in other slots just to make sure, and there was no change. |
Re: PIC16F877 not executing?
The MCLR statement may be meaningful. It sounds like you are pretty familiar with PICs and stuff, so if I over-simplify this response, it is only to make it useful for those less familiar with the chips.
MCLR is a master reset switch, it stands for "Master Clear Reset" or something like that. If you connect it to ground, then the whole chip resets. You will note that on many PICs it is located next the the ground pin, making it easy to short the two out using a screwdriver tip, thus making it very easy to reset the PIC. The catch is that if you don't connect the MCLR pin to something, then the voltage just kind of "floats"... in other words, it is fairly random. Yesterday it might have been high, today it might be low. To solve this problem, MCLR is typically connected to the +5 line (or whatever voltage is supplying your PIC) with a resistor. The value of the resistor doesn't really matter that much... all you are doing is making sure that the MCLR pin stays "high" except when you short it to ground. Now, to compound things just a little bit, the PIC uses many pins for many different functions... the MCLR pin, for instance, can also be used as an I/O line (although on many PICs it can only be used as an input, I believe). If you choose to use it as an input, you cannot use it as a reset... and vice versa. You have to let the PIC know whether you want to use the MCLR pin as an input or as a reset when you download your program code. You do this by toggling a configuration bit called "MCLR Reset Enable". You can either write your configuration settings into your code (overwriting your complier/assembler's default settings), or just set them via the configuration menu of your programming software. Just make sure that if you do the setting in you programming software that if you have a "reload code before programming" option that it is turned off, or you will get the default settings back again! So, my first suggestion is to connect the MCLR pin to your +5 supply with a resistor. Try that and see if it works. Otherwise turn off the MCLR Enable bit in your programming software and re-download your code to the PIC. No guarantees that this is what is causing you grief, but just a couple of things that spring to mind that might be worth checking. Jason Edit: And if that isn't enough already, the MCLR pin is also often used to set the PIC into high-voltage programming mode... your programming device quite likely pops MCLR up to 12v at the beginning of your code download. Something to keep in mind when doing in-circuit (where you don't take the chip off the board) programming! |
Re: PIC16F877 not executing?
My experience has been similar to Jason's, such that I always put about a 22K pullup on the MCLR. I can't say I've observed a MCLR error, since I don't have access to an In Circuit Debugger (I use a PICKIT 2 ICSP, but the chips I use don't support the debug feature).
The other thing I've noted is to make sure you disable the low voltage programming, else almost any noise on the PGM pin will tend to interrupt the program and cause the device to attempt to go into a programming mode. My quick test for this is if the chip At last, but I feel most likely, try connecting a 1 microfarad capacitor (I use a ceramic non-polarized) between power and ground fairly close to the power pins on the chip. I have had a number of PIC designs which would run off the power supply provided by the ICSP, but when connected to a 5 V power supply they would simply stop. The capacitor always corrected that. |
Re: PIC16F877 not executing?
Spam post reported.
|
Re: PIC16F877 not executing?
I usually use a 10K resistor to pull MCLR up. You should probe that pin with a voltmeter to see where it is. You might have a solder bridge or other short somewhere that's messing you up.
The next thing to check is that your crystal or oscillator if you're not using the internal oscillator is functioning as it should. I've seen PICs get into a strange states and do weird things when their crystal/oscillator isn't working correctly. You should see a nice, strong signal at OSC1 if everything is working. |
Re: PIC16F877 not executing?
Thanks for all your responses, if it decides it doesn't like in the future I'll certainly come back here to look. It ended up that it wanted some fuses set in the code. I'm not sure why it wanted them at first, and not later, but it fixed it.
|
| All times are GMT -5. The time now is 00:02. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi