Driver de motor de alta potência G2 18v17

Hello Claire, good morning!
Yes, I understood your explanation well, as well as Amanda’s. The driver works very well, even if the uncharged motor current fluctuates a bit, the HPMD G2 responds to the calculations. You told me to add load, and I did the following, I held the wheel a little so as not to rotate with the maximum speed and to increase the current, as you asked, when the current reached approximately 0.950A the voltage of the CS pin was approximately 52mV (measured with the multimeter), I’m happy because we know it’s very good, Amanda also said that. And the interesting thing is also when I locked the shaft, the value of the CS pin was the 20mV of the result of my driver … within the expected, because as it has in the datasheet, the values ​​are read, but not with the engine locked.
What I was confused was with the readings with arduino, that made it difficult for me to better understand my HPMD G2.
You asked in the second paragraph for me to do the analog reading before doing something else, I did it:

void loop ()
{
   // c_value = volt / 0.02;
  // volt = volt + 0.0345;
  volt = (5.0 / 1023.0) * (7) - 0.0345 * analogRead (c_sens);
  // Print data via serial
  Serial.print ("V:");
  Serial.print (volt, 3);
  Serial.print ("V | I:");
  Serial.print (c_value, 3);
  Serial.println ("A");
  Serial.print (c_sens, 3);
  Serial.println ("mV");
  delay (800);
} // end loop

I get these values:
V: -0.138V | I: 0.000A
121mV

Is that what you want me to do ??

Thanks again for all, Amanda, Jim and Claire.
I’m waiting for more help!

Marcio

Could you try printing the analog readings before you do any processing of them (i.e. print the value of just analogRead (c_sens))?

-Claire

Hello Clarie,

const int c_sens = A2;
void setup() {
  pinMode(c_sens, INPUT);
  //analogReference(INTERNAL);
  Serial.begin(9600);
}
void loop() {
  Serial.println(analogRead(c_sens),3);
  delay(1000);
}

I print these values in analogRead (c_sens) only with the arduino connected to USB without internal reference:

112101
112010
111211
111112
111020

I print these values in analogRead (c_sens) with the arduino attached to the CS pin and with analogReference (INTERNAL);

120
121
102
100
21
102

I print these values in analogRead (c_sens) with the arduino attached to the CS pin and without analogReference (INTERNAL);

0
2
0
0
1
1
0

Thankful,
I’m waiting!

Marcio

Serial.println(analogRead(c_sens),3);

It looks like you are printing your analog reading in base 3 rather than standard base 10 (for decimal numbers). When using the Arduino println function with integers (rather than floats) the second argument sets the base (not number of decimal points). Please remove that from this test code and try again.

-Claire

Hello Clarie,

I did so in code:

float c_sens = A2;
// int c_sens = A2;
// const int c_sens = A2;
void setup () {
   pinMode (c_sens, INPUT);
   analogReference (INTERNAL);
   Serial.begin (9600);
}
void loop () {
   Serial.println (analogRead (c_sens));
   delay (1000);
}

With the float, I got:

20
12
12
12
13
12

With cons int, I got:

20
14
14
14
13
12
14

With int, I got:

24
15
17
16
19
16
17

I used all with analogReference (INTERNAL);
Sounds good, is not it Claire?
I’m waiting!
Thankful!

From those readings it looks like the offset you should use in your Arduino code is around 13mV. That corresponds with your lowest readings of 12 counts of the ADC with the internal 1.1V reference.

Could you try the same test with the motor loaded to close to 1A? You do not need to do the test with both floats and ints; just one is enough.

-Claire

When I held the shaft for a while, but not to stop, the motor current increased near 900mA the values were:
30
26
34
30
25
38

I’m waiting!

If you use an offset of 13mv like I suggested in the last post to do the following calculation:

(1100mV/1024counts * number of counts - 13mV)/20mVperA

You get a range of about 0.7-1.18A, which seems reasonably close to 0.9A. Since you were just holding the wheel by hand, the large variation could be due to variations in the amount of pressure you were using. To test the precision of the CS output better, you could use something like a power resistor to get a constant current to measure. You might also want to average many samples of the current reading in your final application.

-Claire

Hello Claire, sorry for the delay … good morning !!

I put a resistor (10 OHM’s per 5W) as in the picture below and get these values. I think we need to find values ​​on the serial monitor equal to or closer to the original value, how can I improve those values ​​being closer in this code? I think we are finding good values, but we can still improve to give quality to my project. I would also like to know how to display the values ​​with the serial plotter, can you explain me?
This is the code of the values ​​below and I also have a photo of the circuit:

const int c_sens = A2;
float volt;
#define dir 7
#define pwm 6
#define slp 10
void setup () {
  pinMode (dir, OUTPUT);
  pinMode (pwm, OUTPUT);
  pinMode (slp, OUTPUT);
  pinMode (c_sens, INPUT);
  analogReference (INTERNAL);
  Serial.begin (9600);
  digitalWrite (dir, HIGH);
  digitalWrite (pwm, HIGH);
  digitalWrite (slp, HIGH);
  }
void loop () {
  volt = (1.1 / 1024 * 12 - 0.013) /0.020; // result: volt = -0.005469
  Serial.print ("V:");
  Serial.print (volt);
  Serial.print ("V | V:");
  Serial.print (analogRead (c_sens));
  Serial.println ("mV:");
  delay (800);

Motor off
Multitester (original value):
I (resistor) = 0A | CS_pin = 34.5mV
Values ​​on the serial monitor:

V: -0.01V | V: 28mV:
V: -0.01V | V: 28mV:
V: -0.01V | V: 28mV:
V: -0.01V | V: 27mV:
V: -0.01V | V: 28mV:
V: -0.01V | V: 28mV:

Motor on
Multitester (original value):
I (resistor) = 1.2A | CS_pin = 56mV
Values ​​on the serial monitor:

V: -0.01V | V: 49mV:
V: -0.01V | V: 49mV:
V: -0.01V | V: 50mV:
V: -0.01V | V: 49mV:
V: -0.01V | V: 49mV:
V: -0.01V | V: 50mV:

making:
20mV * 1.2A + 34.5mV = 58.5mV

Thanks for the help!

Marcio

If you are getting 28mV read form the Arduino when no current is flowing, then that is what you should use in your code as the offset. Comparing the mV reading of the CS pin from your meter and Arduino (taking offset into account and averaging your Arduino readings) we get:

Meter: 56 - 34.5 = 21.5mV
Arduino: 49.333 - 27.8333 = 21.5mV

So it seems like the Arduino is measuring fairly accurately. As for that measurement not totally matching the actual current through the resistor, if you want more accuracy (especially at low currents) you might want a dedicated current sensor like our 5A ACS714.

-Claire

Ok Claire, very good !!

I would like to print this value of 56mV, identical to the value of the multitester or as you said I have to acquire another sensor (5A ACS714)? As the value being printed is approximately 49mV, if I add 7mV I would get the exact value of my reading, but when I put it for example: Serial.print (analogRead (c_sens)) + 0.007;
The same value is shown on the serial monitor, because this sum does not happen?

I have another question: How best to estimate the parameters of my DC motor ?? Do you know a safe and accurate process ?? That person is using the DC motor equal to what you sell. I’m researching a lot of how to do to estimate the parameters of my DC motor to get my transfer function and design my controller as best I can.
Would you recommend this site?
http://ahtakoru.com/brushed-dc-motor-identification-simulink-estimating-pololu-metal-gearmotor-parameters-example/#comment-2143

I’m waiting!
Thankful!

Marcio

The statement Serial.print (analogRead (c_sens)) + 0.007 will not add 0.007 to the sensed value before printing since it is not contained within the print statement’s parentheses. Also note that just an analog read of the CS pin does not give you an output of millivolts. You need to convert it by multiplying by 1100/1024.

We do not have any specific advice for estimating your motor parameters.

-Claire

Claire,
I put the possibilities for the sum to be performed, but I still did not get the correct value as read by the multimeter: 56mV
Still have a solution? Am I making mistakes on anything?

void loop () {
   digitalWrite (slp, HIGH);
   volt = (1100/1024 * 12 - 0.028) /0.020;
  // Serial.print (analogRead (c_sens) + 0.007);
  // Serial.print (analogRead (c_sens + 0.007));
  // Serial.print (analogRead (c_sens)) + 0.007;
   Serial.println ("mV");
   delay (800);
}
// Serial values print:
49.01 mV
50.01 mV
49.01 mV
48.01 mV
50.01 mV
49.01 mV

After finishing this step, I have one last question, okay.

I’m waiting!

Just doing an analog read of the CS pin does not give you a value in mV. You have to convert the reading by multiplying by 1100/1024 when you are using the internal 1.1V reference. Also, I suspect you want to add 7mV (0.007V). Currently your code is adding 0.007mV.

All of your recent questions have been about understanding programming concepts and Arduino functions which are outside the scope of our technical support. I suggest finding someone locally that can help you with programming.

-Claire