fl { POV_II PropForth5.5 2013/06/20 13:54:19 Serial-pararel-conversion by using shift-register(74HC595 2pcs) P0 -- Shift Clock P1 -- Data P2 -- Latch Clock PWM P3 -- Inverter -- MOSFET -- Motor LED-drum sensor P4 -- photo-sensor output } \ Send 16bits to shift-register \ ( n1 n2 n3 n4 -- ) n1:16bit-data n2:_lc n3:_data n4: _sc lockdict create a_shift_out forthentry $C_a_lxasm w, h12D h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z2WyPW1 l, zfiPZB l, z1SyLI[ l, z2WyPb1 l, zfiPeB l, z1SyLI[ l, z2WyPj1 l, zfiPmB l, z1SyLI[ l, zfyPOG l, z2WyPrG l, zgyPO1 l, z1jixZD l, z1bixZC l, z2WiQ7k l, z20yQ0S l, z3ryQ00 l, z1[ixZC l, z3[yPvU l, z1bixZE l, z2WiQ7k l, z20yQ0S l, z3ryQ00 l, z1[ixZE l, z1SyLI[ l, z1SV01X l, freedict \ a cog special register [ifndef ctra h1F8 wconstant ctra ] \ a cog special register [ifndef ctrb h1F9 wconstant ctrb ] \ a cog special register [ifndef frqa h1FA wconstant frqa ] \ a cog special register [ifndef frqb h1FB wconstant frqb ] \ a cog special register [ifndef phsa h1FC wconstant phsa ] \ a cog special register [ifndef phsb h1FD wconstant phsb ] \ waitcnt ( n1 n2 -- n1 ) \ wait until n1, add n2 to n1 [ifndef waitcnt : waitcnt _xasm2>1 h1F1 _cnip ; ] \ ---------------- Constant ------------------------------------------------------------ \ Ports 0 wconstant _sc 1 wconstant _data 2 wconstant _lc 3 wconstant _pwm 4 wconstant _sense d800000 constant 10msec d80000 constant 1msec d8000 constant 100usec d80 wconstant 1usec d70 wconstant max_pwm \ ---------------- Variables ----------------------------------------------------------- \ Duty ratio for Motor variable duty \ Time that drum takes for 1-rotation variable rotTime \ ---------------- PWM ----------------------------------------------------------------- \ Convert duty to ticks \ ( n1 -- ) n1:duty ratio : setDuty max_pwm min 0 max 100usec u* duty L! ; \ Output Hi-pulse to pwm-port(100Hz) : pwm duty L@ _pwm pinout \ Set port to output 1 frqa COG! 0 phsa COG! cnt COG@ 10msec + \ cnt + 10msec swap \ ( cnt ticks -- ) _pwm h10000000 or ctra COG! \ PWM/NCO mode on servo pin begin negate phsa COG! \ Set value to phsa 10msec waitcnt \ cnt + 10msec duty L@ \ ( cnt ticks -- ) 0 until ; \ ---------------- Measurement for disk's rotate-speed ----------------------------------------- \ Get state of _sense \ ( -- n1 ) n1:t/f : senseState 1 _sense lshift ina COG@ and ; \ Time for 1-rotation \ ( -- n1 ) n1:Time for 1-rotation (ticks) : rot_T 1 frqa COG! 1 frqb COG! h20000000 _sense or ctra COG! \ POS detector h30000000 _sense or ctrb COG! \ NEG detector \ Wait until _sense become high begin _sense 1 lshift ina COG@ and until \ Clear phsb (low-pulse counter) 0 phsb COG! begin \ Wait until _sense become low begin senseState 0= until phsa COG@ \ Read hi-pulse ticks 0 phsa COG! \ Clear phsa (Hi-pulse counter) \ Wait until _sense become hi begin senseState until phsb COG@ \ Read lo-pulse ticks 0 phsb COG! \ Clear phsa (low-pulse counter) + 1msec u/ . ." msec" cr fkey? swap drop until ; \ ---------------- LEDs ----------------------------------------------------------------\ Set LED-port to output \ ( -- ) : led_set_up _sc 3 0 do dup pinout 1+ loop drop ; \ Off all LEDs \ ( -- ) : leds_off 0 _lc _data _sc a_shift_out ; \ Output character { address column row n b31 b30 b29 . . . b1 b0 | n+4 0 0 0 0 0 | . | . \|/ n+d124 0 0 0 0 0 } variable row_line variable odd \ ( n -- ) n:character code : char_out_1 dup 1 and if 2 else 1 then odd L! \ Check even/odd hFE and d64 u* h8000 + \ Get ROM Font address d28 + \ Skip 7-line(7 Long) \ column=d16 d16 0 do dup d23 0 do i 2 <> if i 7 <> if i 9 <> if i d11 <> if i d13 <> if i d18 <> if i d20 <> if \ Skip lines row_line L@ 1 lshift row_line L! dup L@ odd L@ 2dup and if row_line L@ 1 or row_line L! then 2drop thens 4 + \ Add +4 to address loop drop \ Set LEDs row_line W@ _lc _data _sc a_shift_out 1 delms leds_off \ Move 1mm \ Motor { \ Print 16bit-data to terminal row_line L@ 1 d16 0 do 2dup and if h2A else bl then emit 1 lshift loop 2drop cr } odd L@ 2 lshift odd L! \ next colummn bit loop drop ; \ Display "E" on drum \ ( -- ) : test1 led_set_up leds_off \ Setup pwm 40 setDuty c" pwm" 0 cogx 5000 delms 27 setDuty begin 1 _sense lshift dup waitpne \ Wait until _sense= Low h45 char_out_1 fkey? swap drop until 0 setDuty ; \ HardWare test of LED-board \ ( -- ) : a_shift_test1 led_set_up leds_off 1 d16 0 do st? dup _lc _data _sc a_shift_out 1 lshift d100 delms loop drop leds_off ; { \ Send 16bits to shift-register \ ( n1 n2 n3 n4 -- ) n1:16bit-data n2:_lc n3:_data n4: _sc \ $C_treg1 -- _scm \ $C_treg2 -- _datam \ $C_treg3 -- _lcm \ $C_treg4 -- loop counter \ $C_treg5 -- wait loop counter fl build_BootOpt :rasm \ get _scm mov $C_treg1 , # 1 shl $C_treg1 , $C_stTOS spop \ get _datam mov $C_treg2 , # 1 shl $C_treg2 , $C_stTOS spop \ get _lcm mov $C_treg3 , # 1 shl $C_treg3 , $C_stTOS spop \ shift 16bit-data to left shl $C_stTOS , # d16 \ set loop-count mov $C_treg4 , # d16 __1 shl $C_stTOS , # 1 wc \ set _data to Hi/Lo muxc outa , $C_treg2 \ clock pulse Hi:500nsec Lo:200nsec or outa , $C_treg1 mov $C_treg5 , cnt add $C_treg5 , # d28 waitcnt $C_treg5 , # 0 \ set _scm to Lo andn outa , $C_treg1 djnz $C_treg4 , # __1 \ set _lc to Hi or outa , $C_treg3 \ wait mov $C_treg5 , cnt add $C_treg5 , # d28 waitcnt $C_treg5 , # 0 \ set _lc to lo andn outa , $C_treg3 spop jexit ;asm a_shift_out }