fl { FORO Ram Mapping 16X8 LED Controller Driver with keyscan(HT16K33-24) MotorDriver using DRV8830 Using i2c_utility_0.4_1.f PropForth 5.5(DevKernel) 2018/09/02 22:01:18 DRV8830 Propeller scl ---- P28 sda ---- P29 ( Need pull-up resister[10ohm] to 3.3V at SCL/SDA on DRV8830) out1 ------ Motot+ out2 ------ Motot- Vcc ------ 5V(MotorPoer & Logic) GND ------ GND ISENSE ------ resistor -- GND A0 ------ GND A1 ------ GND FAULT ------ LED -- resitor(220ohm) -- 5V DRV8830 (Connectable max 9 devices on same I2C line.) Slave address A1 A0 addr[wr] addr[rd] 0 0 hC0 hC1 0 open hC2 hC3 0 1 hC4 hC5 open 0 hC6 hC7 open open hC8 hC9 open 1 hCA hCB 1 0 hCC hCD 1 open hCE hCF 1 1 hD0 hD1 Propeller---LevelShift-------------------------------------------i2c-line 3.3V->Battery | | | DRV8830 DRV8830 HT16K33 |SV:h63 |SV:h64 |SV:h70 Forward/Back Rotate 8x8MatrixLED Motor Motor | | | | -------------------------------Battery(AAx4pcs:6V) IR sensor(GP1UXC41QS) Propeller P0-----Vout GND Vcc -----3.3V } : FOLO ; \ =========================================================================== \ Constants \ =========================================================================== \ ---- HT16K33-24 ---- \ Slave addres h70 for HT16K33-24 hE0 wconstant HT16K33 \ command 0 wconstant addrPtr h20 wconstant sysSetup h80 wconstant Blink hE0 wconstant Brightness \ bit data 1 wconstant oscOn 1 wconstant dispOn \ ---- DRV8830 ---- hC6 wconstant rotMot \ [h63] A0=GND A1=open hC8 wconstant movMot \ [h64] A0=A1=open \ Register 0 wconstant CONTROL 1 wconstant FAULT \ Value inside CONTROL register 1 wconstant rev \ IN2=0 IN1=1 2 wconstant fwd \ IN2=1 IN1=0 \ Value inside FAULT register 0 wconstant fault \ --- IR sensor(GP1UXC41QS) ---- 0 wconstant IRsensor IRsensor >m constant mIRsensor d8000000 constant 100ms d800000 constant 10ms \ LeaderCode for NEC format d674400 constant NEC15T d764320 constant NEC17T d314720 constant NEC7T d404640 constant NEC9T d89920 constant NEC2T h1F8 wconstant ctra h1F9 wconstant ctrb h1FA wconstant frqa h1FB wconstant frqb h1FC wconstant phsa h1FD wconstant phsb \ =========================================================================== \ 8X8 Font Characters \ =========================================================================== wvariable Font -2 allot h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, h00 c, h0C c, h1E c, h1E c, h0C c, h00 c, h00 c, h00 c, h00 c, h06 c, h0F c, h0F c, h06 c, h00 c, h00 c, h00 c, h00 c, h06 c, h0F c, h0F c, h06 c, h00 c, h00 c, h00 c, h00 c, h0C c, h1E c, h1E c, h0C c, h00 c, h00 c, h00 c, h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, h00 c, h30 c, h78 c, h78 c, h30 c, h00 c, h00 c, h00 c, h00 c, h60 c, hF0 c, hF0 c, h60 c, h00 c, h00 c, h00 c, h00 c, h60 c, hF0 c, hF0 c, h60 c, h00 c, h00 c, h00 c, h00 c, h30 c, h78 c, h78 c, h30 c, h00 c, h00 c, h00 c, h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, h00 c, h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, h00 c, h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, h00 c, h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, h18 c, h3C c, h3C c, h18 c, h00 c, h00 c, h00 c, \ =========================================================================== \ Variables \ =========================================================================== \ --- IR sensor ---- variable irVar 8 allot wvariable rptL wvariable rptR wvariable inputCode wvariable waitingKey wvariable backF \ =========================================================================== \ HT16K33 \ =========================================================================== \ Write command to HT16K33 \ ( n1 n2 -- ) n1:command n2:slave_address : wrCom1 \ Start I2C _eestart \ Write slave address[wr], then receive Acknowledge-bit(ACK:Lo NACK:Hi) _eewrite \ ( n1 t/f ) \ Write command swap _eewrite or \ ( t/f ) \ Stop I2C _eestop err? \ ( -- ) ; \ Write command and data to HT16K33 \ ( n1 n2 n3 -- ) n1:data n2:command n3:slave_address : wrCom2 \ Start I2C _eestart \ Write slave address[wr], then receive Acknowledge-bit(ACK:Lo NACK:Hi) _eewrite \ ( n1 n2 t/f ) \ Write command swap _eewrite or \ ( n1 t/f ) \ Write data swap _eewrite or \ ( t/f ) \ Stop I2C _eestop err? \ ( -- ) ; \ Initialize HT16K33 \ ( -- ) : init_HT16K33 sysSetup oscOn or HT16K33 wrCom1 \ Set systemOscillator to on Blink HT16K33 wrCom1 \ Set Blink to off Brightness 1 or HT16K33 wrCom1 \ Set Brightness to 1 \ RAM ckear 8 0 do 0 addrPtr i 2* + HT16K33 wrCom2 loop h81 HT16K33 wrCom1 \ Display on ; \ Display 1character-font \ ( n1 -- ) n1:font code[0,1,2,3,4,5,6,7,8] : charSet 8 * Font + \ Top address of character 8 0 do dup C@ addrPtr i 2* + HT16K33 wrCom2 1+ loop drop ; \ case \ ( n1 n2 -- n1 n3 ) n1:number1 n2:number2 n3:true if n1=n2 : case over = ; \ Move eye \ ( n1 -- ) dirction \ 0:from center to right 1:from left to center \ 2:from center to left 3:from left to center \ 4:from center to up 5:from up to center : dir 0 case if 3 0 else 1 case if 6 3 else 2 case if 9 6 else 3 case if d12 9 else 4 case if d16 d12 else d20 d16 thens rot drop do i charSet d100 delms loop ; \ =========================================================================== \ DRV8830 \ =========================================================================== : i2c_wr \ Start I2C _eestart \ Write slave address[wr], then receive Acknowledge-bit(ACK:Lo NACK:Hi) _eewrite \ ( n1 n2 t/f ) \ Write register swap _eewrite or \ ( n1 t/f ) \ Write data swap _eewrite or \ ( t/f ) \ Stop I2C _eestop \ err? \ ( -- ) if err_msg cr ." matrix" then ; \ Clear fault \ ( n1 -- ) n1:slave addr : fault_clr h80 \ data FAULT \ register rot i2c_wr ; \ Set status to standby \ ( n1 -- ) n1:slave addr : set_standby 0 \ data CONTROL \ register rot i2c_wr ; \ Stop Motor \ ( n1 -- ) n1:slave addr : stop 0 \ data CONTROL \ register rot i2c_wr ; \ Braking Motor \ ( n1 -- ) n1:slave addr : Brake 3 \ data CONTROL \ register rot i2c_wr ; \ Move foward \ ( -- ) : Foward h26 2 lshift fwd or CONTROL movMot i2c_wr ; \ Mov back \ ( -- ) : Back h26 2 lshift rev or CONTROL movMot i2c_wr ; \ Mov left \ ( -- ) : Left h26 2 lshift fwd or CONTROL rotMot i2c_wr ; \ Mov right \ ( -- ) : Right h26 2 lshift rev or CONTROL rotMot i2c_wr ; \ =========================================================================== \ IR sensor(GP1UXC41QS) \ =========================================================================== \ Wait until IRsensor goes to Hi \ ( -- ) : waitUntilHi mIRsensor mIRsensor waitpeq ; \ Wait until IRsensor goes to Lo \ ( -- ) : waitUntilLo mIRsensor mIRsensor waitpne ; \ Save pulse-count in buffer \ ( -- n1 ) n1:last address+4 for saved pulse count(phsa/phsb) : pulseCount here W@ alignl 4- \ Keep Hi-state during 10ms cnt COG@ begin ina COG@ mIRsensor and if cnt COG@ over - 10ms > if drop 1 else 0 then else drop cnt COG@ 0 then until 0 phsa COG! waitUntilLo begin 0 phsb COG! waitUntilHi 4+ \ ( buffer_addr+4 ) phsa COG@ over L! \ Get Lo-part 0 phsa COG! \ Check ending of IR-signal begin ina COG@ mIRsensor and if phsb COG@ 10ms > if 1 1 else 0 then else 0 1 then until swap \ ( 0/1 buffer_addr ) 4+ \ ( 0/1 buffer_addr+4 ) phsb COG@ over L! \ Get Hi-part swap \ ( buffer_addr+4 0/1 ) until ; \ Check IR-format \ ( -- ) : irCheck 0 waitingKey W! pulseCount \ ( last_address ) 1 waitingKey W! here W@ alignl 4+ L@ here W@ alignl L@ dup \ ( last_address LeaderCode(Hi) LeaderCode(Lo) LeaderCode(Lo) ) NEC15T NEC17T between \ ( last_address LeaderCode(Hi) LeaderCode(Lo) 1/0 ) if \ ." NEC format" cr drop NEC7T NEC9T between \ ( last_address 1/0 ) if 0 swap \ ( 0 last_address ) here W@ alignl - d12 - 4 - here W@ alignl d12 + swap bounds do 1 rshift i L@ NEC2T > if h80000000 or then 8 +loop \ b7........b0 b7.b0 b15......b0 \ invertedData Data CustomCode d16 rshift hFF and \ Key code else drop hFF \ RepeatCode then else 3drop 0 \ error then inputCode W! \ Save key-code ; \ Analyze NEC-format \ ( -- ) : irAnalyze hex 1 frqa COG! h54000000 IRsensor or ctra COG! 1 frqb COG! h68000000 IRsensor or ctrb COG! begin irCheck 0 until ; \ Wait releasing key \ ( -- ) : releasKey cnt COG@ begin ina COG@ mIRsensor and if cnt COG@ over - 100ms > if 1 else 0 then else drop cnt COG@ 0 then until drop ; \ Foward and Back continue to move when pusshing key only one time and stop when pusshing stop-key \ Left and Right move only when pussing key \ ( -- ) : folo init_HT16K33 0 charSet c" irAnalyze" 1 cogx begin waitingKey W@ if inputCode W@ h1C case if \ Stop 0 charSet movMot Brake rotMot Brake 0 backF W! else 8 case if \ Left 2 dir rotMot Brake backF W@ if Right else Left then releasKey rotMot Brake 3 dir backF W@ if 4 dir then else h5A case if \ Right 0 dir rotMot Brake backF W@ if Left else Right then releasKey rotMot Brake 1 dir backF W@ if 4 dir then else h18 case if \ Back 4 dir backF W@ 0= if movMot Brake Back 1 backF W! then else h52 case if \ Foward backF W@ if 5 dir 0 backF W! then movMot Brake Foward then then then then then drop then \ fkey? swap drop 0 until 1 cogreset ; \ Boot after Power-on : onreset5 onreset folo ;