Newbie could do with a little help please

Thread Starter

lew247

Joined Apr 23, 2010
15
I'm trying to design a circuit using a pic 16F877 which isn't too much of a problem, I've got an easypic 6 board

What I need is help with a circuit, I need the pic to switch a solenoid that will be in the car, and also possibly some relays

Will the circuit below work?
Or can anyone see any problems, or got any suggestions?

If I use a relay it will be in the position of the solenoid.

What is the max current this circuit could switch?

I "may" need to switch a circuit that can handle 10A so maybe a relay is best for this? in which case can I use the above circuit but use a relay instead of the solenoid?

Obviously I'd have to have a diode across the relay coil

Will I need a relay across the solenoid coil above?


Sorry for so many questions but I've not done any electronics like this for over 30 years now.

 

Thread Starter

lew247

Joined Apr 23, 2010
15
it's for my own car
I'm going to run it on oil as well as diesel
the solenoid will control which fuel goes to the fuel injection pump.

It's basically a 3 way valve with the solenoid stitching which input port goes to the output port.

Normally diesel, once the oil is heated to a certain temp then it will switch to oil (hence the reason for having a pic)

but even if it wasn't for a car, would the circuit work as it is, or would it need anything else?
or did I miss something obvious?
 
Last edited:

SgtWookie

Joined Jul 17, 2007
22,230
You should use a resistor between the PIC I/O pin and the MOSFET. The resistor should be physically as close to the MOSFET as you can get it. This will help to prevent the gate from "ringing" when it is suddenly turned on or off; the resistor acts as a snubber.
[eta] The MOSFET should be an N-channel logic level type power MOSFET. For International Semiconductor/Vishay part numbers, generally those beginning with "IRF" are standard level, and are not suited to control by logic. Those beginning with "IRL" are logic-level.

Getting clean power to your circuit will be a challenge. Automotive environments are amongst the most brutal on the planet. You can get very high (>60v) peak voltages when load dumps occur (such as the lights being turned off, etc.) A standard regulator such as an LM317 would get "zapped".

The PICs with the -E/x suffixes are rated for automotive temp ranges. The -I/x suffixes are only rated for the commercial temp ranges. if you try to use an -I suffix part in an auto, it will be much more likely to fail.
 
Last edited:

beenthere

Joined Apr 20, 2004
15,819
or did I miss something obvious?
Not at all. We have been having some discussions as to the nature of assistance we feel is safe to provide for automotive projects. Yours is well into the comfort zone.

To be fair to members, we have yet to distill the comments and post clear policy on such help.
 

Thread Starter

lew247

Joined Apr 23, 2010
15
Thanks for that guys, nice to be in such a friendly forum :)

One question though if someone doesn't mind

the resistor between the pic o/p and the mosfet? any idea what value?
 

SgtWookie

Joined Jul 17, 2007
22,230
One question though if someone doesn't mind

the resistor between the pic o/p and the mosfet? any idea what value?
Normally, you'd use a fairly low value; somewhere in the vicinity of 50 Ohms.

However, since you're going to be using this thing in a vehicle, and you are not going to be using PWM, you may want to use a 3.3k Ohm resistor. The reasoning is that their may be high voltage transients on the system, which may well exceed 60v - and gate shorted to the drain terminal is a common failure mode for MOSFETs. Using a 3.3k Ohm resistor will limit the maximum current that your uC will have to sink in such a failure mode, and help to ensure it's survival even if the MOSFET fails. If you use a small wattage resistor, it will burn up before the uC will.

Use 100k for the pull-down resistor instead of 10k. In case the 3.3k resistor gets fried or the uC is removed, at least you will still have some kind of device in place to keep the gate from floating.
 

Thread Starter

lew247

Joined Apr 23, 2010
15
I don't actually think there will be high voltage near the circuit

it's going in a diesel, no spark plugs or coil hence no high voltage.

the only voltage is 12v well say up to 14v from the alternator.

However I'll take your advice and use the resistors you mentioned, better to be safe, than sorry.

Thanks
 

SgtWookie

Joined Jul 17, 2007
22,230
I don't actually think there will be high voltage near the circuit

it's going in a diesel, no spark plugs or coil hence no high voltage.

the only voltage is 12v well say up to 14v from the alternator.
You don't have headlights?

Read this part again:
Getting clean power to your circuit will be a challenge. Automotive environments are amongst the most brutal on the planet. You can get very high (>60v) peak voltages when load dumps occur (such as the lights being turned off, etc.) A standard regulator such as an LM317 would get "zapped".
 

Thread Starter

lew247

Joined Apr 23, 2010
15
Been having a long think about this and I ran into a snag, well I think I did anyway

If I used the circuit as posted on page 1 (with the added protection) I'mm need to isolate the car earth from the circuit.
and as the solenoid will more than likely have the case common with one of the cpis I came up with the following circuit.



Can anyone tell me if they see anything wrong with this, or any reason why it shouldn't work?
I know the choice or the irf9540 is a bit overkill on a circuit thats going to use probably around half an amp but I'd rather it was able to handle more than needed, then if I decide at a later stage to change things, that wont need changing.

I have a feeling I may need a 100K resistor on the mosfet for protection but not sure which pins it should go across
or should I just change the 10K thats already there to 100K?
 
Last edited:

tracecom

Joined Apr 16, 2010
3,944
With regard to your power supply, I think you have the 7805 drawn backwards, i.e. pin 1 (the input) should be connected to 12v and pin 3 (the output) should be power to your pic. In addition, the experts (of which I am not one) say you need a .33uf cap on the input and a .1uf on the output.
 

cjdelphi

Joined Mar 26, 2009
272
Getting clean power to your circuit will be a challenge. Automotive environments are amongst the most brutal on the planet. You can get very high (>60v) peak voltages when load dumps occur (such as the lights being turned off, etc.) A standard regulator such as an LM317 would get "zapped".
Wow, really? I thought the battery would act as a buffer to keep the high voltage spikes down... secondly, I thought the job of the regulator on the alternator was supposed to stop high voltage spikes > 15v

I put together a circuit which measures the battery [highest cap ratings in the circuit are 16v] it's been working for 2 years now without any problems never had any issues with voltage spikes....

Now you have me worried about the circuit now :p
 

Thread Starter

lew247

Joined Apr 23, 2010
15
With regard to your power supply, I think you have the 7805 drawn backwards, i.e. pin 1 (the input) should be connected to 12v and pin 3 (the output) should be power to your pic. In addition, the experts (of which I am not one) say you need a .33uf cap on the input and a .1uf on the output.
Removed the psu diagram that was above in post 13, I had it wrong.
 
Last edited:

Thread Starter

lew247

Joined Apr 23, 2010
15
After doing more research, I really wasn't happy with using the 7805 "just in case of voltage spikes"

I came up with the following diagram, thanks to the online design facility on national semiconductors website
also getting sent free samples too :)

The LM2591HV is designed to cope with voltage spikes up to 60v



Still not certain about my design for the "switch" to activate the solenoid,
I don't know if the IRF9540 has enough protection against "possible voltage spikes" in the car.

if someone could have a look please and let me know what they think?

top diagram in post 13
 
Last edited:

Thread Starter

lew247

Joined Apr 23, 2010
15
I feel kinda not knowing anything right now
I actually don't get what you mean - big problem will be the Vgs -"The Zener diode clamps Vgs to a range of 1v to -12v."

The solenoid voltage will be 12v direct from the battery.

Basically the pic chip will be measuring the temp of the fuel line, and when it reaches a certain temp it will activate the solenoid to switch fuel to an alternative fuel (veg oil)

so it will be not activated for maybe 5 minutes of driving, then activated and stay activated till the end of the journey, anything up to 6 hours.
so a "simple" on/off with the circuit abovebeing a "switch" taking the place of a relay
if that makes sense.
 

SgtWookie

Joined Jul 17, 2007
22,230
I feel kinda not knowing anything right now
I actually don't get what you mean - big problem will be the Vgs -"The Zener diode clamps Vgs to a range of 1v to -12v."
Oh, sorry - you did pretty well with your circuit; I thought you knew MOSFET terminology.

Vgs is the voltage on the gate, using the source terminal as the reference point; or in other words: the difference between the voltage on the gate and the source terminals.

Most MOSFETs will be destroyed if the Vgs exceeds +/- 20v. Some won't tolerate more than +/-15v. So, one reasonably easy way to reduce the likelihood of that from happening is to use a Zener diode (shunt regulator) as a "clamper". http://en.wikipedia.org/wiki/Clamper_(electronics)

The way I've wired it, If the gate attempts to go more positive than the source terminal than about 0.7v, the Zener diode will conduct in the forward direction to keep the voltages the same. If Vgs tries to exceed -12v, the Zener breaks down and conducts current to keep the Vgs around -12v.

The idea here is the 330 Ohm resistor between the transistor's collector and the Zener needs to be a low-wattage part. If you get a really high spike in there and the wattage rating of the resistor is exceeded, it will burn up first instead of the Zener. Resistors are probably the least expensive electronic device that you can buy.

If you wanted a bit more reliability, you might use a 25mA constant current sink circuit instead of the 330 Ohm resistor. That way the Zener's power dissipation rating limit of 500mW won't be exceeded; the maximum current allowed is roughly 41.6mA.

[/QUOTE]The solenoid voltage will be 12v direct from the battery.

Basically the pic chip will be measuring the temp of the fuel line, and when it reaches a certain temp it will activate the solenoid to switch fuel to an alternative fuel (veg oil)

so it will be not activated for maybe 5 minutes of driving, then activated and stay activated till the end of the journey, anything up to 6 hours.
so a "simple" on/off with the circuit above being a "switch" taking the place of a relay if that makes sense.[/QUOTE]
Sure, it makes sense - if the device is actually a solenoid-actuated 3-port valve.

You may wish to add a positive indication that you are operating on veggie oil or petroleum. Measuring the voltage across the solenoid would give you an indication whether the solenoid activate command was acted upon. But in order to determine if the switch actually changed positions, you would need to measure the flow in both the veg oil line and the petroleum fuel line; this could get expensive.
 
Top