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 16f877 led test circuit

Status
Not open for further replies.

spirosd

New Member
I am new to electronics and I am trying to use a 16f877 to pulse 4 leds. The problem that I am facing is the circuit rather than with the code.

Directly connecting the leds to portb results to the desired result but after a few seconds the pulsing stops. If I apply slight pressure the the pic the pulsing starts again. Looking on the web one possible reason was 'noisy' (is this the right description) power supply. I added .1 uf caps to both VDD pins of pic; with no success.

Now nothing works and I suspect that I have damaged the pic. I have tried with a new pic and adding 1k resistor to the PORTB pins (thinking that possibly I have damaged the original pic by sourcing too much current) but the leds do not pulse.

I have checked the program (using C and Hi-Tech C to generate the hex code) using a simulator (gpsim) and I believe the code is correct. The power supply that I am using is a old computer PSU - measured the output voltage at 5.7V.

Is there something else that I should check / try? As I mentioned earlier I am new to both electronics and pic. Your help would be greatly appreciated.
 
You should have put a resistor in series with each led (330 ohm or so).to limit the current...
Not dooing so can damage the pic and the led's. Now, a pic is not so easy damaged so there's a big chance that only the leds are defective...
 
go to

this website has great pic tutorials

the first tutorial is for LED flashing. although the code is written for the PIC16F628 but u can change the code for the 877 by following the instructions on the changes page

as for the noise in power supply. the author of the above mentioned tutorials recommends using 9V batteries. that way when u r troubleshooting the circuit u have cleared one culprit out of the way (ripple in the supply)

i hope that helps
 
Thank you both for your replies ...

I tested the leds and they are working correctly ... I tried a new pic with 1k resistor in series and nothing then i tried with 470 ohms a heard a puf and the reasuring smell of a burned component ... :oops: ... at least I know that this pic is gone. Then tried the old one and all the leds lit up (instead of pulsing) .... That one is also gone ... :cry:

An expensive lesson ... but as they say ... you can not make an omellete without breaking eggs ... be positive as they say. How can I prevent this from happening again? (I now have 2 nice souvenirs :lol: )
 
can you make a drawing of how you connected the hole setup?

If you fry a pic so hard that the magic smoke comes out of it then it's likely you connected something else wrong then the leds.
 
I have a attached a picture of the circuit.

Thank you for your help Exo.
 

Attachments

  • dsc00027.jpg
    dsc00027.jpg
    58.8 KB · Views: 1,845
spirosd said:
I have a attached a picture of the circuit.

It's hard to tell how it's wired from a picture of a breadboard, but that looks really horrid!.

I'm presuming the device to the left is a 5V regulator, if so it hasn't got any capacitors round it, so it's very likely to be oscillating.

Secondly, the crystal and two capacitors should be as close as possible to the PIC pins - you've got them pretty well as far away as possible!.

If you visit my tutorials, I have a veroboard design for a 16F877 processor board - breadboard isn't really very suitable for designs like this. All the boards in the tutorials are actual practical boards, and have been tested with the code supplied - as already suggested, I also give advice on using the 877 instead of the 628.

As also has been suggested, it's really difficult to kill a PIC - I've put them in the wrong way round before, and burnt my fingers on them, but haven't managed to kill one (yet!).

But follow my tutorials, use a small 9V battery as a power source (not a multi-amp mains PSU), and you shouldn't destroy many components (or any!).
 
Check the upper VSS and VDD connections (pins 32 and 31) they're off by 1 pin. You're putting VDD on VSS and VSS on RD7.

I don't really see how the voltage regulator is connected (if it is one). What power supply do you use and where do you connect it...
 
You need a 3.9K resistor from pin 1 to +5V (MCLR)

I've seen this kind of erratic behavior and thats been the cause. Without it your PIC is resetting, bring your hand near the PIC changes the charge on pin 1 and makes it work ok for a few seconds.
 
Thanks to all for their time in helping me with this.

I purchased a new pic (to make sure that all is well :D ) and following Nigel's advice I have a new circuit, hopefully less horrid (still using the breadboard though).

From what lavenatti mentioned, I RTFM and on page 151 (electrical characteristics) it mentions on a footnote possible spikes on MCLR pin can be counter acted by placing a 50-100 Ohms resistor and sink to VSS (which is the approach that I took (using a 68 ohms resistor).

Now ... program the pic (using pikdev on linux ... and verifying that all is well) nothing happens :oops: !!!

I am really confused!! Using gpsim I can verify the very simplistic code that I am using ... so the error, I hope, is either in my circuit set-up or in the way in which the pic is programmed by myself.

Thank you all for helping me get off the blocks
 
i saw a circuit somewhere which had a 1k ohm resistor in series with a 1N4148 small signal diode between the supply rail and the MCLR pin. the developer of the circuit said that this ensures the right operation of the MCLR pin during use. i just connected it like that and it worked. try using it that way.
 
samcheetah said:
i saw a circuit somewhere which had a 1k ohm resistor in series with a 1N4148 small signal diode between the supply rail and the MCLR pin. the developer of the circuit said that this ensures the right operation of the MCLR pin during use. i just connected it like that and it worked. try using it that way.
I think this setup is more for ICSP use, as the diode prevents the 13V VPP signal from flowing into the supply rail during programming.
 
What power supply did you use? Are you sure the problem lies in the circuit and not the programming stage? What programmer are you using and are you able to verify your program after programming?
 
On the hardware side, I am using a tait classic parallel port programmer. On the software side, I am using the pikdev programmer under linux.

I verify that pikdev correctly identifies the 16f877, load the program to the pic. Program on the pic is then validated (again using pikdev) and no errors are reported.

The circuit is powered by a 9V battery.
 
spirosd said:
From what lavenatti mentioned, I RTFM and on page 151 (electrical characteristics) it mentions on a footnote possible spikes on MCLR pin can be counter acted by placing a 50-100 Ohms resistor and sink to VSS (which is the approach that I took (using a 68 ohms resistor).
And indeed, you've got a resistor from MCLR to VSS (-). wich is constantly resetting your pic, you need to pull MCLR HIGH! (to +) not low.


I also notice you're using portA for the leds. In order to use portA as digital IO pins you need to turn the pic's ADC off, did you do this?
If you've got no idea what that means you might want to start using portB to begin with.

I also don't see the output of your voltage regulator (7805?) go to the upper + power rail of your test board, only to the bottom one. But it could just be outside the picture.

Other things that could prevent the pic from running: Did you select the right oscillator in the configuration word? Are you sure your software is without error?
 
You are also using the analog pins on port a. This could cause you a problem as well if they are not configured correctly (as digital output pins). Try one of the other ports.
 
Success !!! :D It's alive!!

Thank you all very much for the help that you have given me. Exo you were right ... ( :oops: the shame I had even read the manual ....) once I attached to the high instead of the low everything just worked as advertised.

Now to sort out serial and interrupts ....

Thank you all for bearing with my stupidity and for your help and time.
 
Hardware or software

What if you post the code? A simple picture allowed to tell many things about your hardware.

Lot of talking can be easily replaced / saved by posting code.


Besides the breadboarding most probably you have wrong code or just simply omitted to inizialize some registers.

At this stage, for a so minimal / basic use like blinking LEDs, with so many peripherics as the 16F877 has, to play safe, you should make sure that all of them are disabled, including interrupts and WDT.

Just take a tour through the Microchip's forum. Learn from them.

Buena suerte. And enjoy.

Agustín Tomás
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top