Arduino Motor Control Issue

Hello Everyone,

So I have been playing around with a simple LSD motor design for awhile and I am almost at the end. I have one last issue that i think I might know the problem but I wanted more feedback on it. So I am using the BUK9507 TTL NMOS on the LSD. I plan on just using a PWM to drive the TTL gate based on a pot input. The way the code works is that it reads the pot input and divides it by 4 to get the analogWrite value. When the pot is off the values are 1023 on the input and analogWrite value of 255. As the analog value is reduced the gate becomes active. This works perfectly until a point at around 400 for the analog input value. At this point the value drops to 0 instantly and there is no power to the load. I am prototyping with a LED hooked up to 24V until I get everything down right. So I have hooked the signal up to my o-scope and see that the PWM does change at thing point. It is still a PWM but I believe the amplitude drops from the normal 5V to a smaller voltage. So from that result I am guessing that maybe the PWM port cannot provide enough current for the gate? But then again why would the LED light up to 80% on and then have this problem? I have the pot pulled up with a resistor and i also have the PWM pulled down with a resistor. This ensures that the analog signal will be high when nothing is hooked up and the gate will be off. So with all that being said, does anyone have a guess on this issue? I can post more details about the code when I get home but the basics are below:

int throttleval = 0;
int throttlepin = 1;
int gatepin = 10;

void setup()
{
 pinMode(thottlepin, INPUT);
 pinMode(gatepin, OUTPUT);
}

void loop()
{
 thottleval = analogRead(thottlepin);
 setPWM(thottleval);
 delay(100);
}

void setPWM(int throttleval)
{
  int tempval = 0;
  tempval = throttle/4;
  analogWrite(gatepin, tempval);
}

I just free handed the code from memory but I think its close.

So summary: Control works fine until about 80% on time of PWM and then it drops off to 0.

I am prototyping with a LED hooked up to 24V until I get everything down right.

Can you provide a drawings of your hardware set-up? Resistors value, how you hook-up pot and pull-ups etc.

I have attached my setup. Here are some key points:
All grounds are tied together.
The 12V is used to power the arduino.
The Pot is powered by the regulated 5V of the arduino
The pot is pulled up with a 10K resistor
The Gate is pulled down with a 10K resistor
There currently is no current limiting resistor on the gate
There is a current limiting resistor for the LED
There is a cap for the 12V source (I was having some noise in the signals)

Overall it is a pretty simple setup.

Arduino_Setup.JPG

The code you posted contains several errors and doesn't make sense. Please post the actual code you are using.

You should have a resistor (100 to 220 ohms) between the Arduino output pin and the mosfet gate, but otherwise your circuit looks OK to me.

The issue could be related to high input capacitance of this MOSFET : 2530 - 3373 pF at 25V . I just compare to SFE: N-Channel MOSFET 60V 30A - COM-10213 - SparkFun Electronics which is only 1350 pF and 800 - 1040 pF for two types of their products.
As pulse getting shorter when value given to analogwrite become small, I think arduino output is not powerful enough to recharge capacitance in time. There are different freq. of PWM at different outputs, like 490 and 960, I'd try if there is noticeable deference in threshold (400) when effect become an issue, or even try to set lower freq. for PWM. Other way, is buffer output with special mosfet driver or BJT.

Here is my current code.

int throttlepin = 1;
int throttleval = 0;
int gatepin = 10;

void setup(){
  pinMode(throttlepin, INPUT);
  pinMode(gatepin,OUTPUT);
  digitalWrite(gatepin, LOW);
  Serial.begin(9600);
  delay(100);
}

void loop(){ 
  throttleval = analogRead(throttlepin);
  if(throttleval < 400){
    setPWMOut(200);
  }else{
    setPWMOut(throttleval); 
  }
  Serial.print("Read: ");
  Serial.println(throttleval);
}

void setPWMOut(int tempthrottle){
   int tempval = 0;
  tempval = tempthrottle/4;
  Serial.print("Out: ");
  Serial.println(tempval);
  analogWrite(gatepin, tempval); 
  delay(1000);
}

This code has a high delay to see the differences. The normal delay would only be like 100ms

What is the intended purpose of this code:

  if(throttleval < 400){
    setPWMOut(200);
  }else{
    setPWMOut(throttleval); 
  }

Its effect is to cause the PWM to drop to 50 whenever the pot reading is below 400 - rather like the behaviour you are complaining about.

I forgot to comment on that. For testing I did add this part of the code. Since the LED goes out once the analogRead goes below 400ish. That is where the problem is. Whenever the analogread goes below 400 it basically instantly drops to 0 which because of my code drops the PWM down to 0. This should be ok and result in full on but it doesn't. Instead the LED turns off, which in turns means the NMOS is now off. That is the problem. I am not sure if it is the code of like some others have suggest, maybe the gate capacitance. The gate input cap is a max value of 3373 pf. I added a 180 ohm resistor on the PWM line to limit the current but it also increases the time constant to charge the gate. Any ideas of what might be happening or what I might need to change? Is the frequency too high? Is the code bad? Is there a pot issue?

I think I misunderstood your first post. If I understand correctly, you are saying that analogRead never returns values between 1 and about 399, but as you turn the pot it moves directly from around 400 to 0. If that is the case, then perhaps you have a faulty pot. Or maybe it is a log-law pot instead of a linear pot. What happens if you reverse the end connections of the pot?

I don't think gate capacitance has anything to do with it. The Arduino PWM frequencies are low enough that the time taken for the gate to charge (about 1us) is small in comparison with the PWM interval.

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. XD

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! :grin:

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.

Here are some scope pictures and the setup picture. A lot in one picture.

Any ideas on this and why the duty cycle would affect the DC voltage of the VDS?

TO220 MOSFETs are gate-drain-source, not gate-source-drain

[ the way to remember this is that the middle pin is internally connected to the metal tab which is bonded to the chip's substrate which is also the drain in a power MOSFET ]

You are correct. I mislabeled in the picture but I have it all connected correctly.