{ 20080810 4x8 LED 7Seg CC display driver (board 3) Michael O'Brien michael@fmichael.com automation: propellent /port COM3 _propDisp4x8_1inch_blue_7seg.spin 20080810 : start 20080821 : e: sequence working at <2000 speed f: split 16 bit word into two g: spawn 2 cores for 2x8 bit control word rearrange word so 7seg is on byte0 and grid is on byte1 h: off by 1 crossed wires on 595-0 - fixed loading data preceeds switching multiplexer by eight cycle - causing ghosting solved by saving prev mux state and only switching when rclk is pulsed i: merge 154/138 multiplexing bits - they are the same merge 595 rclk/sclk bits, but move rclk from chip0 to chip1 - in line with mux slight ghosting on grid because it takes its d/rclk/sclk from another chip j: digits displaying correctly, except seg-g on digit 3(blue) for vals 0-on, 2,3-off Ghosting solved by holding previous mux value while loading 595 20081011 : v4: transfered to 7seg blue 1inch 4 digit display board } VAR ' shared mem long Stack0[2048] byte mux154a byte mux154b byte prevmux154a byte prevmux154b byte datD595shift byte tempPartAddress byte segAddress ' Inter processor communication byte tPin long randomNum byte semaphore1 DAT ' next line is a RegularExpression match digitStore byte 1,9,1,6,1,9,3,6 cog long 0 'cog flag/id '7seg CA CC SURE Electronics blue=ca, red=cc ' g f + a b ' 1 2 3 4 5 ' ' -a ' f| |b ' -g ' e| |c ' -d.dp ' ' 10 9 8 7 6 ' e d + c dp ' 'gfab.cde ' 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z - + segDigit byte 0,1,1,1, 0,1,1,1, 0,0,0,1, 0,1,0,0, 1,0,1,1, 0,0,1,1, 1,0,1,1, 0,1,1,0, 1,1,0,1, 0,1,0,0, 1,1,1,0, 0,1,1,0, 1,1,1,0, 0,1,1,1, 0,0,1,1, 0,1,0,0, 1,1,1,1, 0,1,1,1, 1,1,1,1, 0,1,1,0 'OBJ ' fmt: "Format" CON ' non-spin stamp ' _CLKMODE = XTAL1 + PLL16X ' clock speed to high = 12Mhz ' _XINFREQ = 5_000_000 _CLKMODE = XTAL1 + PLL8X ' clock speed to high = 12Mhz _XINFREQ = 10_000_000 ' _delay = 200_000 ' pin assignments _pin595data = 7'2 _pin595sclk = 5'0 _pin595rclk = 6'1 PUB Main repeat tPin from 0 to 15 dira[tPin]~~ outa[tPin]~~' := 1 ' initialize digit store randomNum := 65535 { 8 bit control word latest 0 - d595-a 1 - d595-rclk (4x8 led 7seg) 2 - d595-sclk 3 - 138-a 4 - 138-b 5 - u 6 - u 7 - u } repeat 'cognew(PushDispControlWord(0), @Stack1) PushDispControlWord(0) ' 1x8x16 LED Grid PUB PushDispControlWord(type) prevmux154b := 1 prevmux154a := 1 repeat mux154b from 0 to 1 repeat mux154a from 0 to 1 tempPartAddress := 8 * digitStore[mux154b + mux154b + mux154a] 'gfab.cde repeat datD595shift from 0 to 7 ' reverse the segments for blue led's segAddress := segDigit[tempPartAddress + (7 - datD595shift)] ' place decimal point on 3rd digit if(mux154b < 1) if(mux154a > 0) if(datD595shift > 2) if(datD595shift < 4) segAddress := 1 ' b,a,s,r,d PushRegisterStack(prevmux154b,prevmux154a,0,0,segAddress) PushRegisterStack(prevmux154b,prevmux154a,1,0,segAddress) 'waitcnt(4_100_000 + cnt) waitcnt(9_500 + cnt) ' save last multiplex state before switching ' loading data preceeds switching multiplexer by eight cycle - causing ghosting ' solved by saving prev mux state and only switching when rclk is pulsed PushRegisterStack(mux154b,mux154a,1,1,segAddress) prevmux154b := mux154b prevmux154a := mux154a PUB PushRegisterStack(a,b,s,r,d) ' shift register bits backwards PushRegisterBitOnChip(a) PushRegisterBitOnChip(b) PushRegisterBitOnChip(s) PushRegisterBitOnChip(r) PushRegisterBitOnChip(d) ' load register in 595 outa[_pin595rclk] := 0 ' waitcnt(350_000 + cnt) outa[_pin595rclk] := 1 ' waitcnt(350_000 + cnt) PUB PushRegisterBitOnChip(bit) ' write bit outa[_pin595data] := bit ' waitcnt(350_000 + cnt) ' toggle shift clock outa[_pin595sclk] := 0 ' waitcnt(350_000 + cnt) outa[_pin595sclk] := 1 ' waitcnt(350_000 + cnt)