1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Electronics PIC16F877A and, apparently, a poltergeist

Discussion in 'Modding' started by Emon, 15 Jan 2007.

  1. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
    Crazy stuff happening with my 16F877A. I can program it fine, and it runs. Right now it's running a program that blinks an LED, connected to port B, every few seconds. When I put my hands near the LED, the PIC, or even the metal backplate of my breadboard, the LED starts flickering crazy fast. Clearly, I'm altering the capacitance of something in the circuit, and my guess is it's messing up the clock somehow. I'm using a 12 MHz crystal and two 22pF ceramic disc caps. I've tried quiet a few other crystals, too, and none of them make a difference. I do have the PIC's oscillator set in HS mode.

    Oh, and here's something else for you. When I unplug my PICkit 2 from the circuit, the PIC ceases to work at all. And yes, it is powered externally.

    What the hell is going on? :confused:
     
  2. Macaba

    Macaba What's a Dremel?

    Joined:
    4 Mar 2006
    Posts:
    107
    Likes Received:
    1
    Take a gooooood look at your MCLR pin. Is it setup correctly? Does it have a 10k resistor to pull-up to +5V? Or do you have the internal weak pullup enabled? The only trouble with the internal pullup, is that some programmers prefer this not to be enabled.

    Likewise, check you don't have any external pin interupts floating.
     
  3. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    Also check PGM is pulled low or LVP disabled in your config word, as this will do funny stuff in the same way leaving MCLR floating does.
     
  4. LuitvD

    LuitvD What's a Dremel?

    Joined:
    13 Aug 2006
    Posts:
    263
    Likes Received:
    0
    isn't the PGM pin multiplexed on the 887A? As long as you pull-up the MCLR pin the PGM pin is just fine I guess... It's just what Macaba said... the things I forgot for quite a long time too... the MCLR pin making the led flicker, and the external interrupts stopping my chip completely :p
     
  5. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    Uhh, no :duh: :rolleyes:

    No, you have to pull PGM low if LVP is enabled, which by default it is, and is something newcomers forget to disable in the config word.
     
  6. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
    Is there, like, any information on this stuff? I've read quite a few tutorials and none of them mentioned this stuff. And by information I do not mean page 254 of 642 in a cryptic datasheet.
     
  7. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    Page 254 is a good read though........
     
  8. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
  9. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    Cryptic?! I'd argue that Microchip produce some of the best datasheets out there.

    Get reading!
     
  10. Macaba

    Macaba What's a Dremel?

    Joined:
    4 Mar 2006
    Posts:
    107
    Likes Received:
    1
    The datasheets can be like an epiphany, you'll read the whole thing cover to cover. Then 3 months later, you'll have a problem. Of course, the solution to the problem is in the datasheet in one of those sections you just glossed over. Welcome to datasheet world!

    Seriously, steveyG is totally correct about microchip having some of the best datasheets, failing that, the microchip forum is good too.

    I havn't really had any 'doh ray me' moments. The only things that I have found out through knowledgable people, that would have otherwise really stumped me is the fact that the upper bits of the PC counter don't increment when doing a table lookup in a different 'page'. At least, i think thats how you describe it technically. So you have to change the bits yourself.
     
  11. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
    You're right, they are good datasheets, but they aren't particularly suited for beginners. And they shouldn't be, since they're datasheets.
     
  12. jakenbake

    jakenbake full duplex

    Joined:
    5 Jun 2005
    Posts:
    495
    Likes Received:
    3
    heres some stuff from my classes, don't know if it has what you need, but it is on the 16f877 specifically:
    link

    i have all my lab code saved as well...

    edit: heres a schematic of the boards we used to program them
     
    Last edited: 17 Jan 2007
  13. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
    Thanks, I'll take a look.
     
  14. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
    I pulled MCLR high and PGM low. With PGM low, the LED is constantly on instead of blinking. I tied a bunch of other stuff low, too, and it didn't help. With the PK2 connected, it's a lot less sensitive. I tried pulling PGC and PGD both high and low, since the PK2 connects to those, with little no change.

    Whatever the problem is, I think it's on the right side of the PIC, since moving my hand there makes it go nuts, but not the left side. I'd think there are some pins floating there that are messing things up, but I've tried tying everything high and low with no help.

    I should probably read the datasheet. In the meantime, any suggestions? :D
     
  15. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    Can you post your code please. With PGM low and the LED constantly on, your PIC must be running because a pin can't be pulled high while the PIC isn't running (unless it's stalled).

    What decoupling do you have on your board?
     
  16. Macaba

    Macaba What's a Dremel?

    Joined:
    4 Mar 2006
    Posts:
    107
    Likes Received:
    1
    Although PIC's are pretty resilient, i've burnt out a few in my time. Have you tried programming a different 16F877A?
     
  17. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
    Uh oh, you're not going to like this. :hehe: I'm using the HI-TECH PICC compiler at the moment. Please, no lectures, I'm well aware of the pros and cons of assembly and high level languages on small-scale embedded devices.

    Code:
    #include	<pic.h>
    
    /*
     *	Demo program
     *
     *	Flashes LEDs on Port B, responds to switch press
     *	on RA1. Usable on PICDEM board.
     *
     *	Copyright (C)1997 HI-TECH Software.
     *	Freely distributable.
     */
    
    #define BUTTON	RC1	//bit 1 of PORTC
    
    main(void)
    {
    	unsigned char	i, j;
    
    	TRISB = 0x10000000;
    	j = 0;
    	for(;;) {
    		PORTB = 0x10000000;
    		for(i = 100 ; --i ;)
    			continue;
    		PORTB = ~j;		/* output value of j */
    		for(i = 100 ; --i ;)
    			continue;
    		if(BUTTON == 0)		/* if switch pressed, increment */
    			j++;
    	}
    }
    
    I've had simpler assembly programs before, they acted the same way.


    None. Should I? It's running off of an ATX power supply turned bench supply.
     
  18. Macaba

    Macaba What's a Dremel?

    Joined:
    4 Mar 2006
    Posts:
    107
    Likes Received:
    1
    Its amazing how much a difference having a decoupling capacitor near the pins of the IC makes on any supply. Although I'm not sure how it could be the cause of your problems, i'd do it anyway.
     
  19. ConKbot of Doom

    ConKbot of Doom What's a Dremel?

    Joined:
    2 Jul 2003
    Posts:
    2,160
    Likes Received:
    6
    Definitely, you want decoupling caps, ATX power supplies are switching power supplies, so they will always have some noise in them. Plus how long are the wires your using from the PSU to the project board? Are they a twisted pair? if not then they can pick up noise easily.

    Now I'm not saying you should use shielded twisted pair for all your power wire, though that would be good. But decoupliung caps right at the device are always a good idea.
    On the 877A you can take a 806 or 1206 size SMD capacitor and solder it right onto the solder pads for Vss and Vcc pins. Or if your using a socket, you can put a small ceramic cap underneath of it. Along with your pull up resistor for MCLR.
     
  20. Emon

    Emon What's a Dremel?

    Joined:
    14 Jun 2004
    Posts:
    680
    Likes Received:
    0
    I added decoupling caps, 0.01 uF mylar caps. I tried some larger sizes too, none of them helped.
     

Share This Page