fl { HDD motor(BLDC) PropForth5.5 2015/09/08 20:15:05 HDD motor P8 ----- A P9 ----- B P10 ----- C } \ =========================================================================== \ Constants \ =========================================================================== 8 wconstant phaseA 9 wconstant phaseB d10 wconstant phaseC clkfreq d40 / constant 25msec variable phaseState -4 allot 1 c, 1 c, 1 c, 0 c, 0 c, 0 c, \ =========================================================================== \ Variables \ =========================================================================== wvariable stepA wvariable stepB wvariable stepC \ =========================================================================== \ Main \ =========================================================================== : 1+W! dup W@ 1+ swap W! ; : 1-W! dup W@ 1- swap W! ; \ Output pulse to each phase \ ( -- ) : setPhase stepA W@ phaseState + C@ if phaseA pinhi else phaseA pinlo then stepB W@ phaseState + C@ if phaseB pinhi else phaseB pinlo then stepC W@ phaseState + C@ if phaseC pinhi else phaseC pinlo then ; \ Rotate cw during 3seconds \ ( -- ) : HDDmotor_cw 25msec cnt COG@ + d120 0 do \ phaseA 1 stepA W+! stepA W@ 5 > if 0 stepA W! then \ phaseB 1 stepB W+! stepB W@ 5 > if 0 stepB W! then \ phaseC 1 stepC W+! stepC W@ 5 > if 0 stepC W! then 25msec waitcnt \ Output pulse to each phase setPhase loop drop ; : 1-W! dup W@ 1- swap W! ; \ Rotate ccw during 3seconds \ ( -- ) : HDDmotor_ccw 25msec cnt COG@ + d120 0 do \ phaseA stepA 1-W! stepA W@ hFFFF = if 5 stepA W! then \ phaseB stepB 1-W! stepB W@ hFFFF = if 5 stepB W! then \ phaseC stepC 1-W! stepC W@ hFFFF = if 5 stepC W! then 25msec waitcnt \ Output pulse to each phase setPhase loop drop ; : demo \ Initialize step* 0 stepA W! 2 stepB W! 4 stepC W! \ Set pin to outport phaseA pinout phaseB pinout phaseC pinout HDDmotor_cw HDDmotor_ccw HDDmotor_cw HDDmotor_ccw HDDmotor_cw HDDmotor_ccw ;