Previous in Forum: Uni-directional Vs Bi-directional transformer   Next in Forum: Street Lights Poles
Close
Close
Close
8 comments
Rate Comments: Nested
Member

Join Date: Mar 2008
Posts: 9

Help on PIC 16f877a crystal problem

03/24/2008 2:05 PM

currently i using a PIC 16f877a to control my LED from a switch . i have make 1 switch to control over my 5 LED .

my problem is i not sure which oscillator to use and i have try the RC Oscillator without using any crystal and it work. but with a random timing delay and not work on time .

once i use other Oscillator like HS Oscillator with 20 MHz connected to my PIC it work with fast speed all LED blinking . which i just want the LED on once i switch on and off once i switch off

my code is as below

void main()
{


while(1)
{
if ((!input(pin_a0)) == 0)
{
Output_high(pin_c0);
Output_high(pin_c1);
Output_high(pin_c2);
Output_high(pin_c3);
output_high(pin_c4);
Output_low(pin_c5);
}

if((input(pin_a0)) ==0)
{
output_low(pin_c0);
output_low(pin_c1);
output_low(pin_c2);
output_low(pin_c3);
output_low(pin_c4);
Output_high(pin_c5);

}
}
}


thank you .

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#1

Re: Help on PIC 16f877a crystal problem

03/24/2008 2:26 PM

I'm going to suggest you have another problem going on here.

First, are you using bypass capacitors at the power pins of your PIC? If not, place a 0.01 - 0.1uF cap from the power pin to the ground pin, as close to the PIC as practical.

Next, I've had problems with PICs when the reset input is floating. Tie it up (or down, whichever is appropriate) through a resistor.

Third, make sure your power supply circuit can supply the necessary current to drive all of your LEDs. 5 LEDs will draw 100mA, or more, depending on what kind you use. If your power circuit cannot supply that much, the Vcc at the PIC will drop and the chip will reset itself.

An issue with your code, generally when you are testing both cases of an input variable (pin_a0) you want to write your code so that one case has priority over the other, so that if both cases happen simultaneously - the logic doesn't hang up. For example:

if (pin_a0) = 0 then ....

else if (pin_a0 = 1) then ....

end

This way the "0" term has priority over the "1" term and will be tested first.

When you close your switch, the input (pin_a0) doesn't transition smoothly from 0 to 1 - the contacts bounce, so the data into the PIC looks like:

0000100010101011110101111101111111111111111, or similar. Since one part of your code is looking for (pin_a0), and the other part is looking for !(pin_a0) - that is, there is an extra inverter gate delay on the second term, it's possible for both terms to be true at the same instant when (pin_a0) changes.

I suggest that you de-bounce your switch input. If I recall correctly, this capability may be built into the PIC. If not, program a de-bouncing filter. (Change your code to require that the switch is open or closed for about 100mS before you change the state of the LEDs.)

Good luck!

Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#2

Re: Help on PIC 16f877a crystal problem

03/24/2008 2:27 PM

Circuit layout is critical with any crystal oscillator and load capacitor values may need adjusting. Ceramic resonators are pretty reliable, accurate and don't need load capacitors. The micro' may need configuring so that it 'knows' what sort of ascillator you are using.
The commercial products I design nearly all use 8Mhz ceramic resonators. It is only when I need an accurate Real Time Clock that I bother with a crystal.

You realy need an oscilloscope if you are going to investigate the problem with the crystal oscillator. Try Googling 'pic crystal oscillator' ...?

Hope this helps...

Del

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Member

Join Date: Mar 2008
Posts: 9
#3

Re: Help on PIC 16f877a crystal problem

03/24/2008 3:45 PM

yes i use the 100uf on the power pin as shown in picture

and i think the supply have enought power for my LED to light up

but i still donno why the led still keep blinking and give me very fast speed pulse output.

Register to Reply
Guru
Popular Science - Weaponology - New Member United Kingdom - Member - New Member

Join Date: May 2007
Location: Harlow England
Posts: 16512
Good Answers: 670
#4
In reply to #3

Re: Help on PIC 16f877a crystal problem

03/24/2008 5:06 PM

As well as 100UF you need a small ceramic capacitor say 0.1uF or 0.01uF, this is because the 100uF electrolytic will not be very good at supressing high frequency noise.

Del

__________________
health warning: These posts may contain traces of nut.
Register to Reply
Power-User
United Kingdom - Member - New Member Engineering Fields - Transportation Engineering - New Member Technical Fields - Marketing/Advertising - New Member Hobbies - Target Shooting - New Member

Join Date: Sep 2007
Location: South coast of England
Posts: 411
Good Answers: 36
#5

Re: Help on PIC 16f877a crystal problem

03/25/2008 6:30 AM

I haven't used the PIC16 family, but I have used the PIC18F family which has many similarities.

Firstly as drawn, the PIC is supplied with 5V with 4.7K in series but the reset taken direct to the 5V. I hope this is a drawing error as it won't light any LEDS if built this way.

Secondly a PIC should be quite fast enough for static logic applications using its internal RC oscillator. Configuring the clocks in these PICs can be confusing at first, there are a great many options. You need to check the clock divider ratio as this needs to be configured explicitly.

Register to Reply
Power-User

Join Date: May 2007
Location: 39°10' N 91°52' W
Posts: 237
Good Answers: 15
#6

Re: Help on PIC 16f877a crystal problem

03/25/2008 7:04 AM

this site might be able to help you as well, he also has links to pic forums.

__________________
If you don't have time to do it right the first time, when are you going to have time to do it over?
Register to Reply
Member

Join Date: Mar 2008
Posts: 9
#7

Re: Help on PIC 16f877a crystal problem

03/25/2008 1:25 PM

yes is a drawing mistake . i am very sorry about that . and thanks for the link ^^it help me a lot thank ^^

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#8

Re: Help on PIC 16f877a crystal problem

03/25/2008 3:35 PM

Here's an application note that came into my Google reader today:

http://ww1.microchip.com/downloads/en/AppNotes/93009A.pdf?from=rss

Register to Reply
Register to Reply 8 comments
Copy to Clipboard

Users who posted comments:

bhankiii (2); Chankley (1); charlie_r (1); ejida (2); user-deleted-1105 (2)

Previous in Forum: Uni-directional Vs Bi-directional transformer   Next in Forum: Street Lights Poles

Advertisement