Mad Professor
Senior Member
Good day all.
I am looking at starting a new picaxe project.
Last summer I brought some electric quad bikes for my children, and the kids loved them.
But the quad bikes just use a simple on/off switch to drive the motor.
So over the winter I have been thinking about making a controller to give them more control over the speed.
I have not yet designed any of the control boards yet, as I 1st wanted to start work on the picaxe software, To see if I could get it to do what I wanted.
It seems that most of the coding so far is all math based, and math is not my strong point at the best of times.
Here is the current code that I have come up with so far.
I am sure there is better whys of doing the above code, but I have done it in the way that I understand and can follow.
What I need help with at this point in time, is the math needed to calc the value needed for the PWMOUT Freq, taken from motor_freq.
And then the math needed to work out the PWMOUT Duty Cycle value based on the TPS.
Any help you can give on this project would be grate, and I am sure my kids would also thank you for your time, and support.
Best Regards.
I am looking at starting a new picaxe project.
Last summer I brought some electric quad bikes for my children, and the kids loved them.
But the quad bikes just use a simple on/off switch to drive the motor.
So over the winter I have been thinking about making a controller to give them more control over the speed.
I have not yet designed any of the control boards yet, as I 1st wanted to start work on the picaxe software, To see if I could get it to do what I wanted.
It seems that most of the coding so far is all math based, and math is not my strong point at the best of times.
Here is the current code that I have come up with so far.
Code:
#picaxe 18M2 '
let pinsB = %00000000 '
let pinsC = %00000000 '
'Inputs
symbol battery_voltage = C.0 ' Battery voltage monitoring input.
symbol throttle = C.2 ' Throttle input.
symbol foot_brake = B.0 ' Foot brake input.
'Outputs
symbol power_contactor = B.7 ' Drive motor power contactor output.
symbol drive_motor = B.6 ' Drive motor output.
'Settings
symbol motor_freq = 15600 ' Drive motor running Freq in Hz.
symbol tps_min = 0 ' ADC Value for TPS Min.
symbol tps_max = 1023 ' ADC Value for TPS Max.
symbol tps_safe = 10 ' Max percentage of TPS permitted at powerup.
'
symbol pwm_freq = w12 '
symbol pwm_duty = w13 '
init:
low power_contactor ' Turn off power to drive motor power contactor.
pwmout drive_motor,off ' Turn off pwm signal to drive motor.
' insert math equel to "w12 = (1000000/motor_freq)-1 '
pause 1000 ' Pause for 1000ms (1Sec).
sertxd ("EV Controller - Firmware v0.1 (09/03/2011)",cr,lf) '
powerup_throttle_check:
readadc10 throttle,w1 ' Read raw ADC value of TPS, and store data into w1.
let w2 = tps_safe * tps_max '
let w3 = tps_safe * tps_min '
let w4 = w2 - w3 '
let w5 = w4 / 100 '
let w6 = tps_min + w5 '
'debug '
if w1 >= w6 then goto powerup_throttle_check: '
if w1 < w6 then goto main: '
goto powerup_throttle_check: '
main:
readadc10 throttle,w1 ' Read raw ADC value of TPS, and store data into w1.
'insert math to calc req pwm_duty based on tps value.
high power_contactor ' Turn on power to drive motor power contactor.
pwmout drive_motor,pwm_freq,pwm_duty '
debug '
goto main: '
interrupt:
low power_contactor ' Turn off power to drive motor power contactor.
pwmout drive_motor,off ' Turn off pwm signal to drive motor.
'
return '
What I need help with at this point in time, is the math needed to calc the value needed for the PWMOUT Freq, taken from motor_freq.
And then the math needed to work out the PWMOUT Duty Cycle value based on the TPS.
Any help you can give on this project would be grate, and I am sure my kids would also thank you for your time, and support.
Best Regards.