Push Button Throttle

Hi Greg,

Thanks for sharing. I've noticed an error in my circuit schematic - the 22uf cap should be 0.22uf! :oops: I've updated the schematic.

It looks like you might have the two decoupling caps in series? If so then they should be in parallel. I notice that you are using a couple of aluminium caps - Both the decoupling caps should be ceramic (small brown disc type) caps as they are better able to react quickly to voltage changes.

The slower aluminium 100uf RC filter cap is fine as it doesn't need to be fast - just make sure it is positioned the right way round, as the aluminium caps are polarized (apologies if you already knew this!).

When you update the capacitors, let us know how you get on :)
 
My 1st ebike was a Clean Republic conversion kit. It uses an on/off push button, work quite well.
 
Any news on when you can sell either kits or complete throttles. Also what if you dont use E-brakes. I have a switch and could but I don't now.
otherDoc
 
docnjoj said:
Any news on when you can sell either kits or complete throttles. Also what if you dont use E-brakes. I have a switch and could but I don't now.
otherDoc

Thanks for the interest - while my bike is indoors and messing up my apartment I am taking the opportunity to complete my other bike mod this weekend (using an ATTiny, buttons and servos to function the derailleurs). I hope to be finished all the mods by the end of the coming weekend so I can get back on my bike and testing!

The chip requires that your controller operates a 5V brake line that is grounded to 0V when the lever is pulled, as infineon and BMS Battery's KU series controllers do, this is probably fairly standard but I have only tested these controllers.

I will not be selling complete throttle assemblies because there are too many variances such as varying connector types, control cable length, button preferences etc... I worry that if I were to include all the possible connector & wiring options then the price will go through the roof and I will end up pleasing nobody. I will sell (if anyone is interested!) the pre-programmed chip; once it's fully tested and I'm 100% happy with it; along with the resistors and capacitors needed.

Thanks

John
 
Thanks for the feedback. Mines working now. Can't wait to see the push button derailleur project.
I might order a servo from HK and copy you again. As they say it's the sincerest form of flattery.

I made version 2 with the corrected decoupling ceramics. Laid it out a bit neater this time.
Cable tied the buttons to the grip.
It works, I just went for a spin around the block.
It's a bit touchy and may take some time to get used to it.
Signal line goes from 1.4V up to 3.7V over 20 steps, with a 4.6V supply so I'm not sure it's hitting full speed. So that's probably going to be a bit of fine tuning required there .

docnjoj said:
Also what if you dont use E-brakes. I have a switch and could but I don't now.
otherDoc

I am testing it without the ebrake line, and I wouldn't recommend it. Even if you get it down to the lowest speed setting and round a corner, as soon as you're off the brake it takes off again, feels scary. Any old button or switch would do though.

Now to mount mine properly and install an ebrake...


 
Hi Gregory,

Your wee board looks great 8)

My buttons are a little jumpy and I can't quite work out why. I am using another button library for my servo derailleurs, and I like how it functions much better. I will update the code for the throttle with the alternative button library and see if it makes any difference - I'll post up the new code if there's any improvement.

Regarding your concerns about the output voltage, there are a number of posts by respected members here that state the throttle max is achieved at around 3.5V, so I stuck with that. Check out a couple of such posts hereand here

Cheers

John
 
johnamon said:
Hi Gregory,

Your wee board looks great 8)

My buttons are a little jumpy and I can't quite work out why. I am using another button library for my servo derailleurs, and I like how it functions much better. I will update the code for the throttle with the alternative button library and see if it makes any difference - I'll post up the new code if there's any improvement.

Regarding your concerns about the output voltage, there are a number of posts by respected members here that state the throttle max is achieved at around 3.5V, so I stuck with that. Check out a couple of such posts hereand here

Cheers

John


hi what sort of servo derailleur are you making. as i am designing a gearbox that i was thinking of making it push button change. are you using to buttons as in one press of the button to change gears or do you have to hold it down to change.
i would be up for buying one of the boards off you if its what i am thinking of.
adam
 
I am using servos to actuate the normal derailleur wires, which are clamped to the servos near the bottom bracket. I am using a single up, and a single down button with two functions each:

  • momentary press of up/down button = rear derailleur up/down
  • 1 second press of up/down button = front derailleur up/down

The code and servos work well, but securing the servos to the bike in a nice way is turning out to be a mega PITA, it may derail the project :cry:
 
johnamon said:
I am using servos to actuate the normal derailleur wires, which are clamped to the servos near the bottom bracket. I am using a single up, and a single down button with two functions each:

  • momentary press of up/down button = rear derailleur up/down
  • 1 second press of up/down button = front derailleur up/down

The code and servos work well, but securing the servos to the bike in a nice way is turning out to be a mega PITA, it may derail the project :cry:


i found this link http://www.diyshift.com/index.html i would have a go at doing it but i have to many things to do at the moment :D
adam
 
Hi guys,

I have updated the software to make the buttons behave better, they seem less jittery now. In order to remove the jitter I have also manually tabulated the throttle values, rather than allowing the arduino map function to calculate them on the fly. With the manually input throttle values, I get one or two presses (of the 20 total) at the top end of the scale which are beyond the 100% point on the controller, so the wheel doesn't spin any faster. It would be nice to know if others also have a couple of dead presses at the top? Gregory?

In order to run the code below, you must install the ClickButton library, which can be found here

and here is the new code:
Code:
#include <ClickButton.h>
#include <TinyDebugKnockBang.h>
#include <UserTimer.h>

const int upPin = PB1;  // ATtiny45 Pin 6
const int downPin = PB2; //ATtiny45 Pin 7
const int throttleOut = PB0; //ATtiny45 Pin 5
const int brake = PB3;  //ATtiny45 Pin 2
int PWMThrottle = 0;
const int throttleTop = 218; //allows for voltage drop accross 500ohm resistor in voltage divider 3.5V finish Assuming 4.32V supply voltage
const int throttleBottom = 74;// allows for voltage drop accross 500ohm resistor in voltage divider 1.3V Start (Try 1.4 if needs extra press) Assuming 4.32V supply voltage
int throttle = 0;

int upButtonState = HIGH;
int downButtonState = HIGH;

ClickButton debounceUp(upPin, LOW, CLICKBTN_PULLUP);
ClickButton debounceDown(downPin, LOW, CLICKBTN_PULLUP);
int upButtonfunction = 0;
int downButtonfunction = 0;

int throttlemaps[20] = {74,82,90,97,105,112,120,127,135,142,150,157,165,173,180,188,195,203,210,218};

void setup()
{
  
  //Turn off Analogue comparitor
    ACSR |= _BV(ACD);                         //disable the analog comparator
    ADCSRA &= ~_BV(ADEN);                     //disable ADC
  
  
  //Set PWM Frequency, Only Use PB0 or PB1
  UserTimer_SetToPowerup();
  UserTimer_SetWaveformGenerationMode( UserTimer_(Fast_PWM_FF) );
  UserTimer_ClockSelect( UserTimer_(Prescale_Value_1) );
  // Frequency is F_CPU / (1 * (0xFF+1))
  // (8 megahertz) / 256*8 = 3.9  31.25 kilohertz
 
  pinMode(upPin, INPUT);
  digitalWrite(upPin, HIGH);
  pinMode(PB4, INPUT);
  digitalWrite(PB4, HIGH);
  pinMode(PB5, INPUT);
  digitalWrite(PB5, HIGH);
  pinMode(downPin, INPUT);
  digitalWrite(downPin, HIGH);
  pinMode(throttleOut,OUTPUT);
  pinMode(brake,INPUT);
  digitalWrite(brake, HIGH); 
 

  //setup buttons 
  debounceUp.maxPresses     = 20;    // max button multiclick count
  debounceUp.debounceTime   = 50;   // Debounce timer in ms
  debounceUp.multiclickTime = 250;  // Time limit for multi clicks
  debounceUp.heldDownTime   = 500; // time until "held-down clicks" register
  
  
    //setup buttons 
  debounceDown.maxPresses     = 20;    // max button multiclick count
  debounceDown.debounceTime   = 50;   // Debounce timer in ms
  debounceDown.multiclickTime = 250;  // Time limit for multi clicks
  debounceDown.heldDownTime   = 500; // time until "held-down clicks" register
}

void loop()
{ 
  if(digitalRead(brake)==LOW){
    if(PWMThrottle == 0 && throttle==0){    
    }
    else{
      PWMThrottle = 0;
      throttle=0;
      analogWrite(throttleOut,PWMThrottle);
    } 
  }
  else{
     // Update the debouncer
      debounceUp.Update();
      debounceDown.Update();
      
      if (debounceUp.click != 0) upButtonfunction = debounceUp.click;
      if (debounceDown.click != 0) downButtonfunction = debounceDown.click;
      
      //Perform Actions based on button press
      if(debounceUp.click == 1) Action(1);
      if(debounceDown.click == 1) Action(2);
      
      //Perform Actions based on button hold
      if(upButtonfunction < -1 && debounceUp.depressed == true) Action(1);
      if(downButtonfunction < -1 && debounceDown.depressed == true) Action(2);
    }
}



void Action(int button)
{
  if(button == 1)
  { 
    if(throttle<20){
     throttle = throttle + 1;
     for(int g=0;g<4;g++){    
       PWMThrottle = (throttlemaps[throttle]-8)+((g+1)*2);
       analogWrite(throttleOut,PWMThrottle);
       delay(60);
     }
  }
    else{
        PWMThrottle = throttleTop;
         analogWrite(throttleOut,PWMThrottle); 
    }   
      }
   
  if(button == 2){
    if(throttle==0){
      PWMThrottle = 0;
      analogWrite(throttleOut,0); 
    }
    else{     
     throttle = throttle - 1; 
     PWMThrottle = throttlemaps[throttle];
     analogWrite(throttleOut,PWMThrottle);
     delay(500); 
    }  
  }  
}
 
Back
Top