Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Stuck in for loop on: September 20, 2012, 08:48:00 am
Thank you for both of the inputs.  I am suspecting that Nick is initially right.  I only made the flags after I was unable to find the loop hold up.  Thank you both for the feedback!
2  Using Arduino / Programming Questions / Stuck in for loop on: September 20, 2012, 12:16:52 am

I am using an arduino to drive an electric scooter and everything works fine but after the throttle is done being used I want the scooter to time out and open a relay.  I am using the following code:
const int sLED = 5;
const int iLED = 6;
const int dLED = 7;
const int rOut = 8;
const int fetOut = 9;
const int pIn = A1;
boolean driveFlag;

void setup(){
  pinMode(sLED, OUTPUT);
  pinMode(iLED, OUTPUT);
  pinMode(dLED, OUTPUT);
  pinMode(rOut, OUTPUT);
  pinMode(fetOut, OUTPUT);
  pinMode(pIn, INPUT);
  digitalWrite(sLED, HIGH);
  digitalWrite(iLED, HIGH);
  digitalWrite(dLED, HIGH);
  digitalWrite(rOut, LOW);
  digitalWrite(fetOut, LOW);

void loop(){
  if(driveFlag = true){
    analogWrite(fetOut, 0);
  digitalWrite(rOut, LOW);
  digitalWrite(dLED, HIGH);

void startUp(){
  int tempPot = 500;
  digitalWrite(sLED, LOW);
  tempPot = analogRead(pIn);
  }while(tempPot >= 450);
  digitalWrite(sLED, HIGH);

void idle(){
  int tempPot = 0;
  digitalWrite(iLED, LOW);
  tempPot = analogRead(pIn);
  }while(tempPot < 450);
  digitalWrite(iLED, HIGH);

void drive(){
  int potRead = 450;
  int mapVal = 0;
  digitalWrite(dLED, LOW);
  digitalWrite(rOut, HIGH);
  potRead = analogRead(pIn);
  if(potRead < 450){
    potRead = 450;
  }else if(potRead > 700){
    potRead = 700;
  mapVal = map(potRead, 450, 700, 0, 255);
  analogWrite(fetOut, mapVal);
  }while(potRead >= 450);

void timeout(){
  int tempRead = 0;
  int delayTime = 100;
  for(int i = 0; i < delayTime; i++){
    tempRead = analogRead(pIn);
    if(tempRead > 450){
      driveFlag = true;
      driveFlag = false;

What I am observing is the drive LED never shuts off so that means the code never gets past the drive loop in the main loop.

Code notes:

I am sourcing the LEDs so I am pulling them low to turn them on. 
The PWM and everything else works fine but the relay refuses to open with a low command to it.  I have tried to relay just using the arduino and it is capable of opening and closing it.  The arduino controls a NPN transistor to switch on the relay with no problem. 
So any code suggestions would be appreciated. 
3  Using Arduino / Project Guidance / Re: Wheres my voltage? (what am I doing wrong?) on: September 17, 2012, 12:23:02 pm
Like suggested check all your pinouts first (diode, transistor, etc).  Check your PCB for losses or flaws.  The PCB looks pretty clean so if you are getting the right voltage from the battery it should transfer fine.  i can't picture what your motor out looks like.   
4  Using Arduino / Motors, Mechanics, and Power / Re: can't run a bipolar stepper motor on: September 17, 2012, 12:13:52 pm
Need more information.  Do you have an example of your setup?  What is your power supply?  More information helps. 
5  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Motor Control with PWM and totem pole on: September 17, 2012, 09:47:48 am
Woops.  The 5ms is suppose to come from frequency to time which should actually be 2 ms for a 500Hz PWM signal.  I see what yours saying though.  I am still not super clear on the gates of mosfets as you can see.  Can you explain the switching loss a little more in depth (i don't see where this comes from)?  The only power calculations I did were for the load power dissipation needed to drive the motor.  27A rated at 22mOhm when the FET is on give me 16.038 Watts for power.  I plan on running two FETs in parallel like mentioned before to give me a max of 8 Watts of power for normal use per FET. 

The other thing is I am using 5V TTL MOSFET so I wouldn't switch at the 10V so the current would be higher.  So this gives me three viable options that I believe I have components for and I am capable of. 

1.) MOSFET driver.  I don't have the driver chips so I would have to wait and buy one.  I have never used one before but have read up on them when I was planning my original H-bridge design for forward and reverse.  I found a lot of information on using these on where he has built multiple projects.  It is pretty stable and can easily be driven by the arduino.  So that option is there is needed but not preferred since I can't implement it without buying the hardware.  I would probably go back to regular logic MOSFETs as well rather than the TTL for those.  I have some of them but this would be a redesign of my current circuit.

2.) PNP BJT driver.  I could use some PNP to connect the regulated 5V to the gates of the FETs.  I can drive the BJT with the arduino and that seems like it would be pretty simple.  I am only going to be able to get about 100mA out of the BJT most likely though.  I also have to make sure the voltage drop of the PNP doesn't interfere with the TTL logic or I will have to add more circuitry and implement the 12V signal to drive the TTL.  This I have parts for and it is cheap and simple.  The question comes down to is how much current for nice smooth switching.

3.) SN754410 H-bridge.  I have this chip as well.  I can use simple TTL logic from the arduino to toggle one of the quad outputs (or two) and connect the gates to the H-bridge.  This is able to supply 1A continuous if needed for a lot more power.  I can connect either the 5V or 12V gate to this and be able to control either.  This maybe a good option but I am not sure if there is a restriction on using an H-bridge to drive a FET.  Any ideas on this? 

I will look into the zener if need be for more protection.  I guess I can explain a little bit better how ideally this project works.  I attached a drawing of my current setup.  The drawing is crowded but here are the basics.
There is a key switch that connects the 12V to the regulator that is smoothed with caps.  12V is supplied to the 24V relay coil that is hooked to another switch to make or break that for an estop.  There is a third switch that turns on the controller.  The controller handles the following:
Reads pot for amount of throttle (alters PWM to the FETs).
Read that the relay has voltage
Turn the relay on by activating the BJT
Turn on the FETs but PWM controlling the gates

So the way the software works is that when there is a throttle given by the pot, the controller reads to make sure the relay has voltage.  If it does then the relay is activated while the FETs are still off (switches 0 volts).  The controller then PWMs the FETs to conduct the main path to the motor.  When the drive cycle is over, there is timeout period that will wait to make sure the user is done driving the motor.  Once that is complete the FETs are verified to be 0 and the relay opens.  This enables to arcing in the relay for safe operation (except for Estop).  I have fuses on both the 24V line (30A) and the 12V line (3A) (I didn't include).  I am hoping that with this architecture and control I can keep the current pulses down and a safe way to operate the motor.  I have a bunch more indicators that I left out as well to determine what stay the software is in. 

Currently everything works except the FETs.  The FETs currently won't turn on the LED when I PWM the gates.  That means that the conduction path is not complete.  So hints why I have so many questions about FET.  I have already broke a few too (measured diode voltage drops and resistance of the pins to verify) so I know I am not perfect and implementing them yet.  So any suggestion are always appreciated. 

Sorry the long and lengthy post but I just want to make sure I understand what is happening so I can control and modify it better. 
6  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Motor Control with PWM and totem pole on: September 17, 2012, 08:27:25 am
I am talking about the SN754410 H-bridge also.  So I would tie enable to Vcc and toggle the A pin to get the PWM out of the Y pin.  This be able to provide up to 1A for the gate to charge if needed.  Any issues with using this setup with an arduino?
7  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Motor Control with PWM and totem pole on: September 17, 2012, 08:22:35 am
Hello Mark,

Thank you for the reply.  I understand that fast switching requires the ability to be able to charge and discharge the gate capacitance sufficiently all the way for operation and heat issues.  I have some half bridges that I can probably drive this with if need be but I guess I am wondering if something like this really requires this?  We are talking about 500 Hz that the PWM is capable of for the Arduino.  You are talking about 5ms switching.  If I use the setup that has a 50 ohm resistor on the gate with a 10K pull down, I will be having time constants at 110 microseconds.  That is almost 50 time constants per cycle assuming max current.  Now with that said, I won't be supplying the max current of 100 milliamps since the channel doesn't allow it.  So assuming that you can only draw 40mA per channel that gives about 20 time constants per cycle which seems pretty reasonable to me.  Anything wrong with my theory?  If need be, I could just drive an H-bridge with the microcontroller to switch the FETs sufficently correct?

With that being said, my setup doesn't currently work with the 50 ohm on the gate and the 10K pull down.  I am still probing my circuit for the issue.  i am using a 24V battery for the main voltage source and a 12V battery for the controller.  The 12V is regulated to 5V and provides the power to the arduino.  I have an oscope and all the necessary tools.  I observe the PWM is correct and at 5V to drive the TTL logic MOSFET. 

Another question though on the same note.  Any ideas on what may be causing the microcontroller to reset by switching a relay?  I am driving a relay with a BJT that is driven by the arduino.  It is current limited to 20mA by the base resistor.  I am able to switch it fine but when the relay opens back up it resets the arduino.  The relay has a diode in parallal with the coil to take care of any voltages so I don't think it is that surge that does it. 
8  Using Arduino / Motors, Mechanics, and Power / Arduino Motor Control with PWM and totem pole on: September 14, 2012, 10:04:23 am
Hello Everyone,

So I am reading more and more into driving a motor with a FET from the arduino and have a few scenarios and questions.

First here is what I am using for a system.
24V motor, 500W, 27A rated
Estimated power = 500W/24V = ~21A at max
TTL MOSFET, 2000pF gate cap, 22mOhm RDSon
Arduino controller, PWM out (500Hz?), 5V out

Original option. 
Drive the FET with with arduino directly.  (Attached - ugly drawing)
So basically I would just put a 100ohm resistor in series with the gate and have a 4.7K pull down.
This results in a small voltage drop (4.9V still on gate) and would have the gate pulled down when off.
I may have to do two FETs to reduce heat though since the following:
Watts = I^2*R = 21^2*0.022 = 9.702W
So that is 4.851W per FET.
The problem I could see is that makes the gate capacitance 4000pF.  Could the arduino still switch at a fast frequency to control both of these with a PWM?  Can the arduino provide enough current to switch fast enough?  See any issues?  Could I run this with only one FET?

New option - totem pole.
So I looked for alternatives in case the power wasn't there for the arduino to provide.
Totem Pole (Attached)
First off, I haven't done a totem pole before so I have some questions:
I know that you need a current limiting resistor to drive the BJTs.
I know you need an out resistor for the FET gate.
Do you need a pull down resistor?  If so, do you put it on the output side of the totem pole or at the collector of the PNP?  Does the gate resistor count as the ground resistor because the PNP is on when the PWM is off?
So a PWM will turn on the NPN when high and the PNP when low so the gate will see the 5V for the on duration and be grounded during the off.  Does that sound right? 

Any suggestions for using a totem pole to drive a FET?

9  Using Arduino / General Electronics / Potentiometer reading question on: August 13, 2012, 08:48:52 am

I am making a motor controller with an arduino and using the pot as the throttle reading.  Quick question that is confusing me.  So ideally I want to read between 0 to max resistance and map that to the PWM out of another pin.  So ideally I should use a pull down resistor on the pot input signal to keep it low if for some reason the pot is disconnected.  For an example lets use an 10K pot.  It should be hooked up as follows.

             Analog in

Would this work or am I just setting a new lower limit for the analog in value?  What should the proper way be to use a pull down resistor for a pot?  What is the resistance for the pull down resistor?

Please let me know when you get a moment.  I always think I have it then I just confuse myself.
10  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Motor Control Issue on: July 19, 2012, 11:22:15 am
You are correct.  I mislabeled in the picture but I have it all connected correctly. 
11  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Motor Control Issue on: July 19, 2012, 08:15:47 am
Any ideas on this and why the duty cycle would affect the DC voltage of the VDS?
12  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Motor Control Issue on: July 18, 2012, 09:21:04 am
Here are some scope pictures and the setup picture.  A lot in one picture. 
13  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Motor Control Issue on: July 18, 2012, 08:56:41 am
I am doing all these test with an LED hooked up to the 24V source and being grounded through the NMOS.  So my observations are based on brightness and not on the motor response.  Changes the pull down resistor of the gate to a 1K seemed to make it brighter and more responsive.  I made a test program to start at 255 and decrease to 0 and sure enough at 255 it is off and the LED gets brighter and the voltage increases as it gets closed to 0.  Once it hits about 20 the voltage is almost at 24 but then we it goes down to about 15 the voltage drops out and the LED shuts off. 
14  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Motor Control Issue on: July 18, 2012, 08:33:42 am
Resurrecting this post.  So I have all the analog signal working fine and reading.  I do have an interesting PWM issue though.  With that same BUK nmos I have been using, It actually turns on when analogWrite is at 0 and not at 255 like expected.  What would cause this?  Also, when the FET first turns out it does pass the 24V that I can see through my scope but as the PWM duty cycle increases it is only at 5V again where it should be at 24V.  Any ideas why the voltage saturates after it goes above an analogWrite signal of like 20?  Please help! smiley-mr-green
15  Using Arduino / Motors, Mechanics, and Power / Re: Arduino Motor Control Issue on: July 12, 2012, 08:46:26 am
That is correct.  Once it goes below 400 it just drops off.  That is a good point and something I should check.  I will check the pot response tonight and report back.  If that is my only problem then I will be pretty happy.  smiley-lol
Pages: [1] 2