''''''''''''''''''''''''' 'PICAXE-08M E-BIKE CODE ' ' 21-6-09 ' ''''''''''''''''''''''''' FirstPowerUp: 'This is so the bike doesn't bolt from under you if the throttle is Gosub ReadThrottle 'on when powering up! If W1 > 100 then Goto FirstPowerUp Chopper: Gosub ReadThrottle 'Reads the Hall Effect throttle value. (0 - 1023 in theory! More like 15 to 995) If W1 < 25 then Gosub ZeroThrottle 'Zero out the throttle value if it's already a very low value. If Input3 = 0 And W1 > 200 then Gosub HighTemp 'Only go about 1/4 speed if the heat sink temp switch opens. Pwmout 2, 250, W1 'This is where it all happens. Poke $12, $06 'Pokes the TCON register to prescale the PWM by 16:1 ratio. Now pulses down to 250Hz. Goto Chopper ReadThrottle: Readadc10 1, W1 'Read the throttle value and put it into word varible "W1". W1 = W1 - 20 'Trying to scale the throttle as these Hall Effect throttles are not perfect! W1 = W1 * 20/19 If W1 > 1023 then Gosub MaxThrottle 'Hold the value to 1023 if it goes higher then 1023. Return ZeroThrottle: 'Zero out the throttle value to zero if required. W1 = 0 Return MaxThrottle: 'Maximin throttle value to be held at 1023. W1 = 1023 Return HighTemp: W1 = 200 'Hold the bike speed to about a 1/4 if the high temp switch opens. Return