fl { PropForth 5.5 2015/07/16 22:14:56 P0 ----- 220ohm -- SinglePhaseSteppMotor Coil -- P1 } \ =========================================================================== \ Constants \ =========================================================================== 0 wconstant out1 1 wconstant out2 clkfreq constant 1second \ unit 100usec d220 wconstant cw_pulse \ 22msec d65 wconstant ccw_pulse1 \ 65msec d140 wconstant ccw_pulse2 \ 140msec d9000 wconstant max_delay \ 900msec d700 wconstant min_delay \ 70msec \ =========================================================================== \ Variables \ =========================================================================== wvariable sec variable flag variable current \ current second-needle's position variable prev \ previous second-needle's position wvariable delay_time \ =========================================================================== \ Main \ =========================================================================== lockdict create a_delay100us forthentry $C_a_lxasm w, h11C h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z1SyZKN l, z3[yPSJ l, z1SyLI[ l, z1SV01X l, z2WiP[R l, z20iPak l, z3ryPW0 l, z1SV000 l, z1vi l, freedict \ Counting seconds \ ( -- ) : second 0 sec W! clkfreq cnt COG@ + begin clkfreq waitcnt sec W@ 1+ dup d60 = if drop 0 then sec W! 0 until ; \ Initial setting \ ( -- ) : init out1 pinout out2 pinout -1 flag L! ; \ Check flag \ ( -- n1 ) n1:-1 or 0 : check flag L@ invert dup flag L! ; \ Rotate to cw \ ( -- ) : cw check if out1 pinhi cw_pulse a_delay100us out1 pinlo else out2 pinhi cw_pulse a_delay100us out2 pinlo then ; \ Rotate to ccw \ ( n1 -- ) n1:delay time[msec] : ccw check if out1 pinhi ccw_pulse1 a_delay100us out1 pinlo out2 pinhi ccw_pulse2 a_delay100us out2 pinlo else out2 pinhi ccw_pulse1 a_delay100us out2 pinlo out1 pinhi ccw_pulse2 a_delay100us out1 pinlo then ; \ Drive SinglePhaseStepMotor \ ( n1 -- ) n1:pulse count : StepMotor \ Check if minus dup 0< if invert 1+ 0 else 1 then if \ cw 0 do cw delay_time W@ a_delay100us loop else \ ccw 0 do ccw delay_time W@ a_delay100us loop then ; \ Second-needle stop/cw/ccw 10sec by 10sec. \ ( -- ) : demo init 0 current L! 0 prev L! c" second" 0 cogx d100 delms 0 \ initial real second begin \ Wait until it pass 1second begin sec W@ over <> until 1+ dup d60 = if drop 0 min_delay delay_time W! d60 prev L@ - StepMotor 0 current L! else dup d10 u/mod drop 0= if rnd d25 / \ 0 to 10 5 - \ -5 to 5 dup current L@ + current L! dup 0= if \ clock stop drop else drop \ Select speed min_delay delay_time W! current L@ prev L@ - StepMotor then else \ Save real second to current 1 current L@ + current L! \ Move StepMotor to cw direction cw then then current L@ prev L! \ Update prev fkey? swap drop until drop 0 cogreset ; { \ Delay word for unit 100usec \ ( n1 -- ) Delay time = n1 x 100usec \ $C_stTOS:n1 \ $C_treg1: fl build_BootOpt :rasm __1 jmpret __100usret , # __100us djnz $C_stTOS , # __1 spop jexit __100us mov $C_treg1 , __100usec add $C_treg1 , cnt waitcnt $C_treg1 , # 0 __100usret ret \ 5+(7996-18)=7983 __100usec d7983 ;asm a_delay100us }