bear24rw
02-07-2006, 15:45
I am trying to use the battery_voltage variable in user_routines.c but I get this error when trying to compile..
Error [1205] unknown member 'rc_analog01' in '__tag_167'
Am I missing something?
EDIT
After looking at 'ifi_default.h' i found this block of code..
unsigned char oi_analog01, oi_analog02, oi_analog03, oi_analog04; /*rxdata.oi_analog01*/
unsigned char oi_analog05, oi_analog06, oi_analog07, oi_analog08;
unsigned char oi_analog09, oi_analog10, oi_analog11, oi_analog12;
unsigned char oi_analog13, oi_analog14, oi_analog15, oi_analog16;
unsigned char rc_main_batt, rc_backup_batt;
So i decided to try rc_main_batt and rc_backup_batt...
If found that if you took rxdata.rc_main_batt and applied the formula "current voltage = battery_voltage * 0.038 + 0.05; " found at the bottom of 'ifi_aliases.h' you get a value of 650.. im running the the controller off a wall adapter putting out 6 volts to i think this is pretty acurate.
Here is the code if anyone is interested..
float current_voltage = 0;
float average_voltage = 0;
int voltage_count = 0;
int i = 0;
int i2 = 0;
void Process_Data_From_Master_uP(void)
{
Getdata(&rxdata); /* Get fresh data from the master microprocessor. */
current_voltage = rxdata.rc_main_batt; // Store current voltage
average_voltage += current_voltage; // Add the current voltage to the average stack
voltage_count++; // Increase the average stack count
if (voltage_count == 39) // If the stack is 40
{
average_voltage = (average_voltage / 40) * 0.038 + 0.05; // Get the average and apply formula
i = (int)average_voltage; // Truncate decimals
i2 = (int) ((average_voltage - i) * 1000); // Subtract to get decimals only and then multiply by 1000
printf("Average: %d.%03d \n",i,i2); // Print the two together to make it look like a decimal
average_voltage = 0; // Reset the stack
voltage_count = 0; // Rest the counter
}
Putdata(&txdata); /* DO NOT CHANGE! */
}
Thanks to Mark McLeod for example on how to printf floats...
EDIT
I just tried using
current_voltage = rxdata.oi_analog01;
and i get averages of 4.7 so im not sure what to think now.. can anyone clarify as to what one it is and why i get an error when i try to use the 'battery_voltage' aliase... also i just realized that the battery_voltage aliase points to 'rxdata.rc_analog01' which i cant seem to even find anywhere..
Error [1205] unknown member 'rc_analog01' in '__tag_167'
Am I missing something?
EDIT
After looking at 'ifi_default.h' i found this block of code..
unsigned char oi_analog01, oi_analog02, oi_analog03, oi_analog04; /*rxdata.oi_analog01*/
unsigned char oi_analog05, oi_analog06, oi_analog07, oi_analog08;
unsigned char oi_analog09, oi_analog10, oi_analog11, oi_analog12;
unsigned char oi_analog13, oi_analog14, oi_analog15, oi_analog16;
unsigned char rc_main_batt, rc_backup_batt;
So i decided to try rc_main_batt and rc_backup_batt...
If found that if you took rxdata.rc_main_batt and applied the formula "current voltage = battery_voltage * 0.038 + 0.05; " found at the bottom of 'ifi_aliases.h' you get a value of 650.. im running the the controller off a wall adapter putting out 6 volts to i think this is pretty acurate.
Here is the code if anyone is interested..
float current_voltage = 0;
float average_voltage = 0;
int voltage_count = 0;
int i = 0;
int i2 = 0;
void Process_Data_From_Master_uP(void)
{
Getdata(&rxdata); /* Get fresh data from the master microprocessor. */
current_voltage = rxdata.rc_main_batt; // Store current voltage
average_voltage += current_voltage; // Add the current voltage to the average stack
voltage_count++; // Increase the average stack count
if (voltage_count == 39) // If the stack is 40
{
average_voltage = (average_voltage / 40) * 0.038 + 0.05; // Get the average and apply formula
i = (int)average_voltage; // Truncate decimals
i2 = (int) ((average_voltage - i) * 1000); // Subtract to get decimals only and then multiply by 1000
printf("Average: %d.%03d \n",i,i2); // Print the two together to make it look like a decimal
average_voltage = 0; // Reset the stack
voltage_count = 0; // Rest the counter
}
Putdata(&txdata); /* DO NOT CHANGE! */
}
Thanks to Mark McLeod for example on how to printf floats...
EDIT
I just tried using
current_voltage = rxdata.oi_analog01;
and i get averages of 4.7 so im not sure what to think now.. can anyone clarify as to what one it is and why i get an error when i try to use the 'battery_voltage' aliase... also i just realized that the battery_voltage aliase points to 'rxdata.rc_analog01' which i cant seem to even find anywhere..