Still need help with my First Microcontroller Circuit

Thread Starter

beeson76

Joined Apr 19, 2010
211
Here is my first circuit with a microcontroller. It is a PIC16F886. I have programmed the PIC using a Pickit 2 that simply lights a LED on PORTC PIN 0 (RC0). From the PicKit 2 everything works as it should. So I made up this circuit and cannot get anything. I am running off a 7.5V DC adaptor (actually 13.3V) going through a 7805 Voltage Regulator. When I don't have my chip in Voltage at output is 5 volts right on. When I put my chip in Voltage at my Voltage Regulator Output is 10.5V I have a 1uf capacitor between my output and ground on my Voltage Regulator. I have a 4 mhz ceramic resonator on my OSC1 and OSC2 (Pins 9 and 10 of my PIC). I have a .01mf capacitor between my VDD and Vss (Pins 19 and 20 of my PIC.)

Here is my program. Its pretty simple and straighforward.

Rich (BB code):
#include <pic.h>																				//Include Hitech CC Header File


__CONFIG (HS, MCLREN, WDTDIS, PWRTEN, BORDIS, LVPDIS, UNPROTECT);								//Config for PIC16F886 Master Clear Reset, High Power,

#define LED1		RB0

main()																							//Calling the MAIN Function
{																								//Start of the MAIN Function

ANSEL = 0;																						//Initialize A/D ports off
CM1CON0 = 0;																					//Initialize Comparator 1 off
CM2CON0 = 0;																					//Initialize Comparator 2 off

PORTB = 0x00;
PORTC = 0x00;																					//Clear PORTC ports.  In hex.
RBPU = 0;																						//Weak Pullups enabled on PORTB
TRISC = 0x00;																					//All PORTC I/O outputs
//TRISC = 0xFF;																					//All PORTA I/O inputs  **Commented Out**
PORTA = 0b00001000;																				//RA3 Is an input.  Same as the above line that is commented out, except I did an individual port (RA3)
TRISB = 0x00; 																					//PIC16F886 All PORTC are set as outputs
while (1 == 1)																					//The While Loop.  Loops forever
	{																							//The Start of the While Loop
//	if (RA3 == 1)																				//The If-Else Loop.  Test RA3 Port
//		{																						//The Start of the If-Else Loop
			LED1 = 1;																			//If SW1 not pressed, turn on RC0/DS1 LED
//		}																						//The End of the If part of the If-Else Loop
//	else																						//The Else part of the If-Else Loop
//		{																						//The Start of the Else Part of the If-Else Loop
//			RC0 = 0;																			//If SW1 pressed, turn off RC1/DS1 LED
//		}																						//The End of the Else part of the If-Else Loop
	}																							//The End of the While Loop
}																								//The End of the MAIN Function
Any help is greatly appreciated. This simple circuit is driving me crazy. Thanks.
 

Attachments

Markd77

Joined Sep 7, 2009
2,806
Check the regulator datasheet for recommended capacitors on the input and output. 10V on the output is abnormal and could damage the PIC (but it might survive for a short time).
 

Thread Starter

beeson76

Joined Apr 19, 2010
211
Sorry. I had my ground hooked up to the wrong "spot." I now have 5 volts coming out of my Voltage Regulator even with the chip in. I also have 5 volts at my Vdd at both spots on my chip. (Pins 1 and 20). But I still cannot get the LED to light. Any help or suggestions?? Thanks.
 

tom66

Joined May 9, 2009
2,595
It's quite possible the chip is fried, the maximum rating is only 7 volts and while I've run mine at 9 volts for a few seconds before, 10.5 volts is probably too much. If you have a spare, replace it.
 

mcgyvr

Joined Oct 15, 2009
5,394
I'm so glad I started with an Arduino.. So much easier.

Might it have anything to do with the fact that you define the LED pin as RB0 and not RC0
 

BMorse

Joined Sep 26, 2009
2,675
1) the 7805 regulator should be hooked up similar to the circuit below, Just disregard the names on the input and outputs, and you do not need the diode (1N4148), (I had posted this in another thread), but the connections for your application is the same, replace the 12 volt source with your wall wart power, and connect your circuit where it says Music Box...



2) You will need to place a 10K resistor between MCLR/Vpp pin, and Vcc, since you have this enabled in your code you need to pull up MCLR/Vpp pin to get it to run....

3) when you are running your application, are you disconnecting the Pickit2? If not, are you clicking the icon on the toolbar for the pickit2 to set MCLR High? If not, this will keep the uc in reset mode and will not run....

B. Morse
 

BMorse

Joined Sep 26, 2009
2,675
I'm so glad I started with an Arduino.. So much easier.

Might it have anything to do with the fact that you define the LED pin as RB0 and not RC0

he commented everything else out so it is negligible, LED is configured on RB0, in code he is just setting LED=1....

Unless he actually has the LED connected to RC0, then yes that could be an issue....

@Beeson: You should have the pic sinking the LED, instead of sourcing, pics do not usually like that much, so the LED should be connected to the pic pin on the cathode, then to a 330 ohm resistor on the anode, then the other end of resistor to +5....

then to turn the LED on set the pin to Low
Rich (BB code):
LED=0;   //turn on the LED
then to turn the LED off set the pin High
Rich (BB code):
LED=1;   //turn off the LED
B. Morse
 

tom66

Joined May 9, 2009
2,595
Most PICs can source and sink up to 25mA. Exceptions include the PIC24 series, which can only do 18mA, and the dsPIC33F series, which is limited to a mere 4mA, just enough for an indicator. Of course you have to remember the Rds(on) of all PIC outputs is quite poor, around 10-20 ohms, so they do dissipate power as heat, which must be limited because it heats up the chip.
 

Thread Starter

beeson76

Joined Apr 19, 2010
211
I finally got it working thanks to you guys. I am getting some kind of interference, but it could also be my breadboard isn't making a good connection on a component. It seems to work, but then go off after some time, and then I have to touch the chip to get it back on. But I am really happy the circuit it working. Again I appreciate you guys a lot!!! Your awesome.

Just a few questions to learn some more from the circuit.

This question is more of a terminology question. BMorse, when you say sinking "pic sinking the LED instead of sourcing it", what exactly do you mean when you say that. Is it simply a phrase form making a pin High (1) or Low (0). And if I understand it correctly, making a pin Low (0) simply means to ground it right??

The two capacitors on the Voltage Regulator. I have 2 caps rated at 1uf each. I understand these are called Decoupling Capacitors. What exactly do they do?

You will need to place a 10K resistor between MCLR/Vpp pin, and Vcc, since you have this enabled in your code you need to pull up MCLR/Vpp pin to get it to run....
What does this quote mean. How do I pull up the MCLR/Vpp pin? And if I understand this correctly, to reset the PIC I must ground it to ground. The resistor is there to keep the chip "seperate" from ground right until I use say a push button switch to ground it. Should the resistor come before or after the switch or does it matter.

And one last questions:

Of course you have to remember the Rds(on) of all PIC outputs is quite poor, around 10-20 ohms, so they do dissipate power as heat, which must be limited because it heats up the chip.
What does this quote mean. What is Rds?
 

Thread Starter

beeson76

Joined Apr 19, 2010
211
Well the more I mess with the circuit the more it appears that I am getting interefence from something. When I move my hand away from the circuit, the LED goes off, and will come on when I move close to it. Same thing happens when I lift certain things off the table that are close to it. Any suggestions? I know at one time I had the same problem and it turned out that I needed to turn my weak pullups on on PORTB. But I believe I already have them on.
 

Markd77

Joined Sep 7, 2009
2,806
Your resonator is quite far from the PIC. That could be the problem. Not sure how to move it much closer on the solderless breadboard.
If you only need 4MHz you could try the internal oscillator instead.
 

Thread Starter

beeson76

Joined Apr 19, 2010
211
Do you think that could be the problem with the interference. I will try to rework my circuit and try to get it down to a smaller area.
 
I agree on using the internal oscillator. I don't see a point in adding more components when you can get within 1% accuracy with the internal, free up space, and mitigate problems like the oscillator being too far from the PIC (since it's internal)
 

bertus

Joined Apr 5, 2008
22,278
Hello,

Do yopu have a decoupling capacitor (0.1 μF) accross the powerpins of the controller?
Without that spikes may get you strange results.

Bertus
 

Thread Starter

beeson76

Joined Apr 19, 2010
211
Thanks Bertus for the reply.

I have 2 capacitors (1uf each--both of them tantalum axial capacitors) across the pins on my Voltage Regulator. I have one going from input to ground, and I have one going from output to ground. I have the positive sides on my input and output sides--meaning that the positive is "nearer" my input and output instead of ground--hope that makes sense. Is that correct?
 

BMorse

Joined Sep 26, 2009
2,675
<snip>
This question is more of a terminology question. BMorse, when you say sinking "pic sinking the LED instead of sourcing it", what exactly do you mean when you say that. Is it simply a phrase form making a pin High (1) or Low (0). And if I understand it correctly, making a pin Low (0) simply means to ground it right??
Sinking merely means when the pic supplies the ground for the LED, sourcing is when it provides the V+ to the LED.... and yes turning a port output to low brings it close to ground....

The two capacitors on the Voltage Regulator. I have 2 caps rated at 1uf each. I understand these are called Decoupling Capacitors. What exactly do they do?
These caps keep the voltage regulator from resonating or ringing which could cause all sorts of problems fro your circuit....


What does this quote mean. How do I pull up the MCLR/Vpp pin? And if I understand this correctly, to reset the PIC I must ground it to ground. The resistor is there to keep the chip "seperate" from ground right until I use say a push button switch to ground it. Should the resistor come before or after the switch or does it matter.
When referring to a pin being pulled up, just means you need to connect that pin to V+ through a resistor.....

to use a reset switch, connect the switch between the resistor and the MCLR pin, tie one end of the switch to ground and keep the resistor's other end tied to V+, you do NOT want to connect the switch after the resistor, this will create a direct short on your power supply when you press the switch....



B. Morse
 

tom66

Joined May 9, 2009
2,595
Rds(on) is the effective drain-source resistance of a MOSFET. When fully on, i.e. saturated, the resistance is this figure. It's important because 20 ohms at 25mA is 12.5 mW and if you had say a 40 pin chip with 32 IOs, with each connected to an LED you'd be dissipating 400mW, too much for the chip (about 200mW is the limit.)

Make sure that MCLR is pulled high all the time. Use a 2.2k to 4.7k resistor to Vdd to do this.

Make sure you have decoupling caps as close as possible to the power supply pins on the chip, 100n will do.
 

Thread Starter

beeson76

Joined Apr 19, 2010
211
Thanks for the responses, Tom66, Bertus, and BMorse.

Sorry Bertus for the misunderstanding. On Pins 19, and 20, I have a 100nf capacitor "linking" the 2 pins. You can't really see them from the pictures, but you can see them from the first pictures I posted.

I just looked at the picture (the one looking straight down onto the board) and you can see the capacitor there. It is situated really close to the LED. Do you think I need to move it closer to the pins. It is situated about 3 "spaces" off from the pins.
 
Last edited:
Top