Go Down

Topic: Using I/O pin to sink a current? (Read 1 time) previous topic - next topic

FlyingSteve

Dec 06, 2011, 03:13 am Last Edit: Dec 06, 2011, 09:51 pm by FlyingSteve Reason: 1
Hey guys, I am running a mosfet power circuit to turn some loads on/off and I'm using a resistor soldered in the circuit to sink the gate voltage, but I'd like to use my Arduino to control the mosfet and I want the gate to stay energized when I reset the arduino. Sometimes I need to reset it a few times a day, and I can't be having the devices go on/off like that...

What's the easiest way of going about this? I thought that when you set a pin to LOW, that it effectively turns it in to a ground? From my testing I see that it just turns the pin off. Would be nice if I could control the mosfet's some way in the code, like HIGH/LOW...

Any thoughts?

Thanks!

I had thought about using a capacitor on each mosfet, that way it would take longer for the pin to sink through the resistor while the Arduino is resetting?

SurferTim

#1
Dec 06, 2011, 03:54 am Last Edit: Dec 06, 2011, 03:58 am by SurferTim Reason: 1
The pins will sink up to 20ma. The pin voltage could be anywhere from .6v to .9v in this condition, depending on the current it is sinking.

Are you using a P channel mosfet?

CrossRoads

Did you set the pin to an output?
pinMode(pinX, OUTPUT);

once you command digitalWrite(pinX, LOW), it will sink all the current you let it, and if more than 40mA will burn up doing so.

When you reset the Arduino, the pins revert to inputs until your sketch turns them into outputs.

Did you want the Gate pin High or Low during the Reset condition?

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

FlyingSteve

#3
Dec 06, 2011, 05:09 am Last Edit: Dec 06, 2011, 05:11 am by FlyingSteve Reason: 1
I want the gates to stay in their current condition. If they are getting 5v from the arduino, and I reset the arduino, I want them to stay on... If they are off, they should stay off. Get what I mean? It's lighting in my terrarium and if the lights are on when I reset the arduino I don't want the mosfets going off... Which is why I was thinking it would be great if I could use the same arduino pins to send 5v to the mosfets and then when it's time, turn the mosfets off by sinking the voltage. There should be no more current going to the mosfets than the arduino can send out of it's pins. Each mosfet has it's own arduino pin, too...

CrossRoads, no I set the pinMode to INPUT... I'll do it as OUTPUT and try it. The Arduino can only send 40mA anyway, so it shouldn't have a problem sinking it's  own current, right? If need be, couldn't I put an resistor between the pin and it's mosfet to help reduce the current more?

CrossRoads

Yeah, I think put a cap on the MOSFET gate.
After your sketch starts, read the state of the pin, and then set the pin to an output and drive it at the same level.
How long of a power outage do you expect?
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

FlyingSteve

However long it takes for the Arduino to reset when you push the reset button... So like, 2 seconds? I wasn't going to read the state of the pin, since the timing is control by an RTC... So when the sketch starts, if it's during the time for the lights to be on then that pin will return to 5V status, but the gates will still be energized & open anyway, if the lights are supposed to be off, then the gates would be closed and the arduino pin won't be sending voltage.

That's just the thought I came up with knowing that the mosfet gate takes no current, so the gate will stay energized until something external sinks the voltage... I don't see why the Arduino would have a problem sinking it's own current though. When I get home from work later I am going to take one of my spare Uno boards and just try it. I'd prefer to not have to get in to adding more resistors/cap @ this point in time.

liudr

OP, please change your title to sink a CURRENT. You can't sink a voltage. Good discussion by the way. I'm sure others can benefit from reading this so a correct title gets good search hits.

MarkT


Hey guys, I am running a mosfet power circuit to turn some loads on/off and I'm using a resistor soldered in the circuit to sink the gate voltage, but I'd like to use my Arduino to control the mosfet and I want the gate to stay energized when I reset the arduino. Sometimes I need to reset it a few times a day, and I can't be having the devices go on/off like that...

What's the easiest way of going about this? I thought that when you set a pin to LOW, that it effectively turns it in to a ground? From my testing I see that it just turns the pin off. Would be nice if I could control the mosfet's some way in the code, like HIGH/LOW...

Just remove the resistor to ground - A MOSFET gate is quite a substantial capacitance and the pins should be configured as INPUTs during the reset cycle I believe.

Its not necessarily the best way to achieve the effect, its a kludge.  Why are you having to reset BTW?
Quote

Any thoughts?

Thanks!

I had thought about using a capacitor on each mosfet, that way it would take longer for the pin to sink through the resistor while the Arduino is resetting?
[ I won't respond to messages, use the forum please ]

FlyingSteve

MarkT, could you please be a little more clear... Not that I'm stupid lol, but your "I believe" statement is confusing me :)

I'm having to reset because the Arduino also does temperature control via PID algorithm, and sometimes when I open the door it screws the PID up and it way overshoots and then goes into an oscillation that takes a little bit of time to self-correct... So I will manually reset to help avoid that. I am adding in other components to freeze the integral on the PID & include a freeze-time so it won't do that anymore, but in either case if I should need to reset the arduino for whatever reason (Remember, this is for prototyping after-all) I don't want the lights to be going nuts.

Grumpy_Mike

Mark is saying that if you remove the resistor the FET should stay on due to the charge on it's gate.

Personally I don't think it will but what is wrong with a pull up resistor on the FET's gate?

PeterH



I'm having to reset because the Arduino also does temperature control via PID algorithm, and sometimes when I open the door it screws the PID up and it way overshoots and then goes into an oscillation that takes a little bit of time to self-correct... So I will manually reset to help avoid that.


Rather than deliberately crashing the Arduino and trying to minimise the effects of that, I suggest you start by trying to correct the PID parameters. If it's oscillating, perhaps you don't have the derivative feedback set high enough. If you really can't sort that out then you could simply clip the control signal to around the normal steady-state condition so that it doesn't have as much authority to induce these transient overshoots. And if you can't even do *that* then fit a 'reset' switch which leaves the Arduino running but just tells you sketch to restart the PID algorithm.

Trying to come up with clever drivers that will hide the Arduino reset feels like a solution to the wrong problem.
I only provide help via the forum - please do not contact me for private consultancy.

liudr

I think the integral parameter needs to be reduced and a limit of the integral needs to be set.

FlyingSteve

Guys, this isn't a discussion about my PID parameters... I know what needs to be changed and what to do there.

FlyingSteve

Ok,

pinMode(11, OUTPUT);
digitalWrite(11, HIGH);

restart arduino, light comes on.

changed it to digitalWrite(11, LOW);

re-loaded arduino and bam light went out and the little Ardie Uno still lives lol.

FlyingSteve




I'm having to reset because the Arduino also does temperature control via PID algorithm, and sometimes when I open the door it screws the PID up and it way overshoots and then goes into an oscillation that takes a little bit of time to self-correct... So I will manually reset to help avoid that.


Rather than deliberately crashing the Arduino and trying to minimise the effects of that, I suggest you start by trying to correct the PID parameters. If it's oscillating, perhaps you don't have the derivative feedback set high enough. If you really can't sort that out then you could simply clip the control signal to around the normal steady-state condition so that it doesn't have as much authority to induce these transient overshoots. And if you can't even do *that* then fit a 'reset' switch which leaves the Arduino running but just tells you sketch to restart the PID algorithm.

Trying to come up with clever drivers that will hide the Arduino reset feels like a solution to the wrong problem.


The oscillation happens when you open the door and all the inside air comes out...The input temperature changes, the PID responds. The PID needs to know that the door is open and not to freak out. Enter the microswitch on the door. Door opens, microswitch tells arduino that the door is open and to freeze the integral until the switch is depressed again... Once the door closes then a 5min freeze on the integral starts.

I can't hook the switch up until my Mega board shows up tomorrow... I'm already out of pins on this Uno board and I still have a lot more to hook up.

Go Up