Pages: [1]   Go Down
Author Topic: a invalid long problem  (Read 305 times)
0 Members and 1 Guest are viewing this topic.
Enschede, Netherlands
Offline Offline
Full Member
***
Karma: 0
Posts: 226
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to calculate some values depending on some defines.
But i get a error:
ArduKMoto:40: error: 'long' invalid for 'RotationSpeed4'
ArduKMoto:40: error: expected primary-expression before '=' token
ArduKMoto:40: error: expected primary-expression before '=' token

code
Code:
#define SUPPLY_VOLTAGE = 800      // This is the system supply voltage between 12-24V DC in mV
#define MOTOR_VOLTAGE = 600       // Motor normal operating voltage in mV
#define MOTOR_MIN_VOLTAGE = 258   // Minimum desriable motor voltage in mV
// Any change in the above values require a version change
// We now can calculate the voltages used to control speed using PWM
// The used formula equals (PWM_resolution/supply_voltage)*desired_voltage = PWM_value
float long RotationSpeed4 = ((25500/SUPPLY_VOLTAGE)*MOTOR_VOLTAGE)/100;
float long RotationSpeed3 = ((25500/SUPPLY_VOLTAGE)*MOTOR_VOLTAGE)/100;
float long RotationSpeed2 = ((25500/SUPPLY_VOLTAGE)*(MOTOR_VOLTAGE/2))/100;
float long RotationSpeed1 = ((25500/SUPPLY_VOLTAGE)*MOTOR_MIN_VOLTAGE)/100;
Why cant it be a long? and what should it then be?
Logged

New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3699
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is it a float or a long - can't be both.
Logged

Enschede, Netherlands
Offline Offline
Full Member
***
Karma: 0
Posts: 226
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Making it either a float or long gives (almost) the same error:
ArduKMoto:40: error: expected primary-expression before '=' token
ArduKMoto:40: error: expected primary-expression before '=' token
« Last Edit: April 04, 2013, 01:34:21 pm by gharryh » Logged

New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3699
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does your revised code look like?
Logged

Enschede, Netherlands
Offline Offline
Full Member
***
Karma: 0
Posts: 226
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#define SUPPLY_VOLTAGE = 800      // This is the system supply voltage between 12-24V DC in mV
#define MOTOR_VOLTAGE = 600       // Motor normal operating voltage in mV
#define MOTOR_MIN_VOLTAGE = 258   // Minimum desriable motor voltage in mV
// Any change in the above values require a version change
// We now can calculate the voltages used to control speed using PWM
// The used formula equals (PWM_resolution/supply_voltage)*desired_voltage = PWM_value
long RotationSpeed4 = ((25500/SUPPLY_VOLTAGE)*MOTOR_VOLTAGE)/100;
//long RotationSpeed3 = ((25500/SUPPLY_VOLTAGE)*MOTOR_VOLTAGE)/100;
//long RotationSpeed2 = ((25500/SUPPLY_VOLTAGE)*(MOTOR_VOLTAGE/2))/100;
//long RotationSpeed1 = ((25500/SUPPLY_VOLTAGE)*MOTOR_MIN_VOLTAGE)/100;
I commented the last 3 out, they produce the same ero\ro
Logged

New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3699
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is no = in a #define. At least, not in this case.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13734
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

when you use longs you will have truncating errors, check the diffs below

Code:
#define SUPPLY_VOLTAGE  800     
#define MOTOR_VOLTAGE  600

#define SUPPLY_VOLTAGE_F  800.0     
#define MOTOR_VOLTAGE_F  600.0

long l = ((25500/SUPPLY_VOLTAGE)*MOTOR_VOLTAGE)/100;
float f = ((25500/SUPPLY_VOLTAGE_F)*MOTOR_VOLTAGE_F)/100;

// rewritten the math!
long l2 = 25500L * MOTOR_VOLTAGE /SUPPLY_VOLTAGE /100;  // you need to add the L to the values to enforce long math

void setup()
{
  Serial.begin(9600);
  Serial.println(l);
  Serial.println(f,3);  // 3 decimals
  Serial.println(l2);
}
void loop(){}
==> about  2.5%  difference
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: