Not sure if this is the correct board to ask about this but...
I have a ENC 03MB single axis gyro, which uses an output voltage and a reference voltage to output the angular velocity in voltage.
As per the datasheet, this is the formula they use:
Output voltage = V0 + Sv*w
Where the output voltage is the voltage out to the OUT pin, V0 is the voltage out to the OUT pin when not moving, and Sv is the scaling factor, according to the datasheet this is 0.67mV.
So naturally I read the voltage out and the reference, stored it as adcIn and ref respectively, and designed the following equation:
rate=(adcIn-ref)/(0.67/1000.0);
adcIn and ref have been properly divided by 1023 to give the voltage output in Volts, and since 0.67 is in mV i had to divide by 1000 there. I'm using this along with time to get a value for the heading.
For some reason, it doesn't work at all. The value sometimes never increases, or increases randomly, or jumps randomly, or just does not respond to any motion.
Here's my code:
double adcIn, ref, rate, initTime, rot=0;
void setup() {}
void loop() {
initTime = millis();
adcIn = analogRead(0)/1023.0;
ref = analogRead(1)/1023.0;
if(((1000*adcIn)-(1000.0*ref))>10) //deadzone of +/- 10mV
rate=(adcIn-ref)/(0.67/1000.0); //change the rate correctly
else
rate = 0;
rot+=rate*(millis()-initTime)/1000.0; //apply the rate to the heading
Serial.print(rot);
Serial.println(" deg");
Serial.print(rate);
Serial.println(" deg/s");
Serial.print(adcIn*1000);
Serial.println(" mV ADC");
Serial.print(ref*1000);
Serial.println(" mV Reference");
Serial.println();
Serial.println();
}
Any idea as to where I'm going wrong? or am I completely reading this datasheet wrong? There's a datasheet here.



