Go Down

Topic: Shunt Resistors and Input Pins (Read 2 times) previous topic - next topic

jc4003

I'm trying to measure the current going through a DC motor so that I can implement some kind of velocity control, but I'm a bit stuck as to how to implement the circuit.

I have a low resistance resistor in series with the motor which is powered by a motor shield on an Arduino Mega, and I'm trying to measure the voltage across the resistor. The motor shield provides a maximum of 12V and the motor draws up to 1.2A.

However, I'm not sure how to set this up with regards to input pins and grounds. The lowest resistance resistor I have available is 0.47 ohms, is it likely Ill need to go out and find something lower?
Thank you in advance!

Groove

Your resistor should drop just over half a volt at 1.2A.
You may want to look at using the internal Aref, which is around 1.2V, IIRC.
Per Arduino ad Astra

jc4003

Good idea, I'll use the internal Aref.

I was more stuck on how to wire up the resistor to the arduino however, any ideas?

Grumpy_Mike

Resistor to ground other end to the arduino analogue input and the -ve of the motor. Wire the +ve of the motor to the +12V power and the 0V of the power supply to the arduino ground..

jc4003


Grumpy_Mike

#5
Mar 09, 2010, 05:46 pm Last Edit: Mar 09, 2010, 05:46 pm by Grumpy_Mike Reason: 1
Yes.

You might like to put a bit of protection on the analogue input just in case you get a higher voltage on it.
http://www.thebox.myzen.co.uk/Tutorial/Protection.html

jc4003

Thanks a lot, this works really well.

However, I'm having some odd readings from the analogue inputs. They will often give a reading of 0 volts every other time they are read i.e. when the program is run they give something like 0 40 0 40 0 40 0 40.

Any ideas? This only happens when I use the voltage reading from the resistor for control, it seems fine when the voltage source is constant and I simply print the voltage over the resistor.
The code for the loop loop is
void loop()
{
  VshuntR=analogRead(Ipin);
  error=r-VshuntR;
  Vin=error*K;
 
 digitalWrite (dirA, HIGH);    
 analogWrite (speedA, Vin);
 
     delay(100);
     Serial.println(VshuntR);
     
   }
     
Many thanks

Groove

Are you sampling the "LOW"s of your PWM?
Per Arduino ad Astra

Blarp

Some offhand suggestions:

- Add an idling diode across the motor (to catch the backlash from the inductive load) - best use a fast shottky

- Measure the voltage over the shunt using a RC filter (e.g. 1K, 1..10uF, make RC time larger as PWM cycle). This kills the spikes and gives you nice average current, and protects the analog input.

If it is a std commutating DC motor, there will be agressive spikes during PWM switchovers. Connecting a scope can be very instructive..

1K + chip internal clamping diodes will handle most overvoltage spikes if any.

FWIW I connect all off-board wiring from the chip with at least 1K's - it gives the cpu a fighting chance against ESD. YMMV

cr0sh

Something also to note about shunts: Unless you are using an actual shunt resistor (specially made from a special allow, with very low resistance), your measurements can and will vary with temperature, run time, etc. It may not be enough to bother you or what you are doing, but it is something to be aware of, all the same.
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

org00h

That easy,let me find some information to you

Go Up