L298 current sensing... how does it work?

Hi all,

I have wondered for a while, and this thread reminded me to ask, how the current sensing on an L298 works...

More specifically, I see that shield has 2 chunky resistors for current sensing, and the site's Wiki provides this code:

int senA= A0;    // channel A current measurement
int senB =A1;    // channel B current measurement
int sensorValueA=0;
int sensorValueB=0;
double currentA=0;
double currentB=0;
void setup() {
}
void loop() {
 // read the value from the sensor:
 sensorValueA = analogRead(senA);  
 sensorValueB = analogRead(senB);  
 // canculate the driver current for both channel with: I=U/R
 currentA = sensorValueA/1024*5/0.5;
 currentB = sensorValueB/1024*5/0.5;
 delay(100);                  
}

The current sensor is presumably some voltage or other (hence the use of analog pin and Ohm's Law), but I'm not clear exactly.

Can someone please explain how this current sensing on a 298 actually works?

TIA,

Jim

You sense the voltage at the resistor. This is proportional to the current, related by ohms law. The resistor Values are generally quite low so that there is a small voltage drop. Chunky resistors are needed because they could be dissipating quite a low of power, as the currents could get quite high.

It is basically a voltage divider like you would use in other situations with the arduino.

Thanks Marco, So let's see if I got this: the mechanism inside the 298 generates a voltage on the sense line based on the current the connected motor is drawing?- that's what I wasn't sure on. Am I right then to say that if I simply stuck my Fluke across the sense pin and ground I'd see a voltage which is a reflection of the current?

(Then once we measure that voltage, as you say with a divider just as one would measure many other sensors, we use Ohm's Law to get back to the current)

Close.
The voltage is generated across the sensing resistors because they are in seriese with the load. Therefore current through the load has to go through the resistors to compleat the circuit to ground. The relationship between the current and resistor tells you what voltage you see for what current.
The rest you have right.

I've used current-sense Rs with the L298 chips, they go outside the chip in the sense line,
of course. One consideration is that you already lose 1.5-2V inside the L298 due to it's
being bipolar technology, and not MOSFET. Then, with the sense-R you lose a bit more. I
used 0.25-0.5 ohm sense-Rs, which give a v.drop of 0.5-1.0V for max currents of 2A, so
you can see the additional loss right there. 0.25 ohms is the better choice. Note, you
also need fairly robust Rs here, as 0.5V * 2A = 1 watt, which is a lot of wasted heat.

In my ckts, I just fed that voltage straight into the processor ADC, but for a more parts-
hungry ckt with less loss, you can use a small value R, like 0.1 ohms or less, and then
amplify the signal using a non-inverting opAmp ckt. Takes an additional 6-8 parts. You
need the amplifier, since the Arduino ADC will not have enough resolution to accurately
measure the voltage across the smaller Rs.

Lastly, it's also a good idea to use an RC noise filter between the sense ckt and the ADC.
I typically used 10K and 0.1 uF.

I am sorry for posting here, but it is related to my question. I have an l298 and i want to drive two dc motors (6V). I have not understand well what happens with the sense pins and if i should connect or not a resistor at those pins. By looking at the datasheet i saw that the sense node has a max value of 2 Volts, so if i would like to have, let's say 500mA maximum through my motor, if i put one resistor of 2V/500mA=4 Ohms that would work. But by some search i did, i got confused because i saw some examples where there was no resistor and the sense pins were grounded. If anyone could help... :confused:

Why would you be sorry? The sense resistors seem to be just for external current sensing purposes. So if no sensing is required they can be grounded directly instead which is tha same as using very low resistance for sensing.

1 Like

pii967:
Why would you be sorry?

You should be sorry - wasting your first time by posting in 5 year old necrothread, responding to someone who's not even a member at this site any more...

wvmarle:
You should be sorry - wasting your first time by posting in 5 year old necrothread, responding to someone who's not even a member at this site any more...

hahaha! "necrothread" youve made my day ! haha cheers