Hippy & Alistairsam
I am using the folowing pogram from post #56 on page
http://www.picaxeforum.co.uk/showthread.php?15591-stepper-control-with-acceleration-and-variable-freq-square-wave-output/page6
I tryed to figure out how i could set the max speed of the steppermotor? But did not succeeded.
The program is working fine but I would like to change the max rpm. could one of you please help me here?
I would allso like to know how i can change the accelleration.
Alistairsam here is your code unchanged.
Thank you
Willy
I am using the folowing pogram from post #56 on page
http://www.picaxeforum.co.uk/showthread.php?15591-stepper-control-with-acceleration-and-variable-freq-square-wave-output/page6
I tryed to figure out how i could set the max speed of the steppermotor? But did not succeeded.
The program is working fine but I would like to change the max rpm. could one of you please help me here?
I would allso like to know how i can change the accelleration.
Alistairsam here is your code unchanged.
Code:
'28x2
' picaxe pin assignment for stepper driver inputs
' Stepper Driver - Allegro A4983 driver
' High speed slew below uses 1/16 micro stepping
' enablepin = pinC.0
' Dirpin = pinC.1 -> High - CCW, Low - CW
' Clckpin = pinC.2
' MS0pin = pinC.3
' MS1pin = pinC.4
' MS2pin = pinC.5
' Full stepping - MS0,MS1,MS2 low
' 1/16th stepping - MS0, MS1, MS2 high - for tracking speed, hi and low speeds
' 1/8th stepping - MS0 high, MS1 high, MS2 low
'pwmdiv ranges @ 8Mhz
'pwmdiv 16 -> 500 - 1940 Hz
'pwmdiv 4 -> 1950 - 7800 Hz
setfreq m8
Symbol BB = w0
Symbol percal2 = w2
Symbol perd = w3
Symbol Fmin = w4
Symbol Fmax = w5
Symbol F = w6
Symbol Dutyreq =w7
Symbol Duty = w8
Symbol dutycal1 = w9
Symbol dutycal2 = w10
Symbol F2 = w11
Symbol Fdiff = w12
'Enter max freq as max freq / 10 kHz
'Enter duty as duty % * 10
let dirsB = %00000000
let Dutyreq = 300
let Fmin = 50
let Fmax = 2400
Setpinslow:
pwmout C.2,off
let dirsC = %10111111
let pinsC = %10000001 'Turn LED on C.7 on, Enable off
goto keyscan:
keyscan:
Do
for BB = 1 to 10000 step 1
pause 100
if pinB.3 = 1 then highCW
if pinB.4 = 1 then HighCCW
if pinB.5 = 1 then LowCW
if pinB.6 = 1 then LowCCW
if pinB.7 = 1 then TrackCW
if BB = 10000 then goto slp
next BB
Loop
HighCW:
pauseus 5000
if pinB.3 = 0 then Setpinslow:
let pinsC = %10111000 'set enable low and DIR low, 1/16 step
gosub pwroutine
Do
if pinB.3 = 0 then Decel:
pwmout C.2, perd, duty
Loop
HighCCW:
pauseus 5000
if pinB.4 = 0 then Setpinslow:
let pinsC = %10111010 'set enable low and DIR high, 1/16 step
gosub pwroutine
Do
if pinB.4 = 0 then Decel:
pwmout C.2, perd, duty
Loop
LowCW:
pauseus 5000
let pinsC = %10111000 'set enable low and DIR low, 1/16th step
Do
if pinB.5 = 0 then Setpinslow:
Toggle C.2
PauseUs 10
Loop
LowCCW:
pauseus 5000
let pinsC = %10111010 'set enable low and DIR high, 1/16th step
Do
if pinB.6 = 0 then Setpinslow:
Toggle C.2
PauseUs 10
Loop
TrackCW:
pauseus 5000
let pinsC = %10111000 'set enable low and DIR low, 1/16th step
Do
if pinB.7 = 0 then Setpinslow:
Toggle C.2
Pauseus 500
Loop
pwroutine:
sertxd ("Div16")
F = Fmin
Do
Select Case F
Fdiff = F >> 2
Case > 186 goto Div4
Case < 187 : F = F + Fdiff
End Select
percal2 = 12504 / F
perd = percal2 - 1
dutycal1 = Dutyreq / 25
dutycal2 = perd + 1
duty = dutycal1 * dutycal2 /10
sertxd (#w6,",",#w3,",",#w8)
pwmout pwmdiv16, C.2,perd,duty
Loop
Div4:
sertxd ("Div4")
Do
Select Case F
Fdiff = F >> 3
Case > Fmax Return
Case > 758 goto NoDiv
Case < 759 : F = F + Fdiff
End Select
percal2 = 50000 / F
perd = percal2 - 1
dutycal1 = Dutyreq / 25
dutycal2 = perd + 1
duty = dutycal1 * dutycal2 / 10
sertxd (#w6,",",#w3,",",#w8)
pwmout pwmdiv4, C.2,perd,duty
Loop
NoDiv:
sertxd ("NoDiv")
Do
if pinB.3 = 0 and pinB.4 = 0 then Decel
Select Case F
Fdiff = F >> 5
Case > Fmax Return
Case < Fmax : F = F + Fdiff
End Select
percal2 = 20000 / F
perd = percal2 * 10
perd = perd - 1
dutycal1 = Dutyreq / 25
dutycal2 = perd + 1
duty = dutycal1 * dutycal2 / 10
sertxd (#w6,",",#w3,",",#w8)
pwmout C.2,perd,duty
Loop
return
Decel:
sertxd ("decel")
Do
Select Case F
Fdiff = F >> 4
Case < 790 goto Setpinslow
Case > 790 : F = F - Fdiff
End Select
percal2 = 20000 / F
perd = percal2 * 10
perd = perd - 1
dutycal1 = Dutyreq / 25
dutycal2 = perd + 1
duty = dutycal1 * dutycal2 / 10
sertxd (#w6,",",#w3,",",#w8)
pwmout C.2,perd,duty
Loop
slp:
hInt0Flag = 0
HIntSetup %00010001 ' Wake on B.0 (HINT0) going high
let pinsC = %00000001
disablebod
Sleep 0
'Do : Loop Until hint0Flag = 1
enablebod
goto setpinsl
Thank you
Willy
Last edited: