fl { MotorDriver using DRV8830 PropForth5.5 2013/05/18 14:17:05 DRV8830 Propeller scl ---- P28 0x1c sda ---- P29 0x1d out1 ------ Motot+ out2 ------ Motot- Vcc ------ 5V GND ------ GND ISENSE ------ resistor -- GND A0 ------ GND A1 ------ GND FAULT ------ LED -- resitor(220ohm) -- GND |-- Propeller pin(input) 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 Register inside DRV8830 register sub-address name 0 0 CONTROL 1 1 FAULT Register 0 b7-b2:VSET[5..0] : Set DAC output voltage b1 : In1 b0 : In2 Register 1 b7 b6 b5 b4 b3 b2 b1 b0 clear unused unused LIMITS OTS UVLO OCP FAULT } \ First DRV8830's slave address hC0 wconstant 1st_DRV 0 wconstant CONTROL 1 wconstant FAULT 1 wconstant rev 2 wconstant fwd 0 wconstant fault \ Get slave-addr for n \ ( n1 -- n2 ) n1:device's number[from 0 to 8] n1:slave-address : Get_slave 2 u* 1st_DRV + ; \ Write data to DRV8830 \ ( n -- ) n:data : DRV8830_w _eewrite if 8007 ERR then ; \ Read DRV8830 register \ ( n1 n2 -- ) n1:register n2:device's number[from 0 to 8] : drv_rd \ Start data-transfer _eestart \ Send slave_address[wr] Get_slave tuck DRV8830_w \ Send register DRV8830_w \ Send slave_address[rd] _eestart 1+ DRV8830_w \ Read data 0 _eeread \ Stop data-transfer _eestop ; \ Write data to DRV8830 register \ ( n1 n2 n3 -- ) n1:data n2:register n3:device's number[from 0 to 8] : drv_wr \ Start data-transfer _eestart \ Send slave_address[wr] Get_slave DRV8830_w \ Send register DRV8830_w \ Send data DRV8830_w \ Stop data-transfer _eestop ; \ Motor <-- 1.29V ( -- ) : test h42 CONTROL 0 drv_wr ; \ Stop Motor ( -- ) : test1 0 CONTROL 0 drv_wr ; \ Brakeing Motor ( -- ) : test2 3 CONTROL 0 drv_wr ; \ Read FAULT-status ( -- n ) n:fault code : FAULT? FAULT 0 drv_rd hex . decimal ; \ Read CONTROL-setting ( -- ) : CONTROL? CONTROL 0 drv_rd ." VSET DAC H-Bridge" cr dup 2 rshift ." " hex . decimal ." " 3 and 0 over = if ." stanby" else 1 over = if ." reverse" else 2 over = if ." forward" else ." brake" thens drop cr ; \ Display fault if fault occur \ ( -- n ) n:fault code : fault_check ina COG@ 1 fault lshift and if FAULT? then ; \ Clear fault \ ( -- ) : fault_clear h80 FAULT 0 drv_wr \ Motor-voltage is under 3V because this motor is for 3V. : Motr_test \ Rotate up step by step h26 h6 do i 2 lshift fwd or CONTROL 0 drv_wr d100 delms fault_check loop \ Brake \ 3 CONTROL 0 drv_wr \ Stop 0 CONTROL 0 drv_wr \ Rotate up step by step to reverse h26 h6 do i 2 lshift rev or CONTROL 0 drv_wr d100 delms fault_check loop \ Brake \ 3 CONTROL 0 drv_wr \ Stop 0 CONTROL 0 drv_wr ;