PIC16F877A not working again :(


Closed Thread
Results 1 to 25 of 25
  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697

    Default PIC16F877A not working again :(

    Hi, Ive not touched 16F877A's for a while but now i need to use one again and im having more problems with it. Ive written some test code and ive tried mister_e's code from last time. My test code uses portD but ive tested ports A and B with mister_e's code too and im not picking anything up. Ive done all the usual checks (MCLR, Resonator, Capacitor etc). Ive checked the voltage with my oscilloscope and its extremely smooth. It almost looks like theres no load on it at all. The PIC is definately connected to it so im guessing its just not starting up correctly.

    Im sure i got it working last time but i dont know how and im out of ideas now. I dont have any beer this time either . Does anyone have any ideas?

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Hi, Ive not touched 16F877A's for a while but now i need to use one again and im having more problems with it. Ive written some test code and ive tried mister_e's code from last time. My test code uses portD but ive tested ports A and B with mister_e's code too and im not picking anything up. Ive done all the usual checks (MCLR, Resonator, Capacitor etc). Ive checked the voltage with my oscilloscope and its extremely smooth. It almost looks like theres no load on it at all. The PIC is definately connected to it so im guessing its just not starting up correctly.
    Sir...SIR!!!!
    Put down the PIC...now step away from the PIC...Hands behind your ankles...
    Is it in backwards? Ya never, know...could happen...
    And this is my favorite test code...absolutely nothing fancy, but it tells me that things are working...
    Code:
    temp var byte
    trisa = 0  'set all the pins to outputs
    trisb = 0
    trisc = 0
    trisd = 0
    trise = 0
    'also turn analog ports to digital and/or set cmcon if applicable
    main:
    temp = temp + 1
    porta=temp
    portb=temp
    portc=temp
    portd = temp
    porte = temp
    'put a pauseus xxx here if the fastest pin (bit 0 for each port) is entirely too fast
    goto main
    That way each successive pin on each port will have exactly half the frequency of the pin before it. Of course things change with each different type of PIC and it's application, i.e. whether or not I'm using MCLR as MCLR or an I/O, whether or not I'm using OSC1/OSC2 as clock pins or I/O, and so on and so on...
    Last edited by skimask; - 21st October 2008 at 00:01.

  3. #3
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Its not in backwards. I know it can happen, Ive done it pleanty of times myself. Usually i put it in the programmer the wrong way. This is definately correct though. I am using the OSC1 and OSC2 pins for a 3 pin resonator (20MHz). MCLR is being used as MCLR. I dont see any options to use it as an I/O pin on this chip. It has a 10K resistor to VDD.

    CMCON doesnt make much sense to me but that only seems to affect portA. My Code tested portD by turning 2 outputs on and off alternately. mister_e's code tests both portA and portB. I had trouble with portA before but at least portB worked. The only thing i see about portD is that it can act as a parallel port. The datasheet says trisE.4 must be set to enable "PSPMODE" but its default value is 0 so portD should be working as normal I/O pins.

    The values of portD are unknown at startup. Usually that means the LEDs i have connected will flash sometimes when the PIC powers up. This time there not doing. Its like the chip is never turning on. I thought there might be a problem with my breadboard so i tested the power pins on the PIC and there is definately power getting there.

    Ill have a go with your test code when i get home but for now ill continue reading the datasheet to see if there are any other registers that might affect it

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Talking Copy n' paste backdraw ...

    Ha,Ha,Ha


    ive tried mister_e's code from last time.
    Code:
     ifdef PM_USED
                device  pic16F877A, xt_osc, wdt_on, lvp_off, protect_off
            else
                __config _XT_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
            endif
            endasm

    I am using the OSC1 and OSC2 pins for a 3 pin resonator (20MHz).

    Dit you also try to heat your pic, just some degrees ????

    could be another solution ... the Hardware one

    Alain
    Last edited by Acetronics2; - 21st October 2008 at 10:06.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    I know last time i was using a 4MHz one instead. Whats bad about using that code with a 20MHz?

    The test code i wrote myself has "DEFINE OSC 20" at the top so that should have worked

    Edit: The PIC didnt get noticably warmer at all
    Last edited by The Master; - 21st October 2008 at 10:23.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    I know last time i was using a 4MHz one instead. Whats bad about using that code with a 20MHz?
    The test code i wrote myself has "DEFINE OSC 20" at the top so that should have worked
    Edit: The PIC didnt get noticably warmer at all
    Check the datasheet, Oscillator section in particular...
    Have to change the oscillator configuration from XT to HS when using a higher frequency crystal/resonator/etc.

  7. #7
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    I see. The datasheet says XT is for 200KHz to 4MHz. Anything above that is HS. I checked the datasheet for PIC16F87 too and that says the same thing yet ive been using one with a 20MHz resonator without setting it to HS. Ill change the 16F877A to HS when i get home

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    I see. The datasheet says XT is for 200KHz to 4MHz. Anything above that is HS. I checked the datasheet for PIC16F87 too and that says the same thing yet ive been using one with a 20MHz resonator without setting it to HS. Ill change the 16F877A to HS when i get home
    I think you've just been lucky so far. Some of the various oscillator modes (XT, HX, etc) change the 'gain' inside the PIC, drive the crystal/resonator/whatever harder at higher freq's.
    The F87 is a bit newer than the F877A. Maybe it's a bit more tolerant of that sort of thing.

  9. #9
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    So if i set it to XT when it should be HS then i dont risk blowing anyhting up it just means that the resonator might not have enough power to run correctly?

    From what ive seen the PIC seems to be in a kind of standby mode. I do remember them doing the same kind of thing if the resonator isnt connected so that might be the problem.

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    So if i set it to XT when it should be HS then i dont risk blowing anyhting up it just means that the resonator might not have enough power to run correctly?
    It's got nothing to do with 'power' in the way that you're thinking about it. It's the 'gain' for the oscillating signal that goes into/comes out of the crystal/resonator itself.
    The higher the frequency, the more juice you need... i.e. takes more energy to swing an electrical signal back and forth at 20Mhz than it does at 4Mhz. (if you really want to go crazy, pull up the datasheet for any old op-amp and look at 'slew rate')
    You won't blow anything by setting the wrong mode, it'll either work or won't. (well, I should re-state that a bit...you SHOULDN'T blow anything up)

    From what ive seen the PIC seems to be in a kind of standby mode. I do remember them doing the same kind of thing if the resonator isnt connected so that might be the problem.
    How can you actually quantify that 'seems to be in a kind of standby mode'. It's either working for you or not.

  11. #11
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    By that i meant in an idle state where its not doing anything. It doesnt appear to be using any power and its not changing the state of any output pins etc

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    By that i meant in an idle state where its not doing anything. It doesnt appear to be using any power and its not changing the state of any output pins etc
    Can I quote/use that statement the next time a customer calls and complains said machine is not working.

    The machine is just in an idle state, not to worry
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Ive just reprogrammed the PIC chip with my origional test code but setting the oscillator to HS and it works.

    Thanx for your help

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Ive just reprogrammed the PIC chip with my origional test code but setting the oscillator to HS and it works.

    Thanx for your help
    As the great 'Quagmire' says...

    Gigadee-gigadee, gigadee-goo...

  15. #15
    Join Date
    Oct 2008
    Location
    Ashland, KY
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    I've had the same exact problems myself, especially since I've been using either an 8 or 20MHz HC-49 case crystal in a lot of recent experiements. No matter what programming software is used, it always seems to default to "XT" instead of "HS". I usually forget to change the PIC in the drop-down menu in Microcode Studio from 16F628A to whatever PIC the program is for, but that's easy to find and correct when the program doesn't assemble correctly and gives a "too many errors" error message.

    Is there an .ini file or another file I can modify to have the default settings in Microcode Studio automatically select the PIC I've been using most lately, and to default to "HS" instead of "XT" in the oscillator setting? Same question for the PICFlash software from mikroElektronika-anything I can modify to change the same default settings?

  16. #16
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rxforspeed View Post
    Is there an .ini file or another file I can modify to have the default settings in Microcode Studio automatically select the PIC I've been using most lately, and to default to "HS" instead of "XT" in the oscillator setting? Same question for the PICFlash software from mikroElektronika-anything I can modify to change the same default settings?
    Have you seen this about the config settings for the PIC?
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Dave
    Always wear safety glasses while programming.

  17. #17
    Join Date
    Oct 2008
    Location
    Ashland, KY
    Posts
    45


    Did you find this post helpful? Yes | No

    Default Thanks!

    Thanks for the link, Dave! Once I get those default settings changed, I'm sure that'll save me quite a few frustrating moments...

  18. #18
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Ive got another slight problem with this. Ive just tried to control some optoisolators using porte.0 and porte.2. For some strange reason the pins just wont turn on. I added some test code and the correct data is getting to the chip. It copies a bit from the serial data directly to the pin (EG, porte.0=btemp.0). Right after if i check the status of the pin it shows as 0. Ive had a look in the datasheet and i can see that porte gets used for parallel communications but i have set the tris registers to disable it and use it as a general I/O. I have something else connected to porte.1 and that works fine :S

    Edit: It seems that changing the status of another pin is causing those pins to turn off. I had this the other night with portA too. Turning 1 output on would turn another off automatically. Im going to look through all the code again incase theres a silly mistake somewhere
    Last edited by The Master; - 29th October 2008 at 19:09.

  19. #19
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What are you doing with the analog settings or pins.?
    Dave
    Always wear safety glasses while programming.

  20. #20
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Im not using any analogue. The datasheet says analogue is disabled if ADCON1.0 is 0. It also says that its 0 by default.

    I seem to remember these outputs working before by they arnt doing now. Ive not added any code that changes the state of those pins anywhere except the 1 line

  21. #21
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Try adding this to the start of your code.

    Code:
    ADCON1=7 
    CMCON=7
    Dave
    Always wear safety glasses while programming.

  22. #22
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    That worked Now ive just gotta read the datasheet and find out why

    Thanx

  23. #23
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    That worked Now ive just gotta read the datasheet and find out why

    Thanx
    ADCON0.0 is the start/stop bit of ADCON0.

    ADCON1 is where the pins are controlled. There is a table in the ADCON1 section.
    Comparators are similar.

    This also helps.
    http://www.picbasic.co.uk/forum/showthread.php?t=561

    Have Fun
    Dave
    Always wear safety glasses while programming.

  24. #24
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Im sure ive been pointed to that thread before. I knew about the problem but i thought the settings i had would stop it. Aparently not. I must have misread the datasheet and completely overlooked CMCON.

    I should probably read the whole datasheet when using a PIC. The only problem is that by about page 50 i cant remember what was on page 1. There are a few PICs (including the 16F877A) which seem to cover just about everything i do so hopefully if i just concentrate on these few ill get to know them better.

  25. #25
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    It just takes a little time. You are doing fine.

    I only have a dozen or so chips that I use and many of them I do not use all of the features.

    Still learning myself.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. PIC16F877A PORTA.2 not working
    By The Master in forum Off Topic
    Replies: 2
    Last Post: - 10th October 2009, 18:16
  2. PIC16F877A analog problem
    By DeViLa_Q8 in forum mel PIC BASIC
    Replies: 0
    Last Post: - 30th July 2009, 20:19
  3. PIC16F877A for application in mobile robot...
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th January 2009, 14:47
  4. PIC16F877A not working
    By The Master in forum General
    Replies: 6
    Last Post: - 16th November 2007, 11:32
  5. communicating pic18f452 with pic16f877a
    By tamersoss in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th July 2007, 19:54

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts