810 and ku65 controller - PAS pedelec question

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
latest update. i managed it. there was a problem with code.
i will try this. it seems this will work.

previous one did not care the panel voltages and accepts the first preset panel input voltage. ( which is actually make me able to add a potentionmeter and have varible pedelec settings- but i want presets)

rest of functions works. when halls ensor pulsing it gives voltage to thrtottle as i want, and when no pulse it cuts power. also if it matches the magnet on pedal sensor it also cuts power after a specified time. so now it acts like current control system.

here is latest code which i will try next.
Code:
int val = 0;
int panel = 11; //panel voltage input pin 2 3 4 volts preset.
int thr = 6; //voltage output
int THR1 = 150;  // output preset voltage. approx 1.7 volts 8 bit. RC filter for PWM to DC.
int THR2 = 190; // 2.7 volts
int THR3 = 230; // 4.3 volts
int PNLLO = 400; // constant signal from control panel 2 volt. 10 bit
int PNLMD = 630; // 3 volt. 10 bit
int PNLHI = 800; // 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()
{

  if ((digitalRead(hallsensor) == LOW) ) {  //if panel gives 2 volts.
  if ((firsttime == 1) && (panel > PNLLO)) {
  startTime = millis();
  firsttime = 0;
  analogWrite(thr, THR1); // arduino has 1.7 volts output
  val = digitalRead(panel);
  Serial.println(val);
  delay (400);
  } else {
  if ((firsttime == 1) && (panel > PNLLO)) { //adjustment required
  startTime = millis();
  firsttime = 0;
  analogWrite(thr, THR2); //
  val = digitalRead(panel);
  delay (400);

  } else {
  if ((firsttime == 1) && (panel < PNLLO)) { //adjustment required
  startTime = millis();
  firsttime = 0;
  analogWrite(thr, THR3); //
  val = digitalRead(panel);
  delay (400);

  } 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 dan 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");
  }
}

i need to learn something. since battery pack is depleting over time, if i supply voltage from 36 volts pack, won't this effect arduino? if i use DC to DC converter from aliepxress will this work when it is depleting? it says converter input is 40 volt max. battery goes over 41.2 volts when fully charged.
 
  • Like
Reactions: Woosh
D

Deleted member 4366

Guest
I would have thoughg that there's enough power on the 5v rail to power the Arduino. I've powered similar microprocessors like that.
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
i will try to connect arduino with a mini usb cable cut from an old charger. at least no soldering is required on arduino pins. i will connect to 5 volt where ever i found on my setup. ground goes to controller ground.

last night i went to bed at 2 o'clock. i need to finish this fast.
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
still problematic. it is single panel voltage nıw. it works but no assist choices. it has panel input voltage on arduino but i can add conditions correctly. any arduino gurus here? please help. i am lost completely.
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
i managed to power arduino nano over controller output succesfully.

now here is the problem for my bike which is not coaster brake. original controller do not react to reverse rotation of pedals. but my code does. how?
 
Last edited:

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
Code:
int val = 0;
int panel = A5; //panel voltage input pin 2 3 4 volts preset.
int thr = 6; //voltage output
int THR1 = 90;  // output preset voltage. approx 1.7 volts 8 bit. RC filter for PWM to DC.
int THR2 = 150; // 2.7 volts
int THR3 = 220; // 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 (400);
  } else {
  if ((firsttime == 1) && (val > PNLLO) && (val < PNLHI)) { //adjustment required
  startTime = millis();
  firsttime = 0;
  analogWrite(thr, THR2); //
  val = digitalRead(panel);
  delay (400);

  } else {
  if ((firsttime == 1) && (val >= PNLHI)) { //adjustment required
  startTime = millis();
  firsttime = 0;
  analogWrite(thr, THR3); //
  val = digitalRead(panel);
  delay (400);

  } 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");
  }
}

this is the correct version i guess. if not i will edit this post.
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
ok this code works correctly. according to panel setting, motor gets lo mid hi power.

now, reverse pedal rotation problem.
if i built a custom magent disc for hal sensor, if i use 1 magnet 2 magnets 3 magnets and may be 4 magnets in a line, if it reads first 1, then 2 then 3 then 4 magnets it means forward rotation, if it reads 4 3 2 1 or 3 2 1 4 or 2 1 4 3 or 1 4 3 2, that means reverse, and of course if i can program this on arduino, will it work?
 

Woosh

Trade Member
May 19, 2012
19,477
16,424
Southend on Sea
wooshbikes.co.uk
I think you should code to detect the leading edge of the transition.
The pulse width of the signal is much shorter than the non-active pulse. The edge (high going or low going) determines the direction of the rotation.
 
  • Like
Reactions: dgncsk
D

Deleted member 4366

Guest
It would be easier to get PAS that only gives a signal in the forward direction.
 
  • Like
Reactions: dgncsk

Woosh

Trade Member
May 19, 2012
19,477
16,424
Southend on Sea
wooshbikes.co.uk
It would be easier to get PAS that only gives a signal in the forward direction.
sure but coding broadens the mind and only costs time.
I compare coding with cooking. There is a lot of similarity when you can cook your meal better than shop bought.
 
  • Like
Reactions: dgncsk

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
if only i cook well :) }
write a better code to detect hall sensor transition for low to high;
delay (400);

@Woosh how can i detect the specific part of signal then? any ideas?

@d8veh regarding to buying another pas sensor, do you have any aliexpress link for that?
 

Woosh

Trade Member
May 19, 2012
19,477
16,424
Southend on Sea
wooshbikes.co.uk
@Woosh how can i detect the specific part of signal then? any ideas?
Let's assume you sample the output of the pedal assist sensor (PAS) at 1kHz.
There are only two possibilities: either the customer pedals forward or backward. Let's assume that when he pedals forward, the PAS outputs a high going pulse (from 0V to 4.5V).
Let's assume that you have a 6 magnet disc and the cyclist's cadence is 1Hz (60 RPM). Each detection and sampling cycle will be approximately 166ms.

You reset both timer1 and 2 when you see a PAS signal transition from low to high, and continue with sampling. Each 1ms interval, if the signal remains high, you increment Timer1. If you see the signal goes low, lock Timer1 and increment Timer2. Continue sampling until you see the signal go high again. The ratio between Timer1/Timer2 gives you the direction of the pedaling. It should be about 0.2 for a forward pedaling, 5 for a reverse pedaling.
Increment your pulse counter then continue with looping.
Your pulse counter will be used to control the PWM output to your throttle.
 
  • Informative
Reactions: dgncsk

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
it seems writing such code is few months away from me now. i hardly managed to write a code which works for my modification. i bought a book for arduino. it has a section of sampling and timers. i need to study it well i guess.

i want to do several othe rarduino projects so i think i will return back to this project later.

also i am searching for dual hall sensors for ebikes. i found one with led on it. waiting for answers from aliexpress seller.

https://www.aliexpress.com/item/JS-Electric-Bicycle-Pedal-Assistant-Sensor-E-bike-PAS-System-With-12Magnet-Conversion-Kit-Cable-Length/32798528190.html

regarding to this project, i plan to read signal from motor hall sensors to keep track of speed and distance too. may be an lcd would be nice. then, i can eliminate the reverse PAS problem since i will be programming it to work only when forward movement is there(> low speeds 2km(h) may be.)
 
Last edited:

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
there is something wrong. when i supply voltage to arduino from tablet pc it works and sends correct voltages. if i power it over 5 volt from 5v wire on panel, voltages drop and calibration goes wrong. why is internal 5 volt is so? i think i need a dc dc converter to convert 36 to 5v.
 
D

Deleted member 4366

Guest
i think i need a dc dc converter to convert 36 to 5v.
No, you need a 5v regulator. You can copy the way the controller does it, but because the controller already does it, you can tap into its 5v supply to save the bother. The schematic is in the top right of the one on this page of the KU63 controller, where it's done in two stages using a 12v regulator to drop it down first. I'm sure I've seen it done in a single stage in the LCD panels, but I believe that the maximum drop-down of the 78L05 is 30v, so 35v battery voltage max.

http://www.avdweb.nl/solar-bike/electronics/ku63-motor-controller.html#h2-ku63-motor-controller-facts
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
ok.here is problem. after 30 seconds of continuous pedal movement controller start to skip and cutspower intermittently. it does not go off but act weird. can this be the result of my poor pwm filter? arduino is powered externally. i bought very cheap DAC from aliexpress. should i try that?
 

Woosh

Trade Member
May 19, 2012
19,477
16,424
Southend on Sea
wooshbikes.co.uk
can this be the result of my poor pwm filter? arduino is powered externally. i bought very cheap DAC from aliexpress. should i try that?
it's very possible.
I suggest you use a 4-bit DAC. You can make a crude one using resistors. For the kind of applications like throttle emulator, a DAC is inifinitely better than any PWM because of its inherent stability and easy programming.
also calculate a 2 second moving average of the rotational speed and use it to set the output voltage for the throttle.
 
D

Deleted member 4366

Guest
ok.here is problem. after 30 seconds of continuous pedal movement controller start to skip and cutspower intermittently. it does not go off but act weird. can this be the result of my poor pwm filter? arduino is powered externally. i bought very cheap DAC from aliexpress. should i try that?
That's what I got when I ran unfiltered PWM.
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
When battery depletes on my tablet pc, codes starts to go crazy. I think all calibration values including delays shift to. I think its better to buy a proper lcd and controller. Because i cant fix variables and cant change only one at a time and i really got bored. To make this work i need to shift values according to the voltage input changes over time which is quite complex. Lessons learned and i got beginner level arduino codin experience. I will program it to a single assist level for low speed cruising. Which is to conserve battery. When needed i will use throttle.
 
Last edited:

Advertisers