Help with project - dual 12v output controlled via PIC

Thread Starter

PaulW

Joined Aug 12, 2009
4
Hi all

I'm trying to work out a circuit to control 2 x 12v banks of LED's from a PIC microcontroller, which itself is being powered from a 12v source from a car.

I've done a really bad attempt I reckon at a circuit, please note this is my first attempt ever at something like this, and I'm still reading up on various things.

Basically...

The input source voltage is from the battery (12v, but can be dirty and spike from 11.4v to 13,8v), via the pic I want to control 2 sets of 12v automotive LED banks (about 1.2A draw per bank @ 12V), but sequence them in a pattern at 50ms refresh intervals on the fastest cycle.

So far I've come up with this circuit

http://i130.photobucket.com/albums/p266/PaulW21781/629b80d2.png

Input is top-right, outputs are the 2 left connectors. I've also added in 2 LED's which are to show the sequencing if the control module is attached some distance from the powered LED's.

The Crystal timer too, do I actually need this, or will the clock of the 12F629 be capable of the 50ms timings for switching the outputs?

Also, I want to wire in an override switch if possible, so when as 12V feed is applied, instead of it automatically going through the pre-programmed cycle, it will just be constant on for both outputs. Can I do this by adding a switch to GP3 and coding it in the PIC somehow? I'm still trying to learn how all this stuff works if I'm honest, this is just what I've figured out from a hard days reading up.

Finally, am I right in adding the 10uF cap after the LM7805 to clean the power? Or is this something which won't be needed at all... I've added it as I've seen a few circuit designs on the net which are being made for running in a car or bike you see...

Sorry for the barrage of questions, just hope I'm not going about this in the wrong way...

Thanks
 
Last edited:

jpanhalt

Joined Jan 18, 2008
11,087
Since you have plenty of pins, pull MCLR high as shown in the datasheet for external reset.

As for using the crystal, you don't seem to need that level of oscillator accuracy, so dump it and use the internal oscillator. That frees up two pins.

John
 

Thread Starter

PaulW

Joined Aug 12, 2009
4
Cheers for the tips :)

Even though I'm going blind here, I guess its comforting to know I'm at least heading in the direction I want to!

Ok so now I have this...

http://i130.photobucket.com/albums/p266/PaulW21781/7f9f9523.png

No idea what rating to do the cap on the input side of the 7805... Also, the package I use doesn't list a decoupling condensor... so not sure if thats how it goes properly... (I use Ubuntu)

Also... the reply in regards to the mosfets - run as a logic level one? Could someone elaborate on this for me please, as I'm not quite sure I understand, plus its making me question if I have them right for the application...

Thanks again, and sorry if I'm being a bit of a pain with this...
 

jpanhalt

Joined Jan 18, 2008
11,087
Let's deal first with theMCLR pin, because that is easiest. Try something like this, which is based on the datasheet.


The resistor value is not critical; the capacitor is to prevent momentary glitches in the +5V line from causing a reset. The switch, of course, causes a reset by grounding the pin. I have omitted a diode, which is now shown in the Microchip datasheets, because I suspect you will not be using ICSP (In Circuit Serial Programming).

As for the mosfets, you need logic-level mosfets. That is, mosfets that are fully turned on with a gate voltage of 4 volts or so relative to the source. Do not mistake the threshold voltage for that parameter. Then, I would put a small, current limiting resistor between each gate the the PIC pin that drives it. Since the PIC is limited to 25 mA per pin, a 200 ohm resistor will work. I sometimes go a little smaller, if I need a fast transition, but that is not the case here.

Do you need a resistor to drain the gate charge when the PIC pin goes low? NO. The PIC can sink 25 mA per pin too. HOWEVER, if you want the system to start with the mosfets in a known state (i.e., off), then add a larger drain resistor as you have shown. Something like 2K to 4.7K should be adequate.

John
 

SgtWookie

Joined Jul 17, 2007
22,230
I would avoid using the LEDs on the gates of the MOSFETs.

This will lead to slow rise times, and heating of the MOSFETs.

Using 10k resistors from the MOSFET gates to ground is not a bad idea, as this will tend to turn off the MOSFETs if there is a failure in the PIC. It will also help with ESD considerations.
 

Thread Starter

PaulW

Joined Aug 12, 2009
4
I need some sort of visual indication on the circuit though that its working... thats the thing...

Also, are there any circuit simulation programs available at all which I can test this out on? I can't find anything which seems to be good enough (I'm on Linux too which I guess doesn't help...)
 

SgtWookie

Joined Jul 17, 2007
22,230
I don't know how I missed this before, but you have the MOSFETs in upside down.

The source terminal needs to be connected to ground. The drain sinks current from your load; in this case your LED arrays.

Standard power MOSFETs need Vgs (voltage measured on the gate with respect to the source) to be 0v in order to be turned completely off, and 10v to be turned completely ON. Where you get into trouble is somewhere halfway between Vgs=0v and Vgs=10v; then they have a good deal of resistance, and rapidly heat up due to the power dissipation.

Logic level power MOSFETS will be fully turned on when the gate is about 4.5v. This allows logic-level MOSFETs to be controlled directly by logic ICs and uCs.

As far as a visual indication that the circuit's working - put the LEDs and their current limiting resistors between the MOSFET drain terminals and Vcc (+12v); not on the I/O lines that control the MOSFET gates.

You should have resistors connecting the I/O pins to the MOSFET gates. The gate resistors should be close to the MOSFETs. You could use anything from 20 Ohms to 470 Ohms. The purpose of the resistors is to eliminate oscillations on the gates when they change states.

Plan on your +12v being more like 13.8-14v when the engine is running. So, for your indicator LED current limiting resistors, calculate:
Rlimit >= (14v - Vf_LED) / Desired_Current

If you don't know what the typical Vf of your LEDs are, just use 2v. If you don't know what current your LEDs are rated for, just use 15mA. That results in:
Rlimit >= (14v - 2v) / 15mA
Rlimit >= 12 / 0.015 = 800 Ohms. The closest standard E24 resistance is 820 Ohms.

A table of standard resistance values is here: http://www.logwell.com/tech/components/resistor_values.html
Bookmark that page.

Resistor power dissipation: 12v x 15mA = 180mW. Double that for reliability; 360mW. Since they don't make resistors rated for 360mW, you will need to use 820 Ohm resistors rated for 1/2 Watt, as 1/4 W would not have a high enough power rating.

You should use a 0.1uF capacitor across the PIC's power pins; the leads should be as short as possible. Ceramic or poly caps work fine.

[eta]
For your logic-level MOSFETs, you could use these:
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=IRLIZ14GPBF-ND
Basically, International Rectifier's part numbers that start with IRL are logic level. Those that start with IRF are standard MOSFETs. (This isn't true in all cases; you have to look at the datasheets)

You could also use these:
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=IRL510PBF-ND
but they're nearly out of stock. It's best to order extras to have as spares, and for other projects. MOSFETs are very static sensitive; one "zap" and they're toast.
 
Last edited:

SgtWookie

Joined Jul 17, 2007
22,230
I need some sort of visual indication on the circuit though that its working... thats the thing...
As I mentioned above, connect the "it's working" indicator LEDs on the MOSFETs' drains. The extra load on the I/O pins driving the MOSFET gates will result in it NOT working much more quickly, as the uC just doesn't have much current source or sink capability - and you're going to be using most of that just driving the MOSFET gates.

Also, are there any circuit simulation programs available at all which I can test this out on? I can't find anything which seems to be good enough (I'm on Linux too which I guess doesn't help...)
You might find yourself a bit lonely on this one. Check the Electronic Resources forum. If you don't find anything for Linux/Unix, start a new thread; giving it a subject something like "SPICE for UNIX/Linux?"

You really don't have to simulate the entire circuit; you could use a signal generator to simulate the uC's output drive to the MOSFET gates.
 
Top