fl { PropForth 5.5 2015/07/14 10:33:54 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 wvariable current \ current second-needle's position wvariable 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 ; \ Stopping second_needle during 20seconds \ ( -- ) : demo init 0 current W! 0 prev W! 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 then sec W@ d21 d40 between if { \ d21 <= sec W@ <= d40 rnd 8 / \ 0 to d31 d15 - \ -15 to d16 dup current W+! st? \ Set delay_time dup 0= if \ clock stop drop else \ Select speed[56.25msec - 900msec] max_delay swap / delay_time W! current W@ prev W@ - StepMotor then } else \ sec is less than d21 , sec is more than d40 dup current W! \ Save real second to current \ Set delay_time[1sec] \ Move StepMotor to cw direction current W@ prev W@ - dup 1 > if \ Move second-needle at speed 50msec when moving is more than 1 0 do cw d500 a_delay100us loop else \ Move 1 second, No moving when 0 0 <> if cw then then then current W@ prev W! \ 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 }