Still need help with my First Microcontroller Circuit

Discussion in 'General Electronics Chat' started by beeson76, Jul 13, 2010.

  1. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    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.

    Code ( (Unknown Language)):
    1.  
    2.  
    3. #include <pic.h>                                                                                //Include Hitech CC Header File
    4.  
    5.  
    6. __CONFIG (HS, MCLREN, WDTDIS, PWRTEN, BORDIS, LVPDIS, UNPROTECT);                               //Config for PIC16F886 Master Clear Reset, High Power,
    7.  
    8. #define LED1        RB0
    9.  
    10. main()                                                                                          //Calling the MAIN Function
    11. {                                                                                               //Start of the MAIN Function
    12.  
    13. ANSEL = 0;                                                                                      //Initialize A/D ports off
    14. CM1CON0 = 0;                                                                                    //Initialize Comparator 1 off
    15. CM2CON0 = 0;                                                                                    //Initialize Comparator 2 off
    16.  
    17. PORTB = 0x00;
    18. PORTC = 0x00;                                                                                   //Clear PORTC ports.  In hex.
    19. RBPU = 0;                                                                                       //Weak Pullups enabled on PORTB
    20. TRISC = 0x00;                                                                                   //All PORTC I/O outputs
    21. //TRISC = 0xFF;                                                                                 //All PORTA I/O inputs  **Commented Out**
    22. PORTA = 0b00001000;                                                                             //RA3 Is an input.  Same as the above line that is commented out, except I did an individual port (RA3)
    23. TRISB = 0x00;                                                                                   //PIC16F886 All PORTC are set as outputs
    24. while (1 == 1)                                                                                  //The While Loop.  Loops forever
    25.     {                                                                                           //The Start of the While Loop
    26. //  if (RA3 == 1)                                                                               //The If-Else Loop.  Test RA3 Port
    27. //      {                                                                                       //The Start of the If-Else Loop
    28.             LED1 = 1;                                                                           //If SW1 not pressed, turn on RC0/DS1 LED
    29. //      }                                                                                       //The End of the If part of the If-Else Loop
    30. //  else                                                                                        //The Else part of the If-Else Loop
    31. //      {                                                                                       //The Start of the Else Part of the If-Else Loop
    32. //          RC0 = 0;                                                                            //If SW1 pressed, turn off RC1/DS1 LED
    33. //      }                                                                                       //The End of the Else part of the If-Else Loop
    34.     }                                                                                           //The End of the While Loop
    35. }                                                                                               //The End of the MAIN Function
    36.  
    37.  
    Any help is greatly appreciated. This simple circuit is driving me crazy. Thanks.
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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).
     
  3. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    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.
     
  4. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    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.
     
  5. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,770
    970
    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
     
  6. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    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...

    [​IMG]

    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
     
  7. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234

    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
    Code ( (Unknown Language)):
    1. LED=0;   //turn on the LED
    then to turn the LED off set the pin High
    Code ( (Unknown Language)):
    1. LED=1;   //turn off the LED
    B. Morse
     
  8. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    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.
     
  9. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    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?

    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:

    What does this quote mean. What is Rds?
     
  10. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    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.
     
  11. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  12. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    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.
     
  13. wannaBinventor

    Member

    Apr 8, 2010
    179
    4
    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)
     
  14. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    I have removed the ceramic resonator and am now using the internal oscillator. It works fine, but I am still having interference from an unknown source. I have included a couple of pictures. Please note that the ceramic resonator is not being used in these pictures.
     
  15. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,346
    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
     
  16. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    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?
     
  17. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,346
    Hello,

    I mean a capacitor as close as possible to the Vss and Vdd of the 16F886.
    As far as I can see are that the pins 19 and 20.

    [​IMG]

    Bertus
     
  18. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    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....

    These caps keep the voltage regulator from resonating or ringing which could cause all sorts of problems fro your circuit....


    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
     
  19. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    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.
     
  20. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    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: Jul 13, 2010
Loading...