Push Button Throttle

johnamon

10 W
Joined
Jun 20, 2011
Messages
68
Location
Aberdeen, Scotland
Hi all,

I have been working on a push button throttle. The protoboard soldering is all done and I plan to do the bike wiring this evening - so we'll soon find out it it works...

The throttle was created because I didn't find levers or twist throttles to be ideal, changing gear is a pain because I need to release the throttle temporarily which results in jerky power.

My new throttle is designed to increase the throttle output in 5% increments up to 100% and hold the power at the desired level (cruise control). The size of the increments may be increased or decreased, I just thought 5% sounded reasonable for my mid-power (<1kw) setup. The power may be regulated downwards by pressing the "down" button. The throttle increments are scaled from 1.3V (5%) to 3.5V(100%) with additional logic ensuring that 0% outputs 0v. The PWM throttle output from the ATtiny chip is smoothed to near true analogue via a low pass filter.

If the user hits the brakes - then the throttle cuts out completely (0v). An ATtiny45 microcontroller controls the throttle and responds to button presses & brake actuation. The current design requires a digital HIGH signal on the brake line, so around 3V or greater is required to be supplied to the microcontroller.

The circuit looks like this:

ATtiny Rev1.jpg
ThrottleProto 2.jpg

I am currently operating both "up" and "down" buttons off a single microcontroller input because I only have 2 spare wires available at the handlebars, this can be changed to individual button lines which would require 3 wires in total. With three signal wires - one could run a rotary encoder built into the bicycle bell - that'd be cool 8)

I'll hopefully get a video up this weekend of the throttle working :D

Thanks

John
 
Sounds perfect for long open road rides to me. I'd want a secondary ordinary throttle for city use. Then you'd have the best of both worlds.

One way to solve shifter issues if you are using twist shifters, is to put the rear shifter on the left side. It works backwards that way, but you quickly get used to it.

I haven't found shifting much of a problem when using trigger shifters integrated into the brakes, combined with a half twist throttle.
 
I do have grip shift shifters - but my bike really suffers with getting crud in/on the wires and wire stretch - so I have a cunning plan to remove the PITA shifters almost entirely

here

A little PCB & ATtiny45 as above should be sufficient to operate the two required servos.
 
Lol - you can just press and hold the "up" button for a few seconds and it will ramp up to full throttle!! No need to press 20 times :wink:
 
Not the same, but same title:
http://www.endless-sphere.com/forums/viewtopic.php?f=2&t=34612&hilit=+Push+Button+Throttle+

Oh, and what yours does (in a differnet way) is similar to the old Crystalyte cruise control units.
 
Johnamon, thanks for posting. Excellant work....This is the device i need for my electric folder. I'm using a halfgrip throttle at the moment but i get wrist ache from using it. The Ananda controller fitted to the bike doesn't have cruise facitily. I thought of swapping it for a ku63 but this could be a better solution. Can i buy a pre-programmed device from you? (i'll need to check out the brake circuit first).
 
Wurly said:
Johnamon, thanks for posting. Excellant work....This is the device i need for my electric folder. I'm using a halfgrip throttle at the moment but i get wrist ache from using it. The Ananda controller fitted to the bike doesn't have cruise facitily. I thought of swapping it for a ku63 but this could be a better solution. Can i buy a pre-programmed device from you? (i'll need to check out the brake circuit first).

You sure can - but right now I seem to be struggling with either noise or power consumption - when I activate the throttle the wheel turns but the power is very jerky and seems to pulse somewhat.

I am going to rebuild the circuit with decoupling capacitors and see how it operates. The hall sensors in the hall throttle take 40ma, and the ATtiny chip uses nothing like that which leads me to think that the overall power consumption should be ok...
 
my 1st ebike(08/11) from clean republic has a push button throttle....
 
Well I have learned quite a few things in debugging the push-button throttle, but it works now 8)

  • The throttle hall sensor supply voltage doesn't stable enough to allow use of analogue buttons - I've had to use digital buttons with an extra wire :?
  • The throttle supply voltage sits at around 4.6v which means that PWM duty cycle must be increased to allow for it not truly being 5v
  • The throttle signal-ground circuit resistance is circa 8.6kohms which acts as a voltage divider with the resistor used in the RC filter (I had to reduce the RC filter resistor from 10kohm to 470ohm and increase the capacitor to 100uf)
  • Due to the voltage division described above, the PWM duty cycle must be increased further to account for voltage drop across the RC filter's resistor
  • ATtinys require decoupling capacitors
  • The brake works be detecting when the 5v line is grounded, so I now use the same pull-up arrangement in my ATtiny to detect brake activation when the IC's pin goes low

I will update the circuit diagram some time soon, but the throttle works well. This may be adapted to re-map a hall throttle if the supply voltage can stand up to the current requirement.
 
Yeah, it works really well - I'd like to give it a week or so of testing during my daily commute before it gets the green stamp of approval 8)

I am in the process of potting the electronics in my favourite adhesive Sugru to make it more robust, but here is the first proof of non-vapor-ware..
Button Throttle.jpg

Programming the ATtiny chips is a bit tricky because you need either a dedicated programmer, or a spare arduino to act as a programmer. I was thinking of selling the pre-programmed chips, resistors and capacitors as a kit of there was any interest, but before I get to that stage I'll make sure it's all well tested.

I have no problem sharing the code - here it is -: (Please note that if not using an infineon based controller you may need to adjust the throttleTop and throttleBottom variables to fine tune the response, although it appears to work just the same with my KU93)

Code:
#include <Bounce.h>
#define KNOCK_BANG 1
#include <TinyDebugKnockBang.h>
#include <UserTimer.h>

// change in TinyDebugSerial.h line 613 from 3 -> 1 for TinyISP
//  #define TINY_DEBUG_SERIAL_BIT         1
#ifdef KNOCK_BANG
  #define Serial Debug
#endif

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 = 217; //allows for voltage drop accross 500ohm resistor in voltage divider 3.5V finish Assuming 4.32V supply voltage
const int throttleBottom = 77;// 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;

Bounce debounceUp = Bounce( upPin, 75 );
Bounce debounceDown = Bounce( downPin, 75 );

void setup()
{
  //Turn off Analogue comparitor to save power (may not be necessary but belt and braces)
    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); 
 
 debounceUp.write(1);
 debounceUp.write(1);
}

void loop()
{
  if(digitalRead(brake)==LOW){
    if(PWMThrottle == 0 && throttle==0){    
    }
    else{
      PWMThrottle = 0;
      throttle=0;
      analogWrite(throttleOut,PWMThrottle);
    } 
  }
  else{
  
     // Update the debouncer    
      if (debounceUp.update()){
        debounceUp.rebounce(300);
        if(!debounceUp.read() ){
          Action(1);
        }
      }
      
      if(debounceDown.update()){
        debounceDown.rebounce(300);
        if(!debounceDown.read()){
          Action(2);
        }
      }
    }
}

void Action(int button)
{
  if(button == 1){
    if(throttle<100){
     for(int g=1;g<6;g++){
       throttle = throttle + 1; 
       PWMThrottle = map(throttle,0,100,throttleBottom,throttleTop);
       analogWrite(throttleOut,PWMThrottle);
       delay(50);
     }
  }
    else{
        PWMThrottle = throttleTop;
         analogWrite(throttleOut,PWMThrottle); 
    }   
  }
   
  if(button == 2){
    
  if(throttle==0){
      PWMThrottle = 0;
      analogWrite(throttleOut,0); 
    }
    
  else{     
     throttle = throttle - 5; 
     PWMThrottle = map(throttle,0,100,throttleBottom,throttleTop);
     analogWrite(throttleOut,PWMThrottle);
     delay(500); 
    }  
  }
}
 
Hello John,

I'd like to combine your push button throttle with a speedict and a separate half twist throttle.
It would be a nice touch if you had to hold the button for 2-3 seconds in order to get full throttle, and maybe combine it with a 3-speed switch, so you can switch between the full current range and just half of it.

What buttons do you use on the handle bar?
I'd be up to try your throttle, when you need a guinea pig. Shipping to Germany should be easy enough
 
Hi schwibsi,

I have so far used small ip67 buttons from Farnell here but if I were to criticise I would say they were too small...

I'm not quite sure how you would use buttons and a grip twist at the same time, one or the other I'd have thought, you'd certainly have to parallel them into a single throttle connector (and I'd say run a diode on the signal wire from the pushbutton throttle).

Your idea of full throttle via a 3 second hold is actually already implemented, full speed is acheived in circa 5 seconds as the code already stands, any faster and I'd fear chewing up the gears in my overvolted and overpowered bafang BPM. 5 seconds isn't a bad theoretical 0mph - 30mph time 8)

Thanks

John
 
Hello John,

yes, I'd parallel the two throttles. I'd compare, what I'm hoping for to the cruise control throttle buttons in a car along with the analogue accelerator.
Having only digital control without direct analogue control wouldn't suffice for me. Mold it over a bit. I think you'll find that being able to instantly change the throttle to the desired level.

How many pulses do you currently have between 0 and 100%? What's the time between the pulses if you leave your finger on the accelerator?
Does that remain constant or follow an exponentional scale?

I do have an arduino nano here, so theoretically, I could reprogram the chip, with a little guidance ... strike that... a lot of guidance that is.

Do you have a picture of your buttons installed on the handlebar? I'm still looking for a good way to get some buttons and switches on the handlebar in a nice way.
 
schwibsi said:
Hello John,
.....Do you have a picture of your buttons installed on the handlebar? I'm still looking for a good way to get some buttons and switches on the handlebar in a nice way.

Hi Schwibsi, please see the photo below of the buttons in the process of being sugru'd on to the shifters. For reference, the buttons are 6mm sq. I'm looking forward to having the twist throttle removed, I think the buttons will be much more stealth. If I had any black Sugru left they'd be even more stealth :wink:

DSC_1738.JPG

It turns out that it'll be a week or so before I start my full-blown commuting testing, as I am awaiting some JST connectors arriving from Hong Kong...
 
Thanks, you should have mailed me about the connectors. I would have sent you some ;)

Hmm... Sugru for the buttons... that's an interesting idea.
 
Glad you are getting it sussed out Johnamon. I'm still interested in having one of these when you have finally tested it.
 
johnamon said:
Well I have learned quite a few things in debugging the push-button throttle, but it works now 8)

  • The throttle hall sensor supply voltage doesn't stable enough to allow use of analogue buttons - I've had to use digital buttons with an extra wire :?
  • The throttle supply voltage sits at around 4.6v which means that PWM duty cycle must be increased to allow for it not truly being 5v
  • The throttle signal-ground circuit resistance is circa 8.6kohms which acts as a voltage divider with the resistor used in the RC filter (I had to reduce the RC filter resistor from 10kohm to 470ohm and increase the capacitor to 100uf)
  • Due to the voltage division described above, the PWM duty cycle must be increased further to account for voltage drop across the RC filter's resistor
  • ATtinys require decoupling capacitors
  • The brake works be detecting when the 5v line is grounded, so I now use the same pull-up arrangement in my ATtiny to detect brake activation when the IC's pin goes low

Here is the working circuit diagram. This may be adapted to re-map a hall throttle if the supply voltage can stand up to the current requirement.

ATtiny Rev 3.jpg
 
That's a perfect implementation.

Sugru is alight, you could just pot it with cheap resin into a chunk then cable tie it
 
Or I could 3D you a bunch of cases.

I'm working on a 3d printed hall throttle. Sick of the sh*t on the market. My fourth just broke before I even got the bike out for the maiden run! :evil:
 
let me no when you want to sell it as a kit of parts i will buy a set off you.
i found this on the bay that looks like it might work for the buttons.
adam

http://www.ebay.co.uk/itm/3-Handlebar-push-button-Switch-Light-Turn-Signal-Horn-Electric-Scooter-Bike-/360607552824?pt=UK_CarsParts_Vehicles_CarParts_SM&hash=item53f5e29538
 
t3sla said:
That's a perfect implementation.

Sugru is alight, you could just pot it with cheap resin into a chunk then cable tie it

You are right, but I had sugru available lol :wink:


Samd said:
Or I could 3D you a bunch of cases.

I'm working on a 3d printed hall throttle. Sick of the sh*t on the market. My fourth just broke before I even got the bike out for the maiden run! :evil:

That's another good plan - the beauty of this little chip is that you can fit any buttons you like into any enclosure :)

xadmx said:
let me no when you want to sell it as a kit of parts i will buy a set off you.
i found this on the bay that looks like it might work for the buttons.
adam

http://www.ebay.co.uk/itm/3-Handlebar-push-button-Switch-Light-Turn-Signal-Horn-Electric-Scooter-Bike-/360607552824?pt=UK_CarsParts_Vehicles_CarParts_SM&hash=item53f5e29538

I see no reason why they wouldn't work too :D
 
Hi jonamon, update from my playing with your design. Warning I am a noob, but just putting up my experience if anyone else wants more info.

Updated to Arduino 1.0.4 since 1.0.2 didn't like playing with the atTiny library or something.

Had to install the libraries bounce and attiny cores that you call in the code.

Then I uploaded your code following this basic example using an Arduino Uno as the programmer.

Made up the circuit using some old parts, and that may have cause issues as the green cap is 30 years old and had to improvise a 460 ohm resistor. I might pop down to Altronics tomorrow and buy actual parts and start again.

I basically worked but wouldn't hold a set speed, low speeds tended to decrease and the wheel stop. Full whack seemed to work, the progressive increase and decrease worked. Again I blame the capacitor.


pushbutton throttle demo.jpg

I had some fun, and learnt a lot. Thanks for sharing.

Greg
 
Back
Top