Hankinator
New Member
First time poster long time lurker.
I have a need to control a servo based on pulsin. Specifically I have a dirt bike with an electronic controlled powervalve. The CDI/Power valve controller are smoked and quite expensive to replace. I have the CDI coverd but need to build a power valve controller.
In a nut shell I need to read RPM of the engine then make a mechanical movement with a servo based on RPM.
I learned most everything from this thread: http://www.picaxeforum.co.uk/showthread.php?23897-Looking-for-a-DIY-Shift-Rev-Light-ideas
So I have it working a bit now but think it can be better. Code I am using is below...thanks to Goetex.
As you can see in my code I have position "step" based on RPM ranges. How can I ditch this code and convert to an incremental version?
Any ideas?
Thanks,
Hank
I have a need to control a servo based on pulsin. Specifically I have a dirt bike with an electronic controlled powervalve. The CDI/Power valve controller are smoked and quite expensive to replace. I have the CDI coverd but need to build a power valve controller.
In a nut shell I need to read RPM of the engine then make a mechanical movement with a servo based on RPM.
I learned most everything from this thread: http://www.picaxeforum.co.uk/showthread.php?23897-Looking-for-a-DIY-Shift-Rev-Light-ideas
So I have it working a bit now but think it can be better. Code I am using is below...thanks to Goetex.
As you can see in my code I have position "step" based on RPM ranges. How can I ditch this code and convert to an incremental version?
Code:
'****************************
'* HB 3-6k
'Pulse in period RPM
'2000 3000
'1500 4000
'1200 5000
'1000 6000
'800 7500
'700 8571.428571
'600 10000
'****************************
#Picaxe 08M2
#No_data
#com 6 'change as required
#terminal 4800
setfreq M4
pause 200
symbol MARK = W1
symbol SPACE = W2
symbol Period = W3
'===========================================
init: servo 1,170 ; initialise servo ; move servo to one end....power valve is closed
MAIN:
Pulsin C.4,1,MARK 'Measure Positive width
Pulsin C.4,0,SPACE 'Measure Negative width
LET PERIOD = MARK + SPACE 'Calculate Time period
'Display Data
'sertxd ("MARK = ",#MARK,CR,LF)
'sertxd ("SPACE = ",#SPACE,CR,LF)
sertxd ("PERIOD = ",#PERIOD,CR,LF)
sertxd (CR,LF)
pause 200
IF PERIOD < 10000 AND PERIOD >=2000 then ; Check RPM..if 3k or less keep PV closed (servo at closed position 190?)
servopos 1,170
elseif PERIOD <1999 AND PERIOD >=1500 then ;Open @ 4k RPM
servopos 1,145
elseif PERIOD <1499 AND PERIOD >=1000 then ;Open @ 5k RPM
servopos 1,105
elseif PERIOD <999 AND PERIOD >=400 then ;Open @ 6k and avove RPM
servopos 1,78
'elseif PERIOD <449 then ;open when off or stray.
'servopos 1,78
'elseif W3 <1399 AND W3 >=1250 then ;Open @ 7000 RPM
'servopos 1,150
'elseif W3 <1249 AND W3 >=100 then ;Open @ 7500 RPM
'servopos 1,140
'elseif W3 <=99 then
'servopos 1,190
'elseif W1 >6000 then ;Full open 8500 and over
'servopos 0,225
end if
goto MAIN:
Thanks,
Hank