810 and ku65 controller - PAS pedelec question

D

Deleted member 4366

Guest
The controller can't receive an unfiltered pwm throttle signal. it'll just go nuts.
 
  • Like
Reactions: dgncsk

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
if you make a low pass filter to convert a PWM to a voltage, the output depends on the R and C values of your filter. It will take a lot of guesswork to find the appropriate values for R and C. You can use one of the analog inputs to measure the throttle voltage (by connecting your PWM output to it) and adjust your PWM accordingly.

edit



d8veh is correct, connect the output of your low pass filter to an analog input, not the PWM pin.
I suggest you test with 5 kOhm variable resistor and 0.1microF capacitor.

i will try this. i have also arduino mega. so to keep things simple i can use that to see voltages seperately.
 

Woosh

Trade Member
May 19, 2012
19,525
16,464
Southend on Sea
wooshbikes.co.uk
if you are going to do a project using the arduino with the 810 LED panel, I'd be interested in reading more about it. I had in my bucket some similar idea of connecting one of the analog inputs to one of the FETs to act as current sensor to log battery usage.
 

Woosh

Trade Member
May 19, 2012
19,525
16,464
Southend on Sea
wooshbikes.co.uk

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
regarding to the arduino PWM (problem in my case). If 100% duty cycle is 5volts on a pwm pin.

If i use 3 different pwm outputs with different serial resistors on each pin to get desired output voltages, will that one work?( dig pin no11 1.9 volts, no10 3.4 volts, no6 4.5 volts etc..) how big is the load on signal wires? i tried on this without a load on it, it requires mega ohms to find lets say 1.1 volts from 5 volt PWM. is that normal?

so when panel sends 2 volts to arduino, arduino will need to send 1.9 volts to throttle signal cable. you remember this from previous attempts.
 
D

Deleted member 4366

Guest
There's no load on the signal wire, so a seial resistor won't work. Like I said, use a low pass filter. That's what I did when I was messing about with Picaxe chips, and it worked perfectly. If you send the PWM direct to the controller, it works for a bit, but then the controller gets a mind of its own. You'll see that Speedict offer a special throttle adaptor cable for their device for when you want it to control the throttle. AFAIK, that's just a normal cable with a low-pass filter in it.
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
yes i modelled it in circuits.io, and realized that if no load, no voltage changes. i desperately need a low pass filter formula then... i am tired of searching. but i learned basics of arduino. which is good a thing.
 
D

Deleted member 4366

Guest
i desperately need a low pass filter formula then...
It's all in that link that I gave you above. You only have to read it!

My microprocessors PWMed at 10K so I used R =1K and C = 1 microfarad That gives an output voltage of 1v at 20% duty cycle and 4v at 80%, so you can control the throttle within that range by changing the duty cycle to anything between 20% and 80%.

You should test it to see the exact duty cycle that will start the wheel to move and what value gives maximum speed - probably something like 23% and 77%. Then add a few % each end for safety.

If your Arduino PWMs at a different frequency to 10K, there's an on-line calculator near the bottom of that article in the link above.
 
Last edited by a moderator:
  • Like
Reactions: dgncsk

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
i did another sketch. i found this code over youtube and modified it according to my needs. i kept the RGB led to show the state of pedal assist. i added magnet count variable for pedelec sensor. mine is 8. which means for 1 full revolutions there would be 8 pulses on hal sensor. it is in calculation for rpm. this rpm value can be used to display the current cadance for fitness purposes too. also, with utilization of gyro sensor, if i can mange it to integrate, i can adjust pedal assist setting according to slope. since on my preset voltages are approx,2 3 4 volts , by using additional conditions i can increase the assisst level automatically too.



Code:
int panel = A0; //810 panel voltage input pin
int thr = 5; //throttle signal addition wire with a diode on throttle
int THR1 = 90;  // preset output preset voltage. 1.9 volts 8 bit
int THR2 = 130; // 2.5 volts
int THR3 = 185; // 4.8 volts
int PNLLO = 430; // constant signal from control panel 2 volt. 10 bit
int PNLMD = 580; // 3 volt. 10 bit
int PNLHI = 729; // 4 volt. 10 bit
int magnet = 8; //PEDELEC SENSOR Magnet Count to show correct rpm on serial monitor
int val = 0;



//Varibles used for calculations
int ticks = 0, Speed = 0;

int hallsensor = 12;  //The Hall effect sensor pin

//Defines the structure for multiple fans and their dividers
typedef struct{  

char fantype;
unsigned int fandiv;

}  fanspec;


//set 1 for unipole hall effect sensor
//and 2 for bipole hall effect sensor
fanspec fanspace[3]={{0,1},{1,2},{2,8}}; char fan = 1; // from original code
//fanspec fanspace[3]={{0,1},{1,2},{2,8}}; char fan = 0; // from original code

void pickrpm ()
//This is the interrupt subroutine that increments ticks counts for each HES response.
{ ticks++; }

//This is the setup function where the serial port is initialised,
//and the interrupt is attached and other pins initialized.
void setup()
{
pinMode(hallsensor, INPUT);
Serial.begin(9600);
attachInterrupt(0, pickrpm, RISING);


pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);

digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}

void loop ()
{

ticks = 0;  // Make ticks zero before starting interrupts.

interrupts();  // or use sei(); to Enables interrupts
delay (1000);  //Wait 1 second
noInterrupts();  //  or use  cli();  to Disable interrupts


Speed = ((ticks * magnet *1.875)/fanspace[fan].fandiv);  // rpm calculation

  Serial.print (Speed, DEC);  
  Serial.print (" RPM\r\n");

val = analogRead(panel); //

// Following code is for RGB LED.
  if ((Speed > 0) &&(val <= PNLLO)){
  digitalWrite(9, HIGH);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  analogWrite(thr, THR1);
  }


else if ((Speed > 0)&&((val > PNLMD)&&(val < PNLHI))){
  digitalWrite(11, HIGH);
  digitalWrite(9, LOW); 
  digitalWrite(10, LOW);
  analogWrite(thr, THR2);
  }
  if ((Speed > 0)&&(val > PNLHI)){
  digitalWrite(9, LOW); 
  digitalWrite(10, HIGH );
  digitalWrite(11, HIGH);
  analogWrite(thr, THR3);
  }

  if (Speed == 0){
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  analogWrite(thr, 0);
i tried the 1k ohm resistor and 100uF capacitor on simulation. it seems it will work. i found an access to an oscilloscope so i will try today.
 
Last edited:

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
ok. this code works. but only when hall sensor magnets mathces the sensor...
i need to modify this or use previous one which keeps track of on of times not the count. i am stuck again.
 
D

Deleted member 4366

Guest
Some pedal sensors only give a signal in the forward direction. They can be recognised by the additional flashing LED on them, which only flashes when they turn in the right direction,
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
there are no leds on mine. it is simple chinese sensor. but, original system only works on one direction. my setup can work both ways too. it is not a problem for me. bike is with coaster brake.

my issue is, code must wait for some time to see if there will be a pulse next or not. original code only works when sensor state is HIGH. it acts like a traction control now.
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
panel has constant 5 volts on one of pins. there are 2 other pins for lights button. when pressed it outputs 36 volts. there are two other wires, which are ground and signal.

question is, if i supply 5V from arduino instead of controller 5v out, and if i send same preset idle voltage to controller back from arduino, will controller be able to differenciate it?

will there be ground loop problems?
 
D

Deleted member 4366

Guest
You need to explain more what all that means: Which panel? There's no 5v to or from an 810 display. There's 5v inside which comes from the 36v, which is cut down and regulated by a 5v regulator. It's used to power the CPU in the display.

All grounds come from the battery, so no ground loop problems can occur. If you use an auxilliary battery to power something, you must join the grounds. You then have to be careful not to parallel any sense wires because the 5v can be different, which causes problems. This is the problem you get with running one throttle to two controllers. You must take the 5v from only one and split only the signal wire to the two controllers. Some people try to parallel all three wires from each controller to the throttle, but that causes all sorts of problems becuase of the slight differences between the two 5v regulators.
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
Yes you are right. 5 volt is for panel i guess. My main problem is working with hall sensor on arduino within my code.


* edit: i read what you wrote again. when you are saying 5 volts from one soure, will this apply to throtte and hall sensor too? i mean , if i supply voltage to hall sensor ,should i supply 5 volts to throttle from arduino too? won't controller lost any signal in this scenerio? or when panel is switcehd on, will it care if there is throttle or not?? it does not care the hall sensor. i know this by disconnecting it.


what ever i do, even it works on simulation flawlessly, hall sensor acts weird on actual setup. if i short signal and constant 5 volts, it acts like there is hall signal pulse and keep running on preset speeds i sent from arduino. when i change lo mid hi from led panel, speed of wheel changes as planned ( running without panel ofcourse becasue my preset voltages sent to throttle). but when it is connected to arduino and pulsing, nothing happens. serial monitor shows 0 rpm. multimeter shows pulses. hall sensor is fed by arduino and there is no relation with controller as you suggested. when i attach it back to controller it works as speed controller so pins are correct too(native mode of that panel and controller). on my simulations i was using square wave generator with 5 volts and 2.5 volts offset, it was reading RPM accordingly. when it was set to 1Hz, 8 mangents was making 60 rpm. (this is not that important but it was showing this on serial monitor).

i think i am lost again... i need to try again and again.

any comments?
 
D

Deleted member 4366

Guest
Do you have a pull-up resistor on the halls. Without one, they don't switch properly.

The 5v regulator in a normal controller supplies about 300 mA for the CPU, throttle, PAS and anything else, so I guess you need the same. They normally use a 7805 TO-92 fed from a 78T12 TO-220.
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
i do not use a resistor. cant i use internal pull up resistors?

here is an update on code.

i managed to modify another code with same variables and conditions there a missing points but logic is much closer to what i need. i attached a hall sensor shield and i used a neodmyum magnet to test it.

when there is hall sensor activity this sens output voltage, it waits for sometime if there is still activity it keeps going. if not activity it stops sending voltage on preset voltage ( for only 1 preset, for othere i cant add , i cant manage it)


problem is i cant add other to panel input voltages and their related outputs to thrtotlle signal cable.

another problem i face here is, if padal sensor stops on halls sensor magnets it keeps sending voltage to output. i need to figure it. it should wait for some time and cuts power too for HIGH state of hall sensor. any comments?

Code:
int valu = 0;
int panel = 11; //panel voltage input pin
int thr = 6; //throttle signal addition wire with a diode on throttle
int THR1 = 90;  // preset output preset voltage. 1.9 volts 8 bit
int THR2 = 130; // 2.5 volts
int THR3 = 185; // 4.8 volts
int PNLLO = 420; // constant signal from control panel 2 volt. 10 bit
int PNLMD = 630; // 3 volt. 10 bit
int PNLHI = 800; // 4 volt. 10 bit

float rotationTime;
float distanceTravelledPerSecond;
float wheelCircumference = 2;  // Circumference of the wheel
float RPM;
float speeds;
float maximumSpeed;
unsigned int distanceTravelled;
//unsigned int averageSpeed;  // not needed for now
unsigned long revoloutions = 0;
unsigned long startRotation = 0;
unsigned long endRotation = 0;
unsigned long timeInSeconds;
unsigned long timeInMilliseconds;
unsigned long lastMillis;
boolean reedSwitchState;
boolean lastReedSwitchState;
const int reedSwitchPin = 2;

int buttonState;
int val;
int val2;

void DoTimeAndDistanceCalcs()
{
  revoloutions ++;
  endRotation = millis();
  rotationTime = endRotation - startRotation;
  startRotation = endRotation;
  RPM = (600 / rotationTime);
  distanceTravelled = revoloutions * wheelCircumference / 100;
  distanceTravelledPerSecond = RPM * wheelCircumference;
  distanceTravelledPerSecond = distanceTravelledPerSecond / 1000 * 60;
  speeds = distanceTravelledPerSecond;
  if (speeds > maximumSpeed)
  maximumSpeed = speeds;
  timeInSeconds = millis();
  timeInSeconds = timeInMilliseconds / 1000;
  //averageSpeed = (distanceTravelled / timeInSeconds);  //not needed for now
}

void setup() {
  pinMode(reedSwitchPin, INPUT);
  Serial.begin(9600);
  buttonState = digitalRead(reedSwitchPin);
  // lcd.begin(16,4);

}
void loop() {

  valu = analogRead(panel);
  val = digitalRead(reedSwitchPin);
  delay(10);
  val2 = digitalRead(reedSwitchPin);

  if (val == val2) {
  if (val != buttonState) {
  lastReedSwitchState = reedSwitchState;
  reedSwitchState = val;


  if ((lastReedSwitchState == HIGH) && (reedSwitchState == LOW) && (valu <= PNLLO)) {
  DoTimeAndDistanceCalcs();

  analogWrite(thr, THR1);

  //  lcd.setCursor(8,3);

  }





  else  {
  DoTimeAndDistanceCalcs();
  delay(1500);

// there must be some conditions to stop sending voltage to output pin if hall sensor is HIGH for too long. 
  analogWrite(thr, 0);
  }


  // else if ((lastReedSwitchState == LOW) && (reedSwitchState == HIGH) && (valu >= PNLHI)){
  // DoTimeAndDistanceCalcs();
  // analogWrite(thr, THR3); this part wont work for a reason...
  }


  }
  buttonState = val ;
  Serial.println(digitalRead(reedSwitchPin)); // test

}
 

dgncsk

Pedelecer
Mar 31, 2017
83
6
43
Ankara Turkey
i think i did it this time.

Code:
int val = 0;
int panel = 11; //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 = 130; // 2.7 volts
int THR3 = 185; // 4.3 volts
int PNLLO = 420; // 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) && (panel <= PNLLO)) {  //if panel gives 2 volts.
  if (firsttime == 1) {
  startTime = millis();
  firsttime = 0;
  analogWrite(thr, THR1); // arduino has 1.7 volts output
 
  delay (400);
 

  } else
  { if ((digitalRead(hallsensor) == LOW) && (panel > PNLLO) && (panel < PNLHI)) { //if panel gives 3 volts.
  if (firsttime == 1) {
  startTime = millis();
  firsttime = 0;
  analogWrite(thr, THR2); // arduino has 1.7 volts output
 
  delay (400);

  } else
  { if ((digitalRead(hallsensor) == LOW) && (panel >= PNLHI)) { //if panel gives 4 volts.
  if (firsttime == 1) {
  startTime = millis();
  firsttime = 0;
  analogWrite(thr, THR3); // arduino has 1.7 volts output
 
  delay (400);
  }

  }
  }
  }
  }




  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 (400);
  analogWrite(thr, 0); // more than delay, cut power.
  }
}
 

Advertisers