fl { POV on QuickStart with Accelerometer(ADXL202) PropForth 5.2 15/10/2012 19:07:38 P1 -- AccelerometerYout P16 -- P23 LEDs ADXL202 connection ------------- |NC VDD|----------------------|---- 3.3V |VTP VDD|----------------------| |ST XFILT|---0.1uf----GND | GND-----------|COM YFILT|---0.1uf----GND 0.1uF GND---1Mohm---|T2 XOUT|------------P0 | |NC YOUT|------------P1 | GND-----------|COM NC| GND ------------- Using only Accel-Y (P1) (P0 not used) T2 is 8msec(by calculatio) T2 is 6.6msec by osciloscope. } hex \ a cog special register [ifndef ctra h1F8 wconstant ctra ] \ a cog special register [ifndef frqa h1FA wconstant frqa ] \ a cog special register [ifndef phsa h1FC wconstant phsa ] 1 wconstant AY \ Accel-Y 10 wconstant _LEDs \ top of LED-array wvariable LED_data 2E allot \ buffer for LED data(5characters) clkfreq A u/ constant dT \ scroll time per dot(row) wvariable char \ character address wvariable odd \ character odd/even wvariable pos \ scan position of font wvariable row_data \ 1 row data variable accel \ previous shake-direction wvariable dir \ shake-direction AY 1 lshift constant AYm wvariable bit_mask \ even character h10 l, h100 l, h400 l, h4000 l, h40000 l, h400000 l, h1000000 l, h10000000 l, \ odd character h20 l, h200 l, h800 l, h8000 l, h80000 l, h800000 l, h2000000 l, h20000000 l, \ ( -- ) output data inside LED_data to LED16-LED23 \ Display 20byte from buffer-top : drive_LED dira COG@ hFF0000 or dira COG! \ set LED16-LED23 to output begin dir W@ 1 = if LED_data h14 + h14 0 do dup i - C@ _LEDs lshift outa COG@ hFF00FFFF and or outa COG! 1 delms outa COG@ hFF00FFFF and outa COG! 1 delms loop else LED_data h14 0 do dup i + C@ _LEDs lshift outa COG@ hFF00FFFF and or outa COG! 1 delms outa COG@ hFF00FFFF and outa COG! 1 delms loop then drop 0 until ; \ ( n1 n2 n3 -- n4) get row-data(1bit) from 1-column-data(32bit) \ n1:column-data n2:character type odd=0 even=1 n3:row number n4:result 0/1 : getRow 4 u* swap if h20 + then bit_mask + 4 + L@ \ get row-data(1bit) and dup 0<> if drop 1 then ; \ Judge right edge whenshaking board \ ( -- ) : check_accel 0 accel L! h20000000 AY or ctra COG! \ Set ctra to POS detector mode 1 frqa COG! begin 0 AYm waitpeq \ Wait until AY is low 0 phsa COG! \ Clear phsa AYm AYm waitpeq \ Wait until AY is high 0 AYm waitpeq \ Wait until AY is low phsa COG@ dup accel L@ > if 1 dir W! \ from left to right else 0 dir W! \ from right to left then accel L! 0 until ; \ Insert 5-character to buffer(48bytes) \ 1-caracter consist of 8row(bit-field) amd 2row(blank) \ ( -- ) : pov c" drive_LED" 0 cogx c" check_accel" 1 cogx h7F94 char W! \ start ROM-top cnt COG@ dT L@ + begin \ main loop char W@ h80 + dup hC000 > if drop h8014 char W! else char W! then 2 0 do \ even/odd character i odd W! hA 0 do \ get row-data for charcter i pos W! i 8 < if 0 \ set initial data 8 0 do \ get column-data i C u* char W@ + L@ swap 1 lshift swap odd W@ pos W@ getRow + loop row_data W! else 0 row_data W! then dT waitcnt \ wait 0.1sec LED_data h2F 0 do dup dup i + 1+ C@ swap i + C! loop \ shift datas from buffer[i+1] to buffer[i] h2F + row_data W@ swap C! \ store new-data to last-buffer loop loop fkey? swap drop until \ Break if any key hit drop 0 cogreset 1 cogreset ; decimal { \ Check accelerometer : test 0 accel W! h20000000 AY or ctra COG! \ Set ctra to POS detector mode 1 frqa COG! begin 0 AYm waitpeq \ Wait until AY is low 0 phsa COG! \ Clear phsa AYm AYm waitpeq \ Wait until AY is high 0 AYm waitpeq \ Wait until AY is low phsa COG@ dup accel L@ > if 1 dir W! \ from left to right else 0 dir W! \ from right to left then dup accel L! d10000 u/ 0 do h2A emit loop dir W@ . cr fkey? swap drop until \ Break if any key hit ; }