Connect with us

Has my PIC blown?

Discussion in 'Electronic Basics' started by Silverfox, Nov 18, 2005.

Scroll to continue with content
  1. Silverfox

    Silverfox Guest

    Hello there all,

    I am sort of new to the electronic world and wondered if any of you
    could help.

    I have a PIC16F84 and written a simple program to just turn on PIN RA0
    which is attached to an LED.

    Pin 4 (MCLR) is connected to a capacitor wich then goes to ground.
    Pin 5 is to ground.
    Pin 14 is to 5V.
    Pin 17 and 18 are to an Oscillator of 4MHz.
    Pin 19 is to and LED to ground.

    My configuration bits are:
    Oscillator : XT
    Watchdog Timer : On
    Power up timer : Off
    Code Protect : Off

    Please excuse me if any of my terminology is incorrect as I am still
    I have tested the code in simulation mode and the STATUS, TRISA and
    PORTA registers seem to be set correctly.

    The LED doesn't come on? Should I post my code?
    Could somebody point me in the right direction?

    Thanx very much in advance

  2. This will never work, you are holding the chip in reset. MCLR should go
    to +5V. Have you read the datasheet?
    These are ok.
    What kind of oscillator? Is it a 4Mhz crystal?
    There is no pin 19, it's only an 18 pin part. You must mean pin 17.
    Ok if you are using a crystal. If you are using a crystal, then you
    also need to 33pF caps connected to ground.
    PWRTE should be ON.
    Set the TRISA register 0x00 to make all the pins output. You should
    also set TRISB to 0x00 to make all those pins output as well. That way
    you don't have to tie the unused pins to Vcc or gnd. Never let input
    pins float.
    Yes, post ALL of your code. If you can successfully reprogram and
    verify the chip, then it's probably fine.
    Fix the MCLR pin and the other things I mentioned. Tell us how you are
    powering the PIC chip.
  3. Pin 16 is OSCIN and pin 15 is OSCOUT. This is where you connect the
    crystal. If you are using a canned oscillator, you connect its output
    to pin 16 and leave pin 15 open.

    Section 8 of the datasheet tells you how to hook up the oscillator and
    MCLR pin. Read it well. ;-)
  4. Quack

    Quack Guest

    Try connecting MCLR to +5v with a 4.7k resistor.

    The Oscillator you are using, what type? does it have capacitors
    inbuilt ? if not, you will have to add these.

    if it has 3 legs, the middle is usually connected to GND for the
    inbuilt caps

    if its 2 legs you will need to add the appropriate capacitors from
    these legs to a common GND.

  5. Silverfox

    Silverfox Guest

    Well firstly thank you all for your great help :) I don't know which
    to reply to.

    Well I was reading wrong data sheet to start ooops, I was reading
    PIC16F84A, but I think they are similar, but different.

    The oscillator I am using does have 3 pins, middle is grounded, sorry I
    don't know how I can tell if its crystal or not, its like a yellow blob
    on three pins. I am sorry, I am new and I am trying to learn too.

    I am powering my PIC through a 7805C voltage regulator, which is
    powered by a DC power supply.

    I am currently fixing the MCLR and other things and also reading this
    datasheet too, I will let you know how I get on.

    I really hope I don't insult any of you with these questions and my
    niaveity of this new subject to me.

    Oh and my code is:
    ; Testing how to program a PIC
    LIST p=16F84 ; PIC16F84 is the target processor

    #include "P16F84.INC" ; Include header file

    ; General Equates

    ; These are included in the "" file

    BIT0 EQU 0
    BIT1 EQU 1
    BIT2 EQU 2
    BIT3 EQU 3
    BIT4 EQU 4
    BIT5 EQU 5
    BIT6 EQU 6
    BIT7 EQU 7

    ; I/O Equates

    ; These are included in the "" file

    ; Memory Equates

    ; Macros

    BANK0_MACRO macro ; this defines the BANK0_MACRO macro.
    endm ; this is the end of the macro Bank0.

    BANK1_MACRO macro ; this defines the BANK1_MACRO macro.
    endm ; this is the end of the macro Bank1.

    ; Start and Interupt Addresses
    ORG 0H ; Change address depending on pic type,
    ; see reset vector section.
    GOTO INIT ; This is where you want the program to start.

    ; Subroutines Start here.

    INIT ; The program starts here
    CLRW ; Clears the W register.

    ; We are using bank 1 to modify TRISA which will tell PORTA to be
    BANK1_MACRO ; This will set bit 5 of the STATUS register
    ; to say to use bank 1.

    MOVLW B'00000000' ; This will set all the bits of W to 0.
    MOVWF TRISA ; This will move the contents of W to TRISA
    ; Hence, setting up PortA as outputs.
    MOVWF TRISB ; This will move the contents of W to TRISB
    ; Hence, setting up PortB as outputs.

    BANK0_MACRO ; This will set bit 5 of the STATUS register
    ; to say to use bank 0.


    END ; End must appear on the last line of the program
    ; so the assembler knows where to stop.

    Thanx again for your help
  6. Tim Duke

    Tim Duke Guest

    Hi Richard,

    Sounds like you are using a resonator, which already has the two caps that
    you need to connect to ground, so no problems here.

    Your code looks fine and should work ok. Although not a problem with most
    PIC's, it is common form to take the anode of the LED to +5v and cathose to
    the I/O pin of the micro, so that the micro sinks the current. But this does
    then mean that to switch the LED on you need to set the output pin low and
    to switch it off, set it high.

    As stated earlier, take MCLR (which is active when low (solid bar over MCLR
    denotes this)) high through a resistor of around 10k. Also make sure you
    have a current limiting resistor in series with the LED. Around 270 ohms
    will be ok.

    Set your configuration bits to :

    Osc - XT
    Watchdog timer - OFF
    Power up timer - ON
    Code protect - OFF

    I found a great book on PIC's that taught me alot about them. It's called
    PIC in Practice by D.W.Smith, published by Newnes. ISBN 0-7506-4812-0

    All the best,

  7. I don't know of any significant differences. The "A" model probably
    programs faster.

    The 16F84(A) chips are considered obsolete now. There are cheaper, more
    capable parts now that you may like better. The 16F88 has built in ADC
    and an 8MHz internal oscillator that's usably accurate.
    Sounds like a ceramic resonator then. The caps are built in on the 3
    pin models, so you should be fine. A resonator is probably accurate to
    about .5%. A regular crystal might be accurate to .005%. The resonator
    is more than accurate enough for serial communications.
    That should work fine. Be sure to use capacitors on the input and
    output of the regulator. Also be sure to feed the regulator at least 7V
    for headroom.
    Keep us informed as to your progress.
    If anyone was insulted by those questions, it certainly wouldn't be your

    BTW, what kind of programmer are you using to flash the PIC?
    You should probably go ahead and clear PORTA and PORTB as well.
  8. Silverfox

    Silverfox Guest

    Hello there all again

    Ok then, I am using MPLAB IDE 5.62 and PICSTART Plus Development

    I have some succes, thank you very much, to all of you.

    What I have got is:
    Configuration Bits:
    - Oscilator: XT
    - Watchdog Timer: Off
    - Power Up Timer: On
    - Code Protect: Off

    Pin 4 MCLR I have attached to the output of the voltage regulator via a
    4.7K ohms resistor.
    Pin 5 to ground
    Pin 14 to the output of the voltage regulator.
    Pin 15 and 16 to the oscilator. Oscilator middle pin is to ground.
    Pin 17 to cathode of LED via a 270 ohms resisitor.

    I haven't put the capacitors on the input and output of the voltage
    regulator yet. Are these put on to keep the voltage smooth in and out
    of the voltage regulator?

    I have changed the code slightly too, so that PORTA and PORTB bits are
    all set to 1 and I change PortA Bit0 to a 0 to turn on my LED.

    Next step is for me to attach another LED and get it to flash every so

    Thank you very much again for your help.
  9. The one on the output helps to decrease the voltage change when a load
    has high frequency components, but the main reason for them is to
    improve the stability of the feed back control system inside the
    regulator. Without them, some combinations of lead inductance and
    source and load impedance will cause the regulator to become an
    oscillator. This can bounce the output voltage up and down a couple
    volts at a megahertz or two.
  10. Silverfox

    Silverfox Guest

    Ok I think I am understanding the capacitor thing to smooth out the
    voltage so stop it from being eratic. Am I right in saying that voltage
    will run through the capacitor to ground until the capacitor is fully
    charged then it will block the voltage allowing the voltage to the 'In'
    pin of the voltage regulator. Now the part I am getting lost on is, if
    the voltage now coming to to the 'In' pin is a spike, how does the
    capacitor smooth this out and I'm also lost if the voltage dips to the
    'In' pin.

    If the voltage is in the dip, does the capacitor feed voltage back up
    to the 'In' pin?

    I hope you understand what I am trying to say.

    Thank you very much for your help
  11. You have the sort of general idea, but the actual mathematical
    description may be some help. The relation between voltage and
    current for a capacitor is I=C*(dv/dt). In English, that is, Current
    through a capacitor (in amperes) is equal to the capacitance (in
    farads) times the rate of change of voltage (in volts per second).

    So a capacitor passes current any time the voltage changes, and in
    proportion to the speed of the change. A "spike" implys a fast rate
    of change, so a large current. The capacitor doesn't hold the voltage
    still, but it does pass current in the direction that will help reduce
    the speed and magnitude of voltage change. It is, in effect, voltage
    inertia. If the spike in in the direction of increasing voltage, the
    capacitor will reduce the rate of change and lower the peak voltage by
    absorbing some of the energy in the spike. If the spike is is the
    direction of less voltage, the capacitor will reduce the rate of
    change, and raise the minimum voltage by dumping some of its stored
    energy out into the circuit.
    Yes, something like a rechargeable battery.
    I hope you can tell whether or not I did.
    You're welcome.
  12. Silverfox

    Silverfox Guest

    Briliant, thank you :)
  13. Silverfox

    Silverfox Guest

    Ok now I have set up a delay and a loop and I am switchin a red LED on
    and off via pin 17 and I am keeping a green LED turned on, on pin 18.

    So both the anodes of the LED goes to the output pin of the voltage
    regulator. I put a 270 ohms resistor in series and the red LED flickers
    ok, and so does the green LED (but very slightly) as if its being
    interfered by the red LED. So its output pin goes to resistor goes to
    red LED and to the green LED. I am wondering why this causees
    intereference in the green LED.

    If I put in another 270ohms resistor, so one resistor from green LED to
    output pin of voltage regulator and 1 resistor from red LED to output
    pin of voltage regulator and this clears up the flickering.

    Can anyone explain what is happinening here please?

    Thank you all very much in advance

  14. It might help to think of a bypass capacitor as something like a very
    tiny rechargable battery - the "battery" charges on spikes, and
    discharges on dips in an attempt to keep the voltage constant.
  15. You say a resistor is in series. In series with what? Are the two
    LEDs connected in parallel?
    The two colors of LED do not drop the same voltage when the LED is on.
    Red LEDs use need less voltage than green ones do (red photons are
    less energetic, each, than green photons are so it takes less voltage
    to produce them).

    Each LED needs its own current limiting resistor in series with it.
  16. ehsjr

    ehsjr Guest

    Hi Richard,

    A schematic will help to explain this:

    Regulator Output + +---[270R]------+
    | |
    | +--+--+
    | | |
    | [RLED] [GLED]
    ----- | |
    | PIC |---------+ |
    | | |
    | |---------------+

    A green led requires a higher voltage to turn on than
    a red led. A rough approximation is 1.4 volts for a red,
    and 1.7 volts for a green. When a led is turned on, it
    draws current through the resistor, creating a voltage
    drop. Turning on the red led will drop the voltage at
    point A to about 1.4 volts, which is too low for the green
    led to glow properly. Thus it will dim or turn off
    completely every time the red led is turned on.

    Now look (below) at the correct way to wire it:

    Regulator Output + +------------+-----+
    | | |
    | [270R] [270R]
    | | |
    | [RLED] [GLED]
    ----- | |
    | PIC |---------+ |
    | | |
    | |---------------+

    Point A will be held at +5 volts by the regulator, regardless
    of what the red led does. So when the red led is turned on, it
    draws current through the 270 ohm resistor connected to it,
    causing a voltage drop to about 1.4 volts at the bottom of the
    resistor, but does not prevent the green led from turning on.
  17. Silverfox

    Silverfox Guest

    Brilliant explanation, thank you very much. The first wasy is how I did
    do it, but I wired it the second way in the end and it fixed my

    Thank you loads, all of you. :)
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day