Project with 12F629

Thread Starter

cracker

Joined Jan 5, 2008
13
I'm working on a project that is pretty simple in design since I just started working to my own circuitry. It just consists of a 12F629, switch, leds, and battery (of course). The main issue is that I'm not able to light up the leds connected to pins 6 and 7 if I try to set them seperately (MOVLW .2, MOVLW .1 respectively). However if I set pins 5, 6, and 7 high together (MOVLW .7) they all light up fine. I've commented out all of the other code and it just results in no leds blinking at all. Changing the value of the pin to use in the 'problematic code' results in the leds on the other pin working fine. It's one of those bang your head on the keyboard moments...

Another problem is that the 12F629 seems to be very sensitive to electro-magnetic fields. I'm trying to use the switch to alter the pattern of the leds but pin 4 seems to be going high erratically. (I know it's an electro-magnetic field causing it because I can actually manipulate the toggle by putting my hand near it -- though erratically.)

TIA for any help anyone can provide!
 

SgtWookie

Joined Jul 17, 2007
22,230
First question - do you have a bypass capacitor across the MCU's power and ground pins? It's normal to have at least a 0.1uF ceramic or tantalum cap there. Otherwise, you are likely to have problems.

Secondly - are you using current limiting resistors with your LEDs? Your MCU can only source or sink a very small amount of current (I don't have the datasheet in front of me) and nearly all LEDs require using either current regulation or current limiting resistors.

You might need to use driver circuits to power LEDs (I'd recommend that anyway; driver circuits are cheap to replace in comparison to an MCU.) Driving the output pins of your MCU near maximum limits isn't a good idea; it will shorten it's life.

Look in your MCU's datasheet for specifications on sourcing and sinking current for the pins you're using. Find out what the actual voltage drop is across your LEDs by using a power supply and a suitable resistor. Then use Ohm's Law to determine the actual safe resistance value to use, keeping in mind both the MCU's current limits and the limits of the LEDs.
 

Thread Starter

cracker

Joined Jan 5, 2008
13
I added a bypass capacitor but it still seems to be picking up a field and has erratic behavior when using code that is conditional upon the reading of pin 4. So I guess the simplest answer would be to try a higher value capacitor and see if it works any better...

Well I know it isn't the safest practice to not use resistors on leds but I'm running the leds off a 3v watch battery so technically there I'd need negative resistance... I also added a USB connection and have a pot so I can turn up/down the voltage/brightness. I believe the chip will be fine without additional protection.

Driver circuits would be much easier and cheaper to replace, yes. But that would defeat the purpose of me learning PIC assembler and building my own circuitry. :)
 

Thread Starter

cracker

Joined Jan 5, 2008
13
It will be a few days before I am able to test with a proper resistor. In the meantime I will probably scavenge through some motherboards for a suitable fill in until my ebay orders get here (didn't feel like paying a buck per resistor at RS!). I also came across a schematic that consisted of an 12F629 and leds (a die roll simulator) that uses a pin input and it looks like I should also be using a 22 uF bypass capacitor. There are some on motherboards that I have here but they are ceramic whereas they schematic uses tantalum. I'm hoping the ceramic caps will be sufficient but I read that in higher capacitances they can cause problems with circuits whereas tantalum ones don't. Guess I'll just have to see what happens. Thanks for the help guys and I will be sure to follow up when I (hopefully) get it working.
 

Thread Starter

cracker

Joined Jan 5, 2008
13
I've been experimenting a lot more with this problem I'm having. First let me say that I found out what was going on with the one line not going high separately but going high when combined with other lines. Turns out it was an oversight that makes you want to slam your head down on your keyboard... I was sending to pin 4 instead of pin 5! Unfortunately, there still is no joy with the other problem. I've tried using resistors of different values paired with my led (before or after -- tried that after I saw some schems set up that way and thought it might be worth a shot). I added a MOSFET to make sure I'm getting a steady ~5V in my circuit in case that was a problem. I even tried adding a resistor onto pin 4. I've tried test programs in ASM, C, PBP and they all result in ill behavior. Any additional advice/thoughts on this would be greatly appreciated. Here's a pic of how I have my test circuit set up (hopefully it's clear enough to see what's there):

 
Top