# Driver de motor de alta potência G2 18v17

Hello, friend, good morning!
I’m trying to use my CS pin from my pololu driver 18v17, but I’m confused. For example, when I feed my driver with the voltage of the motor (12V) I have to measure 20mV, plus a displacement of 50mV. I’d like to do a test similar to this link:
Watch the video:

``````void loop ()
{
// calculate voltage
volt = (5.0 / 1023.0) * analogRead (c_sens); // Read the voltage from sensor
volt = volt = 0.050;
// calculate current (pololu 18v17 variation 20mV / A)
c_value = volt / 0.020;

// Print data via serial
Serial.print ("V:");
Serial.print (volt, 3);
Serial.print ("V | I:");
Serial.print (c_value, 2);
Serial.println ("A");
delay (800);
} // end loop
``````

With this code I could not get the current proportional to the voltage of my motor.

How can I best use the CS pin to work with the current proportional to voltage?
Do you have any explanatory video or code explaining how to use the CS pin?

Thankful!

Marcio Figueiredo

Hello, Marcio.

I noticed there is a typo in `volt = volt = 0.050;` of your code. You probably meant to type `volt = volt - 0.050;`. What values are you getting? Can you elaborate more on what you are trying to test? I could not understand the video you linked, since it is presented in a different language.

- Amanda

Hello Amanda, thank you for the reply, good morning!

I am trying to get current values ​​proportional to voltage values ​​for my DC motor using the current sensor output from my driver (pin CS). In the information of the site says that:
(CS): Current sense output: This pin outputs a voltage proportional to the current motor when the H-bridge is driving (but not while it is braking, including when current limiting is active). The output voltage is about 20 mV / A plus at 50 mV offset.
The Video I submitted shows the test of a current sensor, and I tried to use the same logic to test my driver, but I do not know if that is enough for me to get these correct values.
Is there any way for me to get the current proportional to the voltage of my DC motor through the CS sensor of my driver?
The code below will not answer my request. Could you help me with a better code?

``````#define c_sens A0
float volt, c_value;
#define dir 4
#define pwm 5
void setup ()
{
pinMode (dir, OUTPUT);
pinMode (pwm, OUTPUT);
pinMode (c_sens, INPUT);
Serial.begin (9600);
} // end setup

void loop ()
{
digitalWrite (dir, HIGH);
digitalWrite (pwm, HIGH);
volt = (5.0 / 1023.0) * analogRead (c_sens); // Read the voltage from // sensor
volt = volt - 0.050;
// calculate current (pololu 18v17 variation 20mV / A)
c_value = volt / 0.020;

// Print data via serial
Serial.print ("V:");
Serial.print (volt, 3);
Serial.print ("V | I:");
Serial.print (c_value, 2);
Serial.println ("A");
delay (800);

} // end loop
``````

Grateful for the attention!

Marcio

Please explain what that means. What does the code actually do?

For measuring voltages less than about 1.1V with a standard Arduino, it is much better to use the internal analog voltage reference (about 1.1V). For best results you need to calibrate the measurements. See http://www.skillbank.co.uk/arduino/measure.htm

In addition to answering Jim’s question, what values are you expecting and what values are you getting when you run your code? Can you post specifications or a link to the product page or datasheet for your motor?

- Amanda

Hello Jim, good morning!
I did not understand your answer, this 1.1V ?? Could you explain?
What could I change in my programming to make the correct measurement on the CS pin?
Thankful!

Marcio

Hello Amanda, thank you for the reply, good morning!
That answer is for Jim_Remington too.

I would just like to get the motor current proportional to voltage across the CS pin. When I execute the code that I sent, the values ​​are not correct. Your pololu site says that when the motor current is zero, we need to have 20mV on the CS pin plus a 50mV offset ??. By doing a basic test I fed the 18v17 driver and measure one voltage at CS pin 34.5mV as you can see in the attached photo. Another question I have: Should I power the driver in (Vin) do I have to get the 20mV in the CS pin independent of any programming?

I have these engines bought in aliexpress:

They are not reliable in terms of quality, I should buy the ones from Pololu.

I am using a DC motor from this seller of 600RPM 12V.

Grateful for the attention!

Marcio

Amanda or Jim,
Will it be necessary to estimate the parameters of my motor??
How to do this to get accurate parameters?

Marcio.

It think you misread the Pololu G2 High-Power Motor Driver 18v17’s product page regarding the current sensor. The output voltage of the CS pin is about 20 mV/A plus a small offset (which is typically about 50 mV). Since it looks like in your test there was nothing connected to the driver’s outputs (so the current was 0A), the reading you are seeing on your multimeter is the offset value for your unit. When you run your code, what values are you getting?

Please note that the current sensor on the G2 HPMD is intended mostly as a rough estimate and is not very accurate at low currents. If you require better accuracy, I recommend adding one of our current sensors to your system.

Can you measure voltage on the CS pin with your motors running at 100% duty cycle under some load and let us know what that is and what your supply current reads?

- Amanda

Hi, Amanda, good morning!
I understood your explanation, I read the current and voltage data through the serial monitor but I still find it strange, see the attached photo.
The code I use is this:

When I run the code, in my power supply the motor current is 190mA, the voltage is 12V (maximum duty cycle) and I am reading 37.5mV on the CS pin measured with a multimeter.
IS THIS CORRECT ??

I do not know how I will include in my code information regarding the document that Jim sent … I have little knowledge in programming to solve. How can you improve, do you have any practical examples so that I can understand this better?

Marcio

code_CSpin.txt (1.0 KB)

We do not have any examples for using the CS pin on the G2 HPMD board.

The ADC for an Arduino has a 10-bit resolution, meaning the ADC can only sense 1024 (2^10) discrete analog levels. By default, the analog reference is 5 V on the Arduino Uno, so the resolution between readings is ~4.9 mV per unit. (Jim’s post suggested using the Arduino’s built-in reference, INTERNAL, for measuring voltages 1.1 V and lower (1023 = 1.1V).)

With a current draw of 190 mA and the resolution of the CS pin being 20 mV/A, the CS output would be ~3.8 mV. When you try to read the CS pin, most likely the value returned is 0, since the Arduino’s default voltage reference is unable to detect below 4.9 mV. If you substitute 0 into your code for `analogRead(c_sens)`, `c_value` equals -1.37, which is what you are getting. As I said in my previous post, the current sensor on the G2 HPMD board is not very accurate at low currents. Also, where did you get the 0.007 value from?

Did you try putting any additional load on the motor to increase the current draw? It does not seem to be the case judging from your first picture. If you did not, can you modify your code to output the values for `analogRead(c_sens)` before running the program again with your motor under some load? Please let us know the results.

- Amanda

Hello Amanda, good morning!
I understood your explanation well, I’m evolving because of your help, thank you!
The value of 0.007 was the code of the video I sent, when the teacher says that when we have an external connection with a microcontroller we have a small voltage drop and he used this value because he is also using the arduino, but I think it will not change nothing in my code due to your explanation, I will remove it.
I have a question about the 1023.0 I will replace with 1.1V and use the function analogReference (INTERNAL) or I will only use the function in void setup () and I should delete the line of code: volt = (5.0 / 1023.0) * analogRead (c_sens); ???
One thing I did not understand was also when you said that:
“… If you replace 0 in your code with analogRead (c_sens), c_value equals -1.37, which is what you are getting …”

How would the code look?
Do I have to calibrate these measures to improve?

Like I said before, I’m kind of confused by the code.

Thankful!

Marcio

Hello Jim, good morning !!
I’m trying to make the calibration where you have it (Calibration example and scaling factor calculation):
http://www.skillbank.co.uk/arduino/calibrate.htm

The author says that:

"I connected the battery to the input and the reading was 2950.
So the voltage would be V = 2950 * 3,275 / 6474 = 1492 mV.
My meter showed it was 1495 mV … "
My values for the scale factor were: V (mV) = 3280/6988 = 0.4693 (I stopped here).

When it says it connected a battery in the input and that the reading was 2950 where it see this value? Did he connect a battery to the A0? Was the battery 2.95V? I did not understand this reading, could you explain?

And the next code is just that:

const float scalefactor = 0.4693; // my scalefactor: yours will be different!
float voltage = sum * scalefactor; // convert to voltage in millivolts
Serial.print (“voltage in mV is:”);
Serial.print (voltage, 0);

I’m waiting for your help !!
Thankful!
Marcio.

I apologize for the confusion; that paragraph is incorrect. I forgot to account for the offset value in the calculations.

Using the Arduino’s built-in reference will give you a better measurement of the CS pin’s voltage output than the default. You would need to change the voltage reference value in `volt = (5.0 / 1023.0) * analogRead (c_sens);` from 5 V to 1.1 V since the range is from 0 V to 1.1 V and not to 5V.

Yes. Jim has pointed to a good resource on getting a more precise measurement on the Arduino.

I looked at your code again and noticed you are outputting the CS voltage value after subtracting the offset. You should output the CS voltage reading before converting the CS voltage in terms of current:

``````volt = (5.0 / 1023.0)*analogRead(c_sens);// Read the voltage from sensor
Serial.print("V: ");
Serial.print(volt,3);
``````

Before we continue troubleshooting, please address the questions in the last paragraph of my post:

- Amanda

Hello Amanda,

I still have not put an additional load, the only load is the DC motor of the link that I sent and that has a resistance value of 5.5 OHM’s, do I need to add another load to leave the precise resolution ?? In my photo project I already added the 100K resistor between Vref and GND, would that influence?
How do you imagine this extra load? Do you have any idea?

In the video that I sent the teacher puts a resistor of 12 OHM’s for 10W and the applied voltage is 12V, in this case there is a current circulating of 1A by the resistor … I understand where you want to get … I understood! !!

I’m waiting!

As for adding load to your motor, you can do so by adding a wheel to the motor shaft and squeezing it. This will increase the torque and current (since they’re proportional). Alternatively, you could use a power resistor like the one in the video.

Adding an additional resistor between VREF and GND on the G2 HPMD board lowers the current limiting threshold; it does not affect the current sensor’s resolution.

- Amanda

Hello Amanda,
I apologize for the previous post that I said that the resistance was 5.5 Ohm’s, because I gave you information of a motor of 12V, 400RPM and 100mA of current without load, but I did not use this motor yet, it was like this:

But you can consider my calculations with the motor of 12V, 600RPM and 200mA, I measured the resistance and gave a value of 17 Ohm’s ok! apologies!!

I measured the resistance by placing an LCR and then an analog multimeter for confirmation, estimated the values ​​by blocked rotor, applying voltages from 1V to 6V, then measuring the current by calculating the resistance and averaging these values. Do you have a better way of estimating my DC motor parameters so that I can continue to do everything with higher quality? As a matter of fact this is influencing bad results !! By what method do these processes occur? Most manufacturers do not provide these values ​​(Resistance, Inductance, Mechanical Time Constant, Electrical Time Constant, Coefficient of friction, moment of inertia), as I will need to program the controller . I am sending some photos of these values ​​with two models of these meters and the .pdf I am using to estimate parameters, but I do not know if I should do it this way.
Does the sensor that indicates the ACS714 would be better for my project or using the CS pin gives me to evolve in the code? Because I’m still confused in programming this pin.

I am grateful and I look forward to your help !!

Seaton, Dave - Application Note.pdf (398.3 KB)

Before you continue with calibrating your measurements, can you tell me more about your project and what you plan to do with the current readings? How precise does the current reading have to be for your application?

- Amanda

An important circuit for my design is that the current reading of the motor is performed, which is done with the resistance (0.1 OHM) in series with the same force of the motor or the variation of the speed of the wheel, making it capable of overcoming the force of friction, without harming its performance. Since, a voltage on the resistance is a current, the signals to the data that are analyzed by an ADC. Therefore, the INA826 instrumentation amplifier is used. The figure (attached photo) shows the internal circuit diagram of the INA826 amplifier. The gain of this amplifier is a controller of an external resistor, as shown in Eq.
G = 1+ (49.4KOhm / Rg)
By adjusting the gain of the amplifier to 10, the output signal has the resolution of 1 V / 1 A.

Based on this text of work done at my university, I wish I could get the current from my motor proportional to voltage, Amanda understands?
But it does not necessarily have a resolution of 1V / 1A, but I have a reference that with certain current value I have my voltage. I also want to get current and voltage graphs with my HPMD G2 Driver as shown in Figures 2 on page 4 of the attached article.
I’m a little confused in calibration, but I’ll try!

Thankful!

Artigo Jovelino.pdf (1.1 MB)

Hi, marciof14.

Since it sounds like your ultimate goal is to be able to use the motor current measurements to tell when there is extra load (to get a constant torque or speed), it seems like the built-in current sensor on the high-power motor driver might be fine, and you might not need to do any special calibration like Jim posted about.

In a previous post you said with your motor attached that you read 190mA at your supply and 37.5mV on the CS pin. Taking into account the 34.5mV offset you measured earlier, that means the driver was reporting 150mA of current. That seems pretty accurate considering those are pretty low currents and that the power supply is providing power for at least the driver logic as well.

I suspect in that case the output from your code was negative because the current (and therefore CS pin voltage) was so low. The Arduino analog read feature can only read voltages in increments of 4.9mV, and 37.5/4.9 = 7.65, which might be truncated to just 7 ticks out of 1023. That means your code would output (5/1023)*(7) - 0.0345 = 0.0342 - 0.0345 = -0.0003A. You could check for a situation like that by printing the actual analog reading you get before you do anything with it in your code.

That kind of situation is why Amanda has asked a few times for you to try adding a load to increase the current to something closer to 1A. Could you try doing those things and see what output you get from your code and how it compares to the readings from your meter?

-Claire