This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adapting motor.ino for a ACS712 current sensor
#1
Hello,

I started building up a pypilot controller with a MD13S I had in possession. The setup seems to be working fine, but since this controller is missing a current sensor, I added a VMA323/ACS712 sensor.

This sensor measures currents from -20A (~0V) to +20A (~5V) with a 0A corresponding to an offset of 2.4V approximately. It has a sensitivity of 100mV/A.

I connected its output to the A1 pin of the Arduino nano.

This is what I've done to motor.ino so far:

- #define VNH2SP30, DISABLE_TEMP_SENSE, DISABLE_VOLTAGE_SENSE, DISABLE_RUDDER_SENSE (I do not have sensors for this yet)

- in TakeAmps(), replace:
Code:
if(pwm_style == 2)
  return v * 9 / 34 / 16;

with:

Code:
if(pwm_style == 2)
  v = v * 5000 / 1024 / 16;
  if (v > 2400)
    return v - 2400;

  return 0;

- Since I need an analog measurement range from 2.4V to 3.4V (approximately), and as far as I understand, the current definition of adcref=_BV(REFS0)| _BV(REFS1) provides a range from 0 to 1.1V, I replaced it with adcref=BV(REFS0) everywhere in the code (two lines changed) to get a 0 to 5V range.


Now when I plot the current on openplotter's pypilot scope, I can see that the voltage offset is properly handled (0 when no current is flowing into the sensor; if I replace 2400 with a lower value in the code, I get a positive value for 0 amps).
But the value increase when current starts flowing in the motor is invalid:
- 100mA --> 1.3

- 1.7 A  --> 3

Direct voltage measurement on the ACS712 sensor shows that the sensor works fine.


It seems this increase is not linear, which is what I would have expected. Is there something else I could have missed or misunderstood in the file?

Thanks for the help!
Reply
#2
sorry to be negative but those current sensors really aren't very good, plus the ADC of an arduino isn't really accurate enough for the very small voltage changes needed to go down to less than an Amp resolution. A better way imho is to use an ina219 & use a different shunt from ebay. The INA has an built in low noise amplifier which can measure the tiny voltage difference across a shunt.
Reply
#3
If you change to the 0-5v range, you need to ensure you use ratiometric mode then. This will fix the voltage calculations and you will use different resistors there too. This can be enabled by tying D4 and D5 to gnd.

You will need special logic to handle this sensor with 2.4v center point and maybe some logic to zero low enough readings.

If you can please use the original code in github and tie D4 and D5 to gnd, then what do you get for current readings? Then modify TakeAmps()
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)