COGNEW help
TC
Posts: 1,019
Hello all,
I am making a simple 7-segment display driver. I have a running prototype, but now I want to put the display driver code in a new cog, and just update the buffer array. here is my working prototype code...
Here is an attempt I did to make the driver code be in another cog. (I know the stack is large, it is just a first run)
I know it has to be something simple, but I just cant see it. Does anyone have any ideas?
Thanks
TC
I am making a simple 7-segment display driver. I have a running prototype, but now I want to put the display driver code in a new cog, and just update the buffer array. here is my working prototype code...
CON _clkmode = xtal1 + pll16x _xinfreq = 6_000_000 CON 'PINS DIG0 = 0 DIG1 = 1 DIG2 = 2 DIG3 = 3 DIG4 = 4 DIG5 = 5 DIG6 = 6 DIG7 = 7 SEG_A = 8 SEG_B = 9 SEG_C = 10 SEG_D = 11 SEG_E = 12 SEG_F = 13 SEG_G = 14 DP = 15 CLR = 16 CLK = 17 VAR BYTE BUFF[8] PUB MAIN DIRA[CLR] := %1 OUTA[CLR] := %1 LOAD_BUFFER(0,2) LOAD_BUFFER(1,4) LOAD_BUFFER(2,1) LOAD_BUFFER(3,9) LOAD_BUFFER(4,10) LOAD_BUFFER(5,3) LOAD_BUFFER(6,8) LOAD_BUFFER(7,5) LOAD_DISPLAY PUB LOAD_BUFFER(DIGIT_NUMBER, VALUE) BUFF[DIGIT_NUMBER] := VALUE PUB LOAD_DISPLAY | DIGIT DIRA[CLK] := %1 OUTA[CLK] := %0 DIRA[DIG0..DP] := %11111111_11111111 REPEAT REPEAT DIGIT FROM 0 TO 7 OUTA[DIG0..DIG7] := BYTE[@DIG + DIGIT] OUTA[SEG_A..DP] := BYTE[@CHAR + BUFF[DIGIT]] OUTA[CLK] := %1 OUTA[CLK] := %0 DAT CHAR BYTE %11111100 '0 BYTE %01100000 '1 BYTE %11011010 '2 BYTE %11110010 '3 BYTE %01100110 '4 BYTE %10110110 '5 BYTE %10111110 '6 BYTE %11100000 '7 BYTE %11111110 '8 BYTE %11110110 '9 BYTE %00000000 'BLANK DIG BYTE %10000000 BYTE %01000000 BYTE %00100000 BYTE %00010000 BYTE %00001000 BYTE %00000100 BYTE %00000010 BYTE %00000001
Here is an attempt I did to make the driver code be in another cog. (I know the stack is large, it is just a first run)
CON _clkmode = xtal1 + pll16x _xinfreq = 6_000_000 CON 'PINS DIG0 = 0 DIG1 = 1 DIG2 = 2 DIG3 = 3 DIG4 = 4 DIG5 = 5 DIG6 = 6 DIG7 = 7 SEG_A = 8 SEG_B = 9 SEG_C = 10 SEG_D = 11 SEG_E = 12 SEG_F = 13 SEG_G = 14 DP = 15 CLR = 16 CLK = 17 VAR BYTE BUFF[8] BYTE COG_ID LONG DISPLAY_STACK[100] PUB MAIN DIRA[CLR] := %1 OUTA[CLR] := %1 LOAD_BUFFER(0,2) LOAD_BUFFER(1,4) LOAD_BUFFER(2,1) LOAD_BUFFER(3,9) LOAD_BUFFER(4,10) LOAD_BUFFER(5,3) LOAD_BUFFER(6,8) LOAD_BUFFER(7,5) 'LOAD_DISPLAY COG_ID := COGNEW(LOAD_DISPLAY(@BUFF, @DIG, @CHAR, DIG0, SEG_A, CLK), DISPLAY_STACK) PUB EXTRACT (VALUE) | DIGIT, DIVISOR DIVISOR := 10_000_000 REPEAT DIGIT FROM 7 TO 0 BYTE[BUFF][DIGIT] := VALUE / DIVISOR ' extract digit VALUE //= DIVISOR ' remove digit from value DIVISOR /= 10 ' fix divisor for next digit PUB LOAD_BUFFER(DIGIT_NUMBER, VALUE) BUFF[DIGIT_NUMBER] := VALUE PUB LOAD_DISPLAY(BUFF_ADDR, DIG_ADDR, CHAR_ADDR, DIG_PIN, SEG_PIN, CLK_PIN) | DIGIT DIRA[CLK_PIN] := %1 OUTA[CLK_PIN] := %0 DIRA[DIG_PIN..(DIG_PIN + 16)] := %11111111_11111111 REPEAT REPEAT DIGIT FROM 0 TO 7 OUTA[DIG_PIN..(DIG_PIN + 8)] := BYTE[DIG_ADDR + DIGIT] OUTA[SEG_PIN..(SEG_PIN + 8)] := BYTE[CHAR_ADDR + BUFF_ADDR[DIGIT]] OUTA[CLK_PIN] := %1 OUTA[CLK_PIN] := %0 DAT CHAR BYTE %11111100 '0 BYTE %01100000 '1 BYTE %11011010 '2 BYTE %11110010 '3 BYTE %01100110 '4 BYTE %10110110 '5 BYTE %10111110 '6 BYTE %11100000 '7 BYTE %11111110 '8 BYTE %11110110 '9 BYTE %00000000 'BLANK DIG BYTE %10000000 BYTE %01000000 BYTE %00100000 BYTE %00010000 BYTE %00001000 BYTE %00000100 BYTE %00000010 BYTE %00000001
I know it has to be something simple, but I just cant see it. Does anyone have any ideas?
Thanks
TC
Comments
Egad, man! Do you enter code with caps-lock on? Code is much easier to read with lower/mixed case.
-Phil
Thank you Phil for the reply.
I added @display_stack, and it still does not work.
Sorry about the caps lock thing. I only use it to try out code. I have been known to put caps in places where they should not be, and I get lost looking for a problem. After I have a working idea. I then take my time to lay out the code better.
I am only trying out the caps-lock thing. It has its ups and downs.
Thanks
TC
That did it. Thank you so much. Now to understand what I was missing.