I'm having trouble in a new cog.
I'm having trouble starting a new cog and having the code execute as I expect it. I'm driving 2 8x8 led arrays and basically making a countdown timer. It's choppy when the digit spans 2 displays. This is what works. Be gentle as this is my first real attempt at spin other than blinking LED's
I thought this would work but it didn't. basically same code but I thought I'd start a new cog and have it constantly run. I'd flag when that particular display needed refreshing and it would happen. Unfortunately, it doesn't.
Comments?
Best regards,
Fred
CON
_CLKMODE=XTAL1+ PLL2X 'The system clock spec
_XINFREQ = 40_000_000 'crystal spec
BLUE = %00000011
GREEN = %00011100
RED = %11100000
_cs0 = 0
_clk0 = _cs0 +1
_mosi0 = _cs0 +2
_cs1 = 3
_clk1 = _cs1 + 1
_mosi1 = _cs1 + 2
_frame_size = 128
display = 32
black = 0
white = blue | green | red
background = black
foreground = red
VAR
byte array[_frame_size]
byte idx
byte bit
byte time
byte minute
byte offset1
byte offset2
byte offset3
byte mask
byte tens
byte sec
long digit
long stack1[25]
long stack2[25]
long stack3[25]
long stack4[25]
byte ck, mo
PUB Go
DIRA[_cs0]~~
DIRA[_cs1]~~ 'osc once to set up 3202
DIRA[_mosi0]~~ 'data set up to the chip
DIRA[_mosi1]~~ 'oscillates to read in data from internals
dira[_clk0]~~
dira[_clk1]~~
outa[_cs0]~
outa[_cs1]~
outa[_cs0]~~
outa[_cs1]~~
cognew(send_frame_0, @stack1)
cognew(send_frame_1, @stack2)
bytefill(@array, foreground, _frame_size)
send_frame_0
pause(1)
send_frame_1
pause(1)
bytefill(@array, background, _frame_size)
send_frame_0
pause(1)
send_frame_1
pause(1)
'idx :=0
show_digits
pub show_digits
array[byte[@colon]] := foreground
array[byte[@colon+1]] := foreground
send_frame_0
repeat minute from 3 to 0
digit := long[@number][minute]
repeat offset3 from 0 to 31
mask~
mask := >| digit
case mask
32:
array[byte[@digit_address_1+offset3]] := foreground
other:
array[byte[@digit_address_1+offset3]] := background
digit <<= 1
send_frame_0
repeat tens from 5 to 0
digit := long[@number][tens]
repeat offset1 from 0 to 31
mask~
mask := >| digit
case mask
32:
array[byte[@digit_address_2+offset1]] := foreground
other:
array[byte[@digit_address_2+offset1]] := background
digit <<= 1
send_frame_0
send_frame_1
repeat sec from 9 to 0
digit := long[@number][sec]
repeat offset2 from 0 to 31
mask~
mask := >| digit
case mask
32:
array[byte[@digit_address_3+offset2]] := foreground
other:
array[byte[@digit_address_3+offset2]] := background
digit <<= 1
send_frame_1
pub send_frame_0
outa[_cs0]~
repeat bit from 0 to (_frame_size / 2)
SPI_byte_0(array[bit])
outa[_cs0]~~
pub send_frame_1
outa[_cs1]~
repeat bit from (_frame_size / 2) to _frame_size
SPI_byte_1(array[bit])
outa[_cs1]~~
pub SPI_byte_0(char)
outa[_clk0]~
outa[_mosi0] := (char.byte[0] & %10000000) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (char.byte[0] & %01000000) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (char.byte[0] & %00100000) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (char.byte[0] & %00010000) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (char.byte[0] & %00001000) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (char.byte[0] & %00000100) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (char.byte[0] & %00000010) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (char.byte[0] & %00000001) <# 1
outa[_clk0]~~
pub SPI_byte_1(char)
outa[_clk1]~
outa[_mosi1] := (char.byte[0] & %10000000) <# 1
outa[_clk1]~~
outa[_clk1]~
outa[_mosi1] := (char.byte[0] & %01000000) <# 1
outa[_clk1]~~
outa[_clk1]~
outa[_mosi1] := (char.byte[0] & %00100000) <# 1
outa[_clk1]~~
outa[_clk1]~
outa[_mosi1] := (char.byte[0] & %00010000) <# 1
outa[_clk1]~~
outa[_clk1]~
outa[_mosi1] := (char.byte[0] & %00001000) <# 1
outa[_clk1]~~
outa[_clk1]~
outa[_mosi1] := (char.byte[0] & %00000100) <# 1
outa[_clk1]~~
outa[_clk1]~
outa[_mosi1] := (char.byte[0] & %00000010) <# 1
outa[_clk1]~~
outa[_clk1]~
outa[_mosi1] := (char.byte[0] & %00000001) <# 1
outa[_clk1]~~
pub pause(ms)
waitcnt((clkfreq/1000)*ms + cnt)
dat
number
zero long %00000110100110011001100110010110
one long %00000010011000100010001000100111
two long %00001111000100011111100010001111
three long %00001111000100011111000100011111
four long %00001001100110011111000100010001
five long %00001111100010001111000100011111
six long %00000010010010001111100110011111
seven long %00001111000100100100010001000100
eight long %00000110100110010110100110010110
nine long %00001111100110011111000100010001
frame_dat
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
byte $00,$00,$00,$00,$00,$00,$00,$00
digit_address_1
byte 0,8,16,24,1,9,17,25,2,10,18,26,3,11,19,27,4,12,20,28,5,13,21,29,6,14,22,30,7,15,23,31
digit_address_2
byte 56,64,72,80,57,65,73,81,58,66,74,82,59,67,75,83,60,68,76,84,61,69,77,85,62,70,78,86,63,71,79,87
digit_address_3
byte 96,104,112,120,97,105,113,121,98,106,114,122,99,107,115,123,100,108,116,124,101,109,117,125,102,110,118,126,103,111,119,127
colon
byte 42,46
I thought this would work but it didn't. basically same code but I thought I'd start a new cog and have it constantly run. I'd flag when that particular display needed refreshing and it would happen. Unfortunately, it doesn't.
pub send_frame_0
repeat
if display0 == true
outa[_cs0]~
repeat bit from 0 to (_frame_size / 2)-1
outa[_clk0]~
outa[_mosi0] := (array[bit] & %10000000) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (array[bit] & %01000000) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (array[bit] & %00100000) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (array[bit] & %00010000) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (array[bit] & %00001000) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (array[bit] & %00000100) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (array[bit] & %00000010) <# 1
outa[_clk0]~~
outa[_clk0]~
outa[_mosi0] := (array[bit] & %00000001) <# 1
outa[_clk0]~~
outa[_cs0]~~
display0 := 0
This is started as in the first code example.Comments?
Best regards,
Fred

Comments
Initialize the appropriate bits of the DIRA register during the initialization of the cog methods (send_frame_0 and send_frame_1).
I'm not sure what kind of problems show up with too high an input frequency.
Jim