I have a circuit to supply voltage to my ebike throttle signal cable. this cable must carry voltage in a range of 1.1 to 4.2 volts. There is PWM filter made out of a resistor and a capacitor to filter PWM to DC.
nano sends preset voltages to throttle cable. when i connect nano to 5 volt bus wire of ebike, it runs when 36v main battery when it is full. When it depletes overtime, nano stops working correctly.
Probably, voltage calibrations for inputs and outputs shift. Then motor start to cut intermittently, goes slow etc. ( becasue of original software of chinese controller unit) original system works without any intermittent cuts, it only loose performance when battery depletes.
When i power it with a seperate 5v power bank with a lithium battery, it works but different than on my PC as well. I am lost. It is impossble to calibrate it correctly. What to do?
there is a LED control panel of ebike controller. it has a button to select target speed of motor. 2 volts 3 volts and 4 volts are being sent. these voltages are normally to control speed limits but i use them to adjust arduino pwm output. 2 volts sends 0, 3 votls send 90, 4 volts send 120 ( 8 bits). these voltages is being sent to throttle signal cable because throttle has priority on everything. which means even there is a target speed to reach, if you use throttle it only obeys they throttle commands. ( these are all conditioned to the pedal hall sensor of course. no pedal movement, no power, never)
when powered by PC, my voltages work correctly, when power is being supplied by ebike battery and when it is fully charged, it also works ok, when battery still has almost half of its capacity, arduinol start to act weird.
may be i need to use a regulator or somethign and feed the arduino from battery directly not from controller bus wire.
here is my code if needed. it works on circuits.io or on actual setup. there is voltage on oeach setting on outpot pin of arduino.
int val = 0;
int panel = A0; //panel voltage input pin 2 3 4 volts preset.
int thr = 5; //voltage output
int THR1 = 0; // output preset voltage. approx 1.7 volts 8 bit. RC filter for PWM to DC.
int THR2 = 90; // 2.7 volts
int THR3 = 120; // 4.3 volts
int PNLLO = 420; // constant signal from control panel 2 volt. 10 bit
int PNLMD = 640; // 3 volt. 10 bit
int PNLHI = 810; // 4 volt. 10 bit
int ledPin = 13; //integrated led
int hallsensor = 2; // hall sensor pin.
int firsttime = 1;
unsigned long startTime;
unsigned long hallTime;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(hallsensor, INPUT);
pinMode(hallsensor, INPUT_PULLUP);
digitalWrite(hallsensor, HIGH);
Serial.begin(9600);
}
void loop()
{
val = analogRead(panel);
if ((digitalRead(hallsensor) == LOW) ) { //if panel gives 2 volts.
if ((firsttime == 1) && (val <= PNLLO)) {
startTime = millis();
firsttime = 0;
analogWrite(thr, THR1); // arduino has 1.7 volts output
val = digitalRead(panel);
Serial.println(val);
delay (300);
} else {
if ((firsttime == 1) && (val > PNLLO) && (val < PNLHI)) { //adjustment required
startTime = millis();
firsttime = 0;
analogWrite(thr, THR2); //
val = digitalRead(panel);
delay (300);
} else {
if ((firsttime == 1) && (val >= PNLHI)) { //adjustment required
startTime = millis();
firsttime = 0;
analogWrite(thr, THR3); //
val = digitalRead(panel);
delay (300);
} else
hallTime = millis() - startTime;
if (hallTime >= 1) {
Serial.print("Time: ");
Serial.print(hallTime);
Serial.print(" milliseconds ");
Serial.print(int(hallTime / 1000));
Serial.println(" seconds");
}
if (hallTime > 500) { // if hall sensor matches to the magnet for more than 0.5 sec
digitalWrite(ledPin, HIGH);
analogWrite(thr, 0); // cut power
}
}
}
} else if (firsttime == 0) { // if no pulse on hall sensor
firsttime = 1;
Serial.println("Time: 0 milleseconds; 0 seconds");
digitalWrite(ledPin, LOW);
delay (500);
analogWrite(thr, 0); // more than delay, cut power.
Serial.println("idle");
}
}