Thread: Current Sensor
View Single Post
  #3   Spotlight this post!  
Unread 12-02-2004, 10:48
WillyC's Avatar
WillyC WillyC is offline
"handy"
#1347
Team Role: Engineer
 
Join Date: Jan 2004
Location: Ottawa, Canada
Posts: 29
WillyC is on a distinguished road
Re: Current Sensor

Quote:
Originally Posted by HHSJosh
I have written some code for the current sensor, but it doesn't do anything but display the sensor's data. You can put this in the final lines of user_routines_fast.c where your own code for every loop can be placed:

Code:
/* The formula comes from the equation of the line from the data by Willy C */
/* For this to work, the current sensors must be connected to Analog Inputs 1 and 2 */

#define Amps1     (rc_ana_in01 * 30) - 75
#define Amps2     (rc_ana_in02 * 30) - 75

printf("1st Sensor: %d\n", Amps1);
printf("2nd Sensor: %d\n", Amps2);

Be careful here guys. I made a mistake in my earlier post when I quoted the Volts vs. Amps characteristics of the current sensors, which Dale was nice enough to correct. Here are the correct values:

Quote:
Originally Posted by Dale(294engr
]

ACS NOTE RANGE:
1Vout = -75A
2.5Vout = 0A
4Vout = 75A
The characteristic is (almost perfectly) linear between -75 amps and 75 amps. Using this adjusted data you'd find that

I = 50 * V - 125

where I is the current and V is the voltage you measure on the analog input.

Also, in the code above, I think you want to use a Get_Analog_Value(rc_ana_01) in order to convert to an analog voltage. You also want to cast to an integer before printf'ing.

user_routines.h:

Code:
/* Current sensor data */
#define CURR_SLOPE 0.02			// Slope  used in the current calculation
#define CURR_INTERCEPT 2.5		// Y intercept used for the current calculation
#define LEFT_CURR_SENS rc_ana_in01	// analog input 1; used to measure current on left motor
#define RIGHT_CURR_SENS rc_ana_in02 	// analog input 2; used to measure current on right motor
user_routines.c/Default_Routine():

Code:
/* Calculate and display the current going to the two drive motors using analog readings */
 
printf("Left motor current = %d\n", (int) (Get_Analog_Value(LEFT_CURR_SENS) - CURR_INTERCEPT) / CURR_SLOPE);
printf("Right motor current = %d\n", (int) (Get_Analog_Value(RIGHT_CURR_SENS) - CURR_INTERCEPT) / CURR_SLOPE);