Rug Warrior Pi: Build Blog (a PiDA bot)

Moderator: Steve

Re: Current Sensor - ACS712

Postby alanmcdonley » Fri Sep 04, 2015 9:18 am

Deleted - wrong
Last edited by alanmcdonley on Fri Sep 04, 2015 3:59 pm, edited 1 time in total.
alanmcdonley
 
Posts: 90
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

Re: Rug Warrior Pi: Build Blog (a PiDA bot)

Postby mikronauts » Fri Sep 04, 2015 9:51 am

Very close!

1A = 0.185V on the +/- 5A version of the ACS712

so

-5A = 2.5V - 5*(0.185V) = 1.575V
0A = 2.5V
+5A = 2.5V + 5*(0.185V) = 3.425V

(1.575V * 1024) / 5 = 322.56 read from the ADC

512 is the 0A reading

(3.425V * 1024) / 5 = 701.44 read from the ADC

Worst case accuracy is +/- 0.5 LSB for the ADC, and +/- 7.68 bits for the ACS712, so ranges from -8.18 bits ... +8.18 bits

Theoretically you can get more (meaningless) resolution by using an op-amp to subtract the 2.5V center voltage, with a gain of 2.x, however the amplified signal will be meaningless, and not be any more accurate.
mikronauts
 
Posts: 119
Joined: Tue Sep 16, 2014 6:58 pm

Re: Current Sensor - ACS712

Postby alanmcdonley » Fri Sep 04, 2015 3:49 pm

Thanks, now I understand:
Code: Select all
5000 mV               1Amp             1000mA
--ADC----     x  ----Sensor------  x  -----------  =   26.39358 mA per "reading bit"
1024 "bits"           185mV            1 Amp


zero_reading = 512 # (unless median zero reading is actually 511 or 513)
current_in_mA = (reading - zero_reading) * 26.39358
alanmcdonley
 
Posts: 90
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

Re: PWM to Servo Pins Crosstalk

Postby alanmcdonley » Fri Sep 04, 2015 8:18 pm

I get serious cross talk from PWM pins to undesignated GPIO/"PiDA Servo" pins, and major current draw, when I have not set the servo pins to servo mode before ramping up the DC motors.

When I ramp up PWM for both motors (servo pins 6, 7), my tilt/pan servos (which do not have a mode set yet) ramp in position and the total current draw is around 1A.

Once I set the servo pins to servo mode, there is no cross talk and the current draw with both motors at no-load max-speed is less than 100 mA.

"pre-flight checklist" is a must.

Weird.

Alan
alanmcdonley
 
Posts: 90
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

Re: Current Sensing Accuracy

Postby alanmcdonley » Sat Sep 05, 2015 7:05 am

mikronauts wrote:Worst case accuracy is +/- 0.5 LSB for the ADC, and +/- 7.68 bits for the ACS712, so ranges from -8.18 bits ... +8.18 bits


That is +/- 216 mA worst case - nearly half an amp. Makes me start to question bothering with a current sensor at all.

For 1000 "ten reading medians" for zero current readings:
median: 514.4
average: 514.5
minimum: 512
maximum: 517
std_dev: 0.8

Range of +/- 66mA for any "10 reading median" at zero current, and around +/- 30ma for 1000 "10 reading median" readings.

I was never good at statistics, but it seems like I should take a few thousand readings anytime I want my robot to "think" about its current draw. (Actually, I got a B in stat without understanding the theory. "I R an enganeer" that knows to apply formulas blindly. If you want to understand something, ask a scientist - or take a walk in nature and realize it doesn't matter anyway.)

Alan
alanmcdonley
 
Posts: 90
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

Re: Current Sensor - ACS712

Postby mikronauts » Sat Sep 05, 2015 8:29 am

Close, but not quite.

When Vcc = 5V, the current sensor is calibrated to 0.185V per A, and has an official range of -5A .. 5A for an ACS712

So the "official" range is equivalent to 1.575V (-5A) ... 3.425V (+5A), with 2.5V being 0A

Converting that to the binary output of an MCP3008, we get

322 = -5A
512 = 0A
701 = +5A

That is, a 5A range represents a range of 189 values

5000mA / 189 = 26.455mA per "count" from the ADC

So you can tell the current reading to within ~26mA

As the ACS712 only has +/- 1.5% accuracy over a 10A range that is better precision than the sensor can provide.

If you average & filter the readings a lot, you can get readings that appear to give better resolution.

If you replace the MCP3008 with an MCP3208, you could get readings to within about 6.5mA, however as the sensor is not capable of providing readings that accurate, the greater apparent accuracy would not help.

Having said that, it should be possible to calibrate each individual sensor separately, and apply calibration factors to get better accuracy.

Frankly, for most robotics applications, the 26mA "grain" should be fine.

alanmcdonley wrote:Thanks, now I understand:
Code: Select all
5000 mV               1Amp             1000mA
--ADC----     x  ----Sensor------  x  -----------  =   26.39358 mA per "reading bit"
1024 "bits"           185mV            1 Amp


zero_reading = 512 # (unless median zero reading is actually 511 or 513)
current_in_mA = (reading - zero_reading) * 26.39358
mikronauts
 
Posts: 119
Joined: Tue Sep 16, 2014 6:58 pm

Re: PWM to Servo Pins Crosstalk

Postby mikronauts » Sat Sep 05, 2015 8:33 am

Crosstalk is a fact of life for unconfigured pins.

set the pin mode to output, and set the pins to a known state (suggest 0)

or

as you observed, configure for servo mode, and drive them properly

I usually configure all pins, even if I don't use them, to avoid such issues.

alanmcdonley wrote:I get serious cross talk from PWM pins to undesignated GPIO/"PiDA Servo" pins, and major current draw, when I have not set the servo pins to servo mode before ramping up the DC motors.

When I ramp up PWM for both motors (servo pins 6, 7), my tilt/pan servos (which do not have a mode set yet) ramp in position and the total current draw is around 1A.

Once I set the servo pins to servo mode, there is no cross talk and the current draw with both motors at no-load max-speed is less than 100 mA.

"pre-flight checklist" is a must.

Weird.

Alan
mikronauts
 
Posts: 119
Joined: Tue Sep 16, 2014 6:58 pm

Re: Current Sensing Accuracy

Postby mikronauts » Sat Sep 05, 2015 8:35 am

I mis-wrote, that is 7.68 counts, not bits for the ADC.

I posted a more thorough explanation of the expected output from the ACS712 two posts above, and I will write a proper article on it :)

alanmcdonley wrote:
mikronauts wrote:Worst case accuracy is +/- 0.5 LSB for the ADC, and +/- 7.68 bits for the ACS712, so ranges from -8.18 bits ... +8.18 bits


That is +/- 216 mA worst case - nearly half an amp. Makes me start to question bothering with a current sensor at all.

For 1000 "ten reading medians" for zero current readings:
median: 514.4
average: 514.5
minimum: 512
maximum: 517
std_dev: 0.8

Range of +/- 66mA for any "10 reading median" at zero current, and around +/- 30ma for 1000 "10 reading median" readings.

I was never good at statistics, but it seems like I should take a few thousand readings anytime I want my robot to "think" about its current draw. (Actually, I got a B in stat without understanding the theory. "I R an enganeer" that knows to apply formulas blindly. If you want to understand something, ask a scientist - or take a walk in nature and realize it doesn't matter anyway.)

Alan
mikronauts
 
Posts: 119
Joined: Tue Sep 16, 2014 6:58 pm

Wheel Encoder Adventure Continues

Postby alanmcdonley » Tue Sep 08, 2015 6:55 pm

I started to test the wiring for the wheel encoders. The emitter leds work but it seems the detectors do not. Perhaps I killed them by reverse power during the wiring tests - headers and ribbon connectors are easy to get mixed up which side is which.

Luckily, I found a source for the tiny, tiny Hamamatsu P5587 emitter-detector chip - therobotstorehk has them. The chip has been out of production for ten years supposedly.

I really didn't want to have to redesign a new encoder mounting, so this is good. (I just have to be successful at desoldering and soldering the tiny pins without lifting a pad and without over heating the chips.)

The adventure continues.

Alan
alanmcdonley
 
Posts: 90
Joined: Thu Jul 23, 2015 10:50 am
Location: Boynton Beach, Florida

Re: Wheel Encoder Adventure Continues

Postby mikronauts » Fri Sep 18, 2015 4:34 pm

Any luck with the encoders?

I just got back from a nice holiday :)

alanmcdonley wrote:I started to test the wiring for the wheel encoders. The emitter leds work but it seems the detectors do not. Perhaps I killed them by reverse power during the wiring tests - headers and ribbon connectors are easy to get mixed up which side is which.

Luckily, I found a source for the tiny, tiny Hamamatsu P5587 emitter-detector chip - therobotstorehk has them. The chip has been out of production for ten years supposedly.

I really didn't want to have to redesign a new encoder mounting, so this is good. (I just have to be successful at desoldering and soldering the tiny pins without lifting a pad and without over heating the chips.)

The adventure continues.

Alan
mikronauts
 
Posts: 119
Joined: Tue Sep 16, 2014 6:58 pm

PreviousNext

Return to Pi Droid Alpha

Who is online

Users browsing this forum: No registered users and 1 guest

cron