fl { TLC5940 drivwe PropForth 5.5 2014/05/22 19:54:05 propeller TLC5940 P0 <---- XERR (Error of LOD or TEF) P1 ----> VPRG (SElection for GS mode and DS mode) P2 ----> XLAT (Latch signal of serial data) P3 ----> SIN (Serial data input) P4 ----> SCLK (serial data shift clock) P5 ----> GSCLK (Reference clock for graiscale PWM) P6 ----> BLANK (Teset GS-counter) DCPRG --- 3.3V (Not used eeprom) IREF --- Resister[2k ohm]---GND (19.5mA) } \ =========================================================================== \ Constants \ =========================================================================== 0 wconstant XERR 1 wconstant VPRG 2 wconstant XLAT 3 wconstant SIN 4 wconstant SCLK 5 wconstant GSCLK 6 wconstant BLANK 1 wconstant chip \ Number of TLC5940 d16 chip u* wconstant ch \ 16ch for 1pc of TLC5940 \ =========================================================================== \ Variables \ =========================================================================== variable GS_buffer 2 ch u* 4- allot \ Gray scale buffer(1word for 1ch) variable DC_buffer ch 4- allot \ Dot Correction buffer(1byte for 1ch) \ =========================================================================== \ Main \ =========================================================================== \ Get max ch \ ( -- ) : max_ch ch 1- ; \------------------------- \ Gray Scale \------------------------- \ Set gray-scale to ch \ ( n1 n2 -- ) n1:gray-scale[0-4095] n2:ch[0-n] : gs_set 2 u* GS_buffer + W! ; \ Send gray-scale[12bits] \ ( n1 -- ) n1:address : gs_shift_out ch 0 do dup W@ d20 lshift h80000000 d12 0 do 2dup and 0<> if SIN pinhi else SIN pinlo then SCLK pinhi SCLK pinlo 1 rshift loop 2drop 2+ loop drop ; \ Update gray-scale \ ( -- ) : gs_update \ Select GS register VPRG pinlo GS_buffer gs_shift_out XLAT pinhi XLAT pinlo ; \ Set all ch to same gray-scale \ ( n1 -- ) n1:gray-scale[0-4095] : gs_setAll GS_buffer ch 0 do 2dup \ ( n1 GS_buffer n1 GS_buffer ) W! 2+ \ ( n1 GS_buffer+2 ) loop 2drop gs_update ; \ Clear all ch of gray-scale to 0 \ ( -- ) : gs_allClr 0 gs_setAll gs_update ; \------------------------- \ Dot Correction \------------------------- \ Set dot-correction to ch \ ( n1 n2 -- ) n1:dot-correction[0-63] n2:ch[0-n] : dc_set DC_buffer + C! ; \ Send dot-correction[6bits] \ ( n1 -- ) n1:address : dc_shift_out ch 0 do dup C@ d26 lshift h80000000 6 0 do 2dup and 0<> if SIN pinhi else SIN pinlo then SCLK pinhi SCLK pinlo 1 rshift loop 2drop 1+ loop ; \ Update dot-correction \ ( -- ) : dc_update \ Select DC register VPRG pinhi DC_buffer dc_shift_out XLAT pinhi XLAT pinlo ; \ Set all ch to same dot-correction \ ( n1 -- ) n1:dot-correction[0-63] : dc_setAll DC_buffer ch 0 do 2dup \ ( n1 DC_buffer n1 DC_buffer ) C! 1+ \ ( n1 DC_buffer+1 ) loop 2drop ; \ Clear all ch of dot-correction to 0 \ ( -- ) : dc_Allclr 0 dc_setAll ; \---------------------------- \ GSCLK drive on other cog \---------------------------- \ Drive Grayscale PWM control \ ( n1 n2 -- ) n1:BLANK n2:GSCLK lockdict create a_gsclk_drive forthentry $C_a_lxasm w, h124 h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z2WyxW0 l, z2WyPW1 l, zfiPZB l, z1bixmC l, z1SyLI[ l, z2WyPb1 l, zfiPeB l, z1bixmD l, z1SyLI[ l, z2WiPnZ l, z2WixZC l, z2WyxW0 l, z3[yPnT l, z2WixZD l, z2WyxW0 l, z1SV04S l, zyy l, freedict \ Initialize TLC5940 \ ( -- ) : init_TLC5940 \ Initialize port VPRG 4 0 do dup pinlo dup pinout 1+ loop drop \ Clear gray-scale for all ch gs_allClr \ Start GS drive c" BLANK GSCLK a_gsclk_drive" 0 cogx ; \ Change PWM-level of each LED-element(LED-bar) { out1---|/|____3.3V |\| out2---|/|____3.3V |\| ... ... ... out15--|/|____3.3V |\| } : demo1 init_TLC5940 0 begin d16 0 do dup i gs_set dup 0= if drop 1 else dup h800 = if drop hFFF else dup hFFF = if drop 0 else 1 lshift thens loop gs_update d100 delms fkey? swap drop until drop gs_allClr \ d100 delms 0 cogreset ; { \ $C_treg1:GSCLK \ $C_treg2:BLANK \ ( n1 n2 -- ) n1:BLANK n2:GSCLK fl build_BootOpt :rasm mov outa , # 0 \ Set GSCLK to output mov $C_treg1 , # 1 shl $C_treg1 , $C_stTOS or dira , $C_treg1 spop \ Set BLANK to output mov $C_treg2 , # 1 shl $C_treg2 , $C_stTOS or dira , $C_treg2 spop __1 mov $C_treg3 , __count __2 mov outa , $C_treg1 mov outa , # 0 djnz $C_treg3 , # __2 mov outa , $C_treg2 mov outa , # 0 jmp # __1 __count d4095 ;asm a_gsclk_drive }