I have constructed an inertial dynamometer for 540 (36mm diameter) size electric motors and it seems to mostly function but I am getting an unusual "bump" in my rpm around 5000 rpm. I have tried different ways of controlling the servo signal to my motor speed control and there does not seem to be any change. I have tried changing settings in the motor speed control and still no change. I am not sure what else to try. Maybe I am incorrectly using the FreqMeasure library.
I have two Arduino Unos. One gathers the sensor readings and the other outputs a servo signal. The RPM is measured by an optical encoder wheel with 4 slots. The loop on the sensor Uno achieves about 50 sps.
The code for the sensor reading.
#include <FreqMeasure.h>
#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include "HX711.h"
HX711 scale;
Adafruit_ADS1115 ads(0x4A); /* Use this for the 16-bit version */
int16_t currentSensor, voltageSensor;
int throttleOutput = 2, statusPin = 13;
long force;
double sum=0;
int count=0;
unsigned long time1 = 0, time2 = 0;
void setup() {
pinMode(throttleOutput, OUTPUT); // HIGH OUTPUT TURNS THE MOTOR OFF.
pinMode(statusPin, OUTPUT);
digitalWrite(throttleOutput, HIGH); // Set throttle and status LED to off
digitalWrite(statusPin, LOW);
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.println("hello");
Serial.print("microseconds, amps, volts, torque, rpm");
ads.begin(); // start Volt+Current sensor
ads.setGain(GAIN_SIXTEEN);
// HX711.DOUT -pin 11//to set the DOUT(or DT) pin
// HX711.PD_SCK -pin 12//to set the SCKpin
scale.begin(11, 12);
delay(2000);
FreqMeasure.begin(); // Start frequency measure function (can only measure dpin 8)
digitalWrite(throttleOutput, LOW); // apply full throttle and turn on status LED
digitalWrite(statusPin, HIGH);
}
void loop() {
time1 = micros();
if (time1 > (time2 + 19000))
{
time2 = micros();
force = (scale.read());
currentSensor = ads.readADC_Differential_2_3();
voltageSensor = ads.readADC_SingleEnded(0) ;
float frequency = FreqMeasure.countToFrequency(sum / count)*15; // The 15 is to convert a 4 slot encoder wheel frequency into an RPM reading {rpm=freq*(60 rpm/hz)/(4 slot/rotation)}
sum = 0;
count = 0;
Serial.println();
Serial.print(time2); Serial.print(",");
Serial.print(currentSensor); Serial.print(",");
Serial.print(voltageSensor); Serial.print(",");
Serial.print(force); Serial.print(",");
Serial.print(frequency);
}
if (FreqMeasure.available())
{
// average several reading together
sum = sum + FreqMeasure.read();
count = count + 1;
}
if (millis() > 5100) // Check if 5.1s have passed and then shutdown
{
scale.power_down(); // Shutdown loadcell to avoid heat build
while(1)
{
digitalWrite(throttleOutput, HIGH); // Set throttle and status LED to off
digitalWrite(statusPin, LOW);
}
}
}
The code for the servo signal
#include <Servo.h>
Servo testESC; // create servo object to control a servo
// twelve servo objects can be created on most boards
int neutral = 91 , fullThrottle = 145; // variable to store the servo position
int triggerPin = 2, outputPin=12, statusPin = 13;
int triggerState;
void setup()
{
pinMode(triggerPin, INPUT_PULLUP);
pinMode(statusPin, OUTPUT);
digitalWrite(statusPin, LOW);
testESC.attach(outputPin); // attaches the servo on pin 3 to the servo object
testESC.write(neutral);
delay(500);
}
void loop()
{
if (!digitalRead(triggerPin))
{
testESC.write(fullThrottle);
digitalWrite(statusPin, HIGH);
}
else
{
testESC.write(neutral);
digitalWrite(statusPin, LOW);
}
}
The graph shows RPM over time (seconds) and appears as if the RPM levels and then "surges" at 5000 rpm.
I also have current and torque measurements and there does not appear to be a surge in current or torque at 5000 rpm but it may just be a lack of resolution.