Yes, so I stopped pedalling as as the wheel slowed down it got to approx 12mph then showed error 22.did you get error 22 in pedaling mode?
Yes, so I stopped pedalling as as the wheel slowed down it got to approx 12mph then showed error 22.did you get error 22 in pedaling mode?
So far I have been switching the LCD off and on to reset, but let me try and wait for a few seconds and retry throttle / pedal see what happens.is switching the LCD off and on again the only way to clear error 22 without touching the pedals?
what if you wait a few seconds then use the throttle or pedal again after error 22 shows up? would that clear error 22?
// Test cadence and torque replication
const byte ThrottlePin = A0;
const byte CadenceInputPin = A2;
const byte TorqueInputPin = A3;
const byte TorqueOutputPin = A5;
const byte CadenceOutputPin = 13;
const byte TorqueAtRest = 198;
int pulseoff = 25; // milliseconds when D13 is low
int pulseon = 25; // milliseconds when D13 is high 4Hz
int cadencepulselength = 991; // in milliseconds
bool cadencestate = false;
bool pulse = false;
unsigned long startMillis;
unsigned long currentMillis;
void setup() {
pinMode(CadenceOutputPin, OUTPUT);
pinMode(TorqueInputPin, INPUT);
pinMode(TorqueOutputPin, OUTPUT); //ControllerTorquePin
pinMode(CadenceInputPin, INPUT); //PASCadencePin
digitalWrite(TorqueOutputPin, LOW);
startMillis = millis();
// Serial.begin(9600);
}
void loop() {
if (millis()>currentMillis) // run once every millisecond
{
currentMillis = millis();
// I'm pedalling
analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4);
if (analogRead(CadenceInputPin) > 512) digitalWrite(CadenceOutputPin, HIGH);
else digitalWrite(CadenceOutputPin, LOW);
}
}
I'll try and test this later today and relay the results.can you try this code which simply replicates torque and cadence:
Code:// Test cadence and torque replication const byte ThrottlePin = A0; const byte CadenceInputPin = A2; const byte TorqueInputPin = A3; const byte TorqueOutputPin = A5; const byte CadenceOutputPin = 13; const byte TorqueAtRest = 198; int pulseoff = 25; // milliseconds when D13 is low int pulseon = 25; // milliseconds when D13 is high 4Hz int cadencepulselength = 991; // in milliseconds bool cadencestate = false; bool pulse = false; unsigned long startMillis; unsigned long currentMillis; void setup() { pinMode(CadenceOutputPin, OUTPUT); pinMode(TorqueInputPin, INPUT); pinMode(TorqueOutputPin, OUTPUT); //ControllerTorquePin pinMode(CadenceInputPin, INPUT); //PASCadencePin digitalWrite(TorqueOutputPin, LOW); startMillis = millis(); // Serial.begin(9600); } void loop() { if (millis()>currentMillis) // run once every millisecond { currentMillis = millis(); // I'm pedalling analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4); if (analogRead(CadenceInputPin) > 512) digitalWrite(CadenceOutputPin, HIGH); else digitalWrite(CadenceOutputPin, LOW); } }
I’ve tested this now. Results as follows:can you try this code which simply replicates torque and cadence:
Code:// Test cadence and torque replication const byte ThrottlePin = A0; const byte CadenceInputPin = A2; const byte TorqueInputPin = A3; const byte TorqueOutputPin = A5; const byte CadenceOutputPin = 13; const byte TorqueAtRest = 198; int pulseoff = 25; // milliseconds when D13 is low int pulseon = 25; // milliseconds when D13 is high 4Hz int cadencepulselength = 991; // in milliseconds bool cadencestate = false; bool pulse = false; unsigned long startMillis; unsigned long currentMillis; void setup() { pinMode(CadenceOutputPin, OUTPUT); pinMode(TorqueInputPin, INPUT); pinMode(TorqueOutputPin, OUTPUT); //ControllerTorquePin pinMode(CadenceInputPin, INPUT); //PASCadencePin digitalWrite(TorqueOutputPin, LOW); startMillis = millis(); // Serial.begin(9600); } void loop() { if (millis()>currentMillis) // run once every millisecond { currentMillis = millis(); // I'm pedalling analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4); if (analogRead(CadenceInputPin) > 512) digitalWrite(CadenceOutputPin, HIGH); else digitalWrite(CadenceOutputPin, LOW); } }
I think your right seems like the replication routine needs tweaking.that seems to indicate that the error is caused by the replication routine and not while the bike is on the throttle.
What do you think?
if you can, change this line:
analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4);
to:
analogWrite(TorqueOutputPin, 20 + analogRead(TorqueInputPin)/4);
to boost the A5 voltage a bit to see if it has any effect on the outcome.
Finally got round to testing this.that seems to indicate that the error is caused by the replication routine and not while the bike is on the throttle.
What do you think?
if you can, change this line:
analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4);
to:
analogWrite(TorqueOutputPin, 20 + analogRead(TorqueInputPin)/4);
to boost the A5 voltage a bit to see if it has any effect on the outcome.
OK I think you're right. I connected A5 to A3 and after approx 3 seconds I received error 22.to test the cadenceInput, connect the A5 wire directly to pin A3 (torqueInput).
Leave the code like it is.
If the code yields error 22 in the same way, we'll know that the replication of the cadence is not good enough.
OK so as soon as I powered on the bike, the motor kicked in without me doing anything then after 2secs returned error 22.Now let's test the translation of the TorqueInput, re-install the A5 wire and connect this time the D13 wire to A2 pin.
Ok I’ve done this and I had the same results.I am surprised by the result.
A2 (cadence input) and D13 (cadence ouput) are normally joined before we place them on the arduino.
I would have expected no error on startup.
Can we join A2 (cadence input) and D13 (cadence ouput) but leave the connection unattached to pin A2?
I tested this and the motor started on its own.Can you re-install the D13 wire and leave the A2 wire disconnected (in the air) to see if the motor starts on its own?
// Test cadence and torque replication Version 2
// Avoid D13 because of the internal LED
// but duplicate output to keep blinking LED as indicator
const byte ThrottlePin = A0;
const byte CadenceInputPin = A2;
const byte TorqueInputPin = A3;
const byte TorqueOutputPin = A5;
const byte CadenceOutputPin = A4;
const byte TorqueAtRest = 198;
int pulseoff = 25; // milliseconds when D13 is low
int pulseon = 25; // milliseconds when D13 is high 4Hz
int cadencepulselength = 991; // in milliseconds
bool cadencestate = false;
bool pulse = false;
unsigned long startMillis;
unsigned long currentMillis;
void setup() {
pinMode(CadenceOutputPin, OUTPUT_PULLUP);
pinMode(TorqueInputPin, INPUT_PULLUP);
pinMode(TorqueOutputPin, OUTPUT_PULLUP); //ControllerTorquePin
pinMode(CadenceInputPin, INPUT_PULLUP); //PASCadencePin
startMillis = millis();
// Serial.begin(9600);
}
void loop() {
if (millis()>currentMillis) // run once every millisecond
{
currentMillis = millis();
// I'm pedalling
analogWrite(TorqueOutputPin, analogRead(TorqueInputPin)/4);
if (analogRead(CadenceInputPin) > 512) analogWrite(CadenceOutputPin, 255);
else analogWrite(CadenceOutputPin, 0);
// blink LED indicator
if (analogRead(CadenceInputPin) > 512) digitalWrite(D13, HIGH);
else digitalWrite(D13, LOW);
}
}