Shop OBEX P1 Docs P2 Docs Learn Events
SX/B 2.00.07 array issue ? - (4) 74HC595 use of SHIFTOUT with 32 LEDs - Sequenc — Parallax Forums

SX/B 2.00.07 array issue ? - (4) 74HC595 use of SHIFTOUT with 32 LEDs - Sequenc

T&E EngineerT&E Engineer Posts: 1,396
edited 2009-02-01 21:23 in General Discussion
I have written a LED sequencer program with 32 LEDs and (4) 74HC595's. See attached schematic and code. The schematic reflects using 12v LEDs and ULN2803s so disreguard that for the moment (but I don't think it matters anyway for my issue).

In the code below (and attached), pay attention to the·array declaration·'pattern··VAR·Byte(LED_COUNT)' which was set to 32 by the CONstant LED_COUNT.·All was working well until I·worked·on expanding the number of DATA statements which seemed to be limited to 28 until·strange LED displays started happening afterwards. So I limited it to 28 and it worked out well for Chaser4 and Chaser5 - DATA statements anyway. But then I noticed that LED_COUNT was set to 32 and for use in the DATLONG routine it should have been set to 28 * 4 which is 112 (not the original 32). So I·set the·CONstant LED_COUNT_LONG·to 112. This is when I got a·VARIABLE EXCEED AVAILABLE RAM error. I can change LED_COUNT_LONG down to as low as 103 without gettting the error but that doesn't really answer the issue.

Here is the question.

Why was the DATLONG routine able to function correctly at all knowing that pattern(idx) was being addressed well above the LED_COUNT value of 32. Values between 0 and 111 was being inserted into pattern(idx)? The program runs well but just doesn't make sense since I beleive pattern(idx) would need to be set to 112 (LED_COUNT_LONG) not 32 (LED_COUNT) for it to work at all.

I am using the new Public Beta version of SX/B 2.00.07.

' =========================================================================
'
'   File...... 74HC595_3_Test.SXB
'   Purpose... Expanding the SX outputs with multiple 74HC595's
'   Author.... Timothy Gilmore
'   E-mail.... [url=mailto:Gilmoret@us.saic.com]Gilmoret@us.saic.com[/url]
'   Started... 28 JAN 2009
'   Updated... 31 JAN 2009
'
' =========================================================================

' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
' Cascade (4) 74HC595's together for use with 32 LEDs
' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------
DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ            4_000_000

' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------

Clock  VAR RA.0   ' shift clock
DataIn  VAR RA.1   ' shift data in
Strobe  VAR RA.2   ' strobe outputs
' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------
DelayTime CON 500
DelayTimeHalf CON DelayTime / 2
DelayTimeQtr CON DelayTime / 4
DelayTimeFifth CON DelayTime / 5
DelayTimeTenth CON DelayTime / 10
 
LED_COUNT  CON 32 'Total number of LEDs used

LED_COUNT_MIN1  CON 31 'LEDs - 1
LED_COUNT_DIV8  CON 4 'LEDs / 8
[b]LED_COUNT_LONG  CON 112 '28 sets of 4 DATA statements = 112
LED_COUNT_LONG_MIN1  CON 111 'LED sets - 1[/b]

' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------
 
pattern  VAR Byte(LED_COUNT)             ' pattern  for LEDs - [b]This works - but why?
'pattern  VAR Byte(LED_COUNT_LONG)[/b]  ' ????? Causes [b]VARIABLE EXCEED AVAILABLE RAM[/b] error
 
idx  VAR Byte
idx2  VAR Byte
temp1  VAR Byte  ' subroutine work vars
tmpW1  VAR Word  ' subroutine work vars
' =========================================================================
  PROGRAM Start
' =========================================================================

' -------------------------------------------------------------------------
' Subroutine Declarations
' -------------------------------------------------------------------------
DATPAT  SUB 2
DATLONG  SUB 2
FORWARD_1 SUB 0
BACKWARD_1 SUB 0
OUT       SUB 0                ' move value to A6821s
CLEARALL SUB 0
' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------
Start:
  PLP_A = %0111            ' pull-up unused pins
  PLP_B = %00000000
  PLP_C = %00000000
  RA = %0000
  TRIS_A = %1000

Main:
FORWARD_1
BACKWARD_1
DATPAT Chaser2
DATPAT Chaser1
DATPAT Chaser3
DATPAT Chaser3
DATPAT Chaser3
[b]DATLONG Chaser4
DATLONG Chaser5[/b]
DATLONG Chaser4
DATLONG Chaser5
GOTO Main
END

' -------------------------------------------------------------------------
' Subroutine Code
' -------------------------------------------------------------------------
SUB DATPAT
 tmpW1 = __WPARAM12
 FOR idx = 0 TO LED_COUNT_MIN1
  READINC tmpW1, pattern(idx)
 NEXT idx
 
 FOR idx = 0 TO LED_COUNT_MIN1 STEP LED_COUNT_DIV8
  SHIFTOUT DataIn, Clock, MSBFIRST, pattern(idx) ' send the bits
  idx2 = idx + 1
  SHIFTOUT DataIn, Clock, MSBFIRST, pattern(idx2)' send the bits
  idx2 = idx2 + 1
  SHIFTOUT DataIn, Clock, MSBFIRST, pattern(idx2)' send the bits
  idx2 = idx2 + 1
  SHIFTOUT DataIn, Clock, MSBFIRST, pattern(idx2)' send the bits
  PULSOUT Strobe, 1 
  IF tmpW1 <> Chaser3 THEN
    PAUSE DelayTimeFifth
  ELSE
    PAUSE DelayTime
  ENDIF
 NEXT idx
 CLEARALL 'Clear out all the patterns
ENDSUB

[b]SUB DATLONG
 tmpW1 = __WPARAM12
 FOR idx = 0 TO LED_COUNT_LONG_MIN1
  READINC tmpW1, pattern(idx)
 NEXT idx[/b]
[b][/b] 
[b] FOR idx = 0 TO 111 STEP LED_COUNT_DIV8
  SHIFTOUT DataIn, Clock, MSBFIRST, pattern(idx) ' send the bits
  idx2 = idx + 1
  SHIFTOUT DataIn, Clock, MSBFIRST, pattern(idx2)' send the bits
  idx2 = idx2 + 1
  SHIFTOUT DataIn, Clock, MSBFIRST, pattern(idx2)' send the bits
  idx2 = idx2 + 1
  SHIFTOUT DataIn, Clock, MSBFIRST, pattern(idx2)' send the bits
  PULSOUT Strobe, 1 
  IF tmpW1 <> Chaser4 THEN
    PAUSE DelayTimeTenth
  ELSE
    PAUSE DelayTime
  ENDIF
 NEXT idx
 CLEARALL 'Clear out all the patterns
ENDSUB[/b]
 
SUB CLEARALL
 FOR idx = 0 TO LED_COUNT_MIN1
  pattern(idx) = 0
 NEXT idx 
ENDSUB

SUB FORWARD_1
 idx = 0
 pattern(0) = %00000001
 DO
   OUT      ' move pattern to LEDs
   PAUSE DelayTimeHalf                       ' hold
   pattern(0) = pattern(0) << 1                 ' shift pattern left
   INC idx
 LOOP UNTIL idx = 8
 idx = 0
 pattern(1) = %00000001
 DO
   OUT      ' move pattern to LEDs
   PAUSE DelayTimeHalf                       ' hold
   pattern(1) = pattern(1) << 1                 ' shift pattern left
   INC idx
 LOOP UNTIL idx = 8
 idx = 0
 pattern(2) = %00000001
 DO
   OUT      ' move pattern to LEDs
   PAUSE DelayTimeHalf                       ' hold
   pattern(2) = pattern(2) << 1                 ' shift pattern left
   INC idx
 LOOP UNTIL idx = 8
 idx = 0
 pattern(3) = %00000001
 DO
   OUT      ' move pattern to LEDs
   PAUSE DelayTimeHalf                       ' hold
   pattern(3) = pattern(3) << 1                 ' shift pattern left
   INC idx
 LOOP UNTIL idx = 8
ENDSUB
SUB BACKWARD_1
 idx = 8
 pattern(3) = %10000000
 DO
   OUT      ' move pattern to LEDs
   PAUSE DelayTimeQtr                       ' hold
   pattern(3) = pattern(3) >> 1                 ' shift pattern left
   DEC idx
 LOOP UNTIL idx = 0
 idx = 8
 pattern(2) = %10000000
 DO
   OUT      ' move pattern to LEDs
   PAUSE DelayTimeQtr                       ' hold
   pattern(2) = pattern(2) >> 1                 ' shift pattern left
   DEC idx
 LOOP UNTIL idx = 0
idx = 8
 pattern(1) = %10000000
 DO
   OUT      ' move pattern to LEDs
   PAUSE DelayTimeQtr                       ' hold
   pattern(1) = pattern(1) >> 1                 ' shift pattern left
   DEC idx
 LOOP UNTIL idx = 0
idx = 8
 pattern(0) = %10000000
 DO
   OUT      ' move pattern to LEDs
   PAUSE DelayTimeQtr                       ' hold
   pattern(0) = pattern(0) >> 1                 ' shift pattern left
   DEC idx
 LOOP UNTIL idx = 0
ENDSUB

' -------------------------------------------------------------------------
SUB OUT
 FOR temp1 = 3 to 0 step -1
  SHIFTOUT DataIn, Clock, MSBFIRST, pattern(temp1)' send the bits
 NEXT temp1
 PULSOUT Strobe, 1                                ' transfer to outputs
ENDSUB
'74HC595  Last        3rd        2nd        1st
Chaser1:
  DATA %00000001, %10000000, %11000000, %00000011
  DATA %00000010, %01000000, %01100000, %00000110
  DATA %00000100, %00100000, %00110000, %00001100
  DATA %00001000, %00010000, %00011000, %00011000
  DATA %00010000, %00001000, %00001100, %00110000
  DATA %00100000, %00000100, %00000110, %01100000
  DATA %01000000, %00000010, %00000011, %11000000
  DATA %10000000, %00000001, %00000001, %10000000
Chaser2:
  DATA %00000000, %11001100, %00011000, %00000000
  DATA %00000000, %00110011, %00111100, %00000000
  DATA %00000000, %11001100, %01111110, %00000000
  DATA %00000000, %00110011, %11111111, %00000000
  DATA %00000000, %11110000, %11111111, %00000000
  DATA %00000000, %00001111, %01111110, %00000000
  DATA %00000000, %11110000, %00111100, %00000000
  DATA %00000000, %00001111 ,%00011000, %00000000
Chaser3:    
  DATA %00001111, %00001111, %00001111, %00001111
  DATA %00111100, %00111100, %00111100, %00111100
  DATA %11110000, %11110000, %11110000, %11110000
  DATA %11000011, %11000011, %11000011, %11000011
  DATA %00001111, %00001111, %00001111, %00001111
  DATA %00111100, %00111100, %00111100, %00111100
  DATA %11110000, %11110000, %11110000, %11110000
  DATA %11000011, %11000011, %11000011, %11000011
[b]Chaser4:
  DATA %00000000, %00000000, %00000000, %00001111
  DATA %00000000, %00000000, %00000000, %00011110
  DATA %00000000, %00000000, %00000000, %00111100
  DATA %00000000, %00000000, %00000000, %01111000
  DATA %00000000, %00000000, %00000000, %11110000
  DATA %00000000, %00000000, %00000001, %11100000
  DATA %00000000, %00000000, %00000011, %11000000
  DATA %00000000, %00000000, %00000111, %10000000
  DATA %00000000, %00000000, %00001111, %00000000
  DATA %00000000, %00000000, %00011110, %00000000
  DATA %00000000, %00000000, %00111100, %00000000
  DATA %00000000, %00000000, %01111000, %00000000
  DATA %00000000, %00000000, %11110000, %00000000
  DATA %00000000, %00000001, %11100000, %00000000
  DATA %00000000, %00000011, %11000000, %00000000
  DATA %00000000, %00000111, %10000000, %00000000
  DATA %00000000, %00001111, %00000000, %00000000
  DATA %00000000, %00011110, %00000000, %00000000
  DATA %00000000, %00111100, %00000000, %00000000
  DATA %00000000, %01111000, %00000000, %00000000
  DATA %00000000, %11110000, %00000000, %00000000
  DATA %00000001, %11100000, %00000000, %00000000
  DATA %00000011, %11000000, %00000000, %00000000
  DATA %00000111, %10000000, %00000000, %00000000
  DATA %00001111, %00000000, %00000000, %00000000
  DATA %00011110, %00000000, %00000000, %00000000
  DATA %00111100, %00000000, %00000000, %00000000
  DATA %01111000, %00000000, %00000000, %00000000
  
Chaser5:
  DATA %11110000, %00000000, %00000000, %00000000
  DATA %01111000, %00000000, %00000000, %00000000
  DATA %00111100, %00000000, %00000000, %00000000
  DATA %00011110, %00000000, %00000000, %00000000
  DATA %00001111, %00000000, %00000000, %00000000
  DATA %00000111, %10000000, %00000000, %00000000
  DATA %00000011, %11000000, %00000000, %00000000
  DATA %00000001, %11100000, %00000000, %00000000
  DATA %00000000, %11110000, %00000000, %00000000
  DATA %00000000, %01111000, %00000000, %00000000
  DATA %00000000, %00111100, %00000000, %00000000
  DATA %00000000, %00011110, %00000000, %00000000
  DATA %00000000, %00001111, %00000000, %00000000
  DATA %00000000, %00000111, %10000000, %00000000
  DATA %00000000, %00000011, %11000000, %00000000
  DATA %00000000, %00000001, %11100000, %00000000
  DATA %00000000, %00000000, %11110000, %00000000
  DATA %00000000, %00000000, %01111000, %00000000
  DATA %00000000, %00000000, %00111100, %00000000
  DATA %00000000, %00000000, %00011110, %00000000
  DATA %00000000, %00000000, %00001111, %00000000
  DATA %00000000, %00000000, %00000111, %10000000
  DATA %00000000, %00000000, %00000011, %11000000
  DATA %00000000, %00000000, %00000001, %11100000
  DATA %00000000, %00000000, %00000000, %11110000
  DATA %00000000, %00000000, %00000000, %01111000
  DATA %00000000, %00000000, %00000000, %00111100
  DATA %00000000, %00000000, %00000000, %00011110[/b]
 

Comments

  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-01-31 16:20
    You can use the detailed RAM map at the end of the listing to see why your big array is bumping into the end of memory. Press Ctrl+L and scroll to the end.
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2009-01-31 16:56
    JonnyMac,

    That is awesome. I never knew about that!
    If I declare: pattern·VAR·Byte(103) it shows all of the RAM locations so you know how much space you have left for RAM variables / arrays. At 103 it brings it to the very end limit. So using an array of 112 would cause the error. Great to know!

    With pattern··VAR·Byte(103) - See below:

    1171                  ;**********************************************************************
      1172                  ; SX/B VARIABLE MEMORY MAP:  [noparse][[/noparse]B]=Byte; [noparse][[/noparse]b0-7]=Bit, [noparse][[/noparse]W]=Word, (#)=Array
      1173                  
      1174                  ; $00 = __RAM(0),  W[noparse][[/noparse]B],  IND[noparse][[/noparse]B]
      1175                  ; $01 = __RAM(1),  RTCC[noparse][[/noparse]B]
      1176                  ; $02 = __RAM(2),  PC[noparse][[/noparse]B]
      1177                  ; $03 = __RAM(3),  STATUS[noparse][[/noparse]B],  PA2[noparse][[/noparse]b7],  PA1[noparse][[/noparse]b6],  PA0[noparse][[/noparse]b5],  _TO[noparse][[/noparse]b4],  PD[noparse][[/noparse]b3],  Z[noparse][[/noparse]b2],  DC[noparse][[/noparse]b1],  C[noparse][[/noparse]b0]
      1178                  ; $04 = __RAM(4),  FSR[noparse][[/noparse]B]
      1179                  ; $05 = __RAM(5),  PORTA[noparse][[/noparse]B],  RA[noparse][[/noparse]B],  Clock[noparse][[/noparse]b0],  DataIn[noparse][[/noparse]b1],  Strobe[noparse][[/noparse]b2]
      1180                  ; $06 = __RAM(6),  RBC[noparse][[/noparse]W],  RBC_LSB[noparse][[/noparse]B],  PORTB[noparse][[/noparse]B],  RB[noparse][[/noparse]B]
      1181                  ; $07 = __RAM(7),  RBC_MSB[noparse][[/noparse]B],  PORTC[noparse][[/noparse]B],  RC[noparse][[/noparse]B]
      1182                  ; $08 = __RAM(8),  __PARAM1[noparse][[/noparse]B],  __WPARAM12[noparse][[/noparse]W],  __WPARAM12_LSB[noparse][[/noparse]B],  __REMAINDER[noparse][[/noparse]B],  __WREMAINDER[noparse][[/noparse]W],  __WREMAINDER_LSB[noparse][[/noparse]B]
      1183                  ; $09 = __RAM(9),  __PARAM2[noparse][[/noparse]B],  __WPARAM12_MSB[noparse][[/noparse]B],  __WPARAM23[noparse][[/noparse]W],  __WPARAM23_LSB[noparse][[/noparse]B],  __WREMAINDER_MSB[noparse][[/noparse]B]
      1184                  ; $0A = __RAM(10),  __PARAM3[noparse][[/noparse]B],  __WPARAM23_MSB[noparse][[/noparse]B],  __WPARAM34[noparse][[/noparse]W],  __WPARAM34_LSB[noparse][[/noparse]B]
      1185                  ; $0B = __RAM(11),  __PARAM4[noparse][[/noparse]B],  __WPARAM34_MSB[noparse][[/noparse]B],  __WPARAM45[noparse][[/noparse]W],  __WPARAM45_LSB[noparse][[/noparse]B]
      1186                  ; $0C = __RAM(12),  __PARAM5[noparse][[/noparse]B],  __PARAMCNT[noparse][[/noparse]B],  __WPARAM45_MSB[noparse][[/noparse]B]
      1187                  ; $0D = __RAM(13),  idx[noparse][[/noparse]B]
      1188                  ; $0E = __RAM(14),  idx2[noparse][[/noparse]B]
      1189                  ; $0F = __RAM(15),  temp1[noparse][[/noparse]B]
      1190                  
      1191                  ; $10 = __RAM(16),  tmpW1[noparse][[/noparse]W],  tmpW1_LSB[noparse][[/noparse]B]
      1192                  ; $11 = __RAM(17),  tmpW1_MSB[noparse][[/noparse]B]
      1193                  ; $12 = __RAM(18)
      1194                  ; $13 = __RAM(19)
      1195                  ; $14 = __RAM(20)
      1196                  ; $15 = __RAM(21)
      1197                  ; $16 = __RAM(22)
      1198                  ; $17 = __RAM(23)
      1199                  ; $18 = __RAM(24)
      1200                  ; $19 = __RAM(25)
      1201                  ; $1A = __RAM(26)
      1202                  ; $1B = __RAM(27)
      1203                  ; $1C = __RAM(28)
      1204                  ; $1D = __RAM(29)
      1205                  ; $1E = __RAM(30)
      1206                  ; $1F = __RAM(31)
      1207                  
      [b]1208                  ; $30 = __RAM(48),  pattern(0)
      1209                  ; $31 = __RAM(49),  pattern(1)
      1210                  ; $32 = __RAM(50),  pattern(2)
      1211                  ; $33 = __RAM(51),  pattern(3)
      1212                  ; $34 = __RAM(52),  pattern(4)
      1213                  ; $35 = __RAM(53),  pattern(5)
      1214                  ; $36 = __RAM(54),  pattern(6)
      1215                  ; $37 = __RAM(55),  pattern(7)
      1216                  ; $38 = __RAM(56),  pattern(8)
      1217                  ; $39 = __RAM(57),  pattern(9)
      1218                  ; $3A = __RAM(58),  pattern(10)
      1219                  ; $3B = __RAM(59),  pattern(11)
      1220                  ; $3C = __RAM(60),  pattern(12)
      1221                  ; $3D = __RAM(61),  pattern(13)
      1222                  ; $3E = __RAM(62),  pattern(14)
      1223                  ; $3F = __RAM(63),  pattern(15)
      1224                  
      1225                  ; $50 = __RAM(80),  pattern(16)
      1226                  ; $51 = __RAM(81),  pattern(17)
      1227                  ; $52 = __RAM(82),  pattern(18)
      1228                  ; $53 = __RAM(83),  pattern(19)
      1229                  ; $54 = __RAM(84),  pattern(20)
      1230                  ; $55 = __RAM(85),  pattern(21)
      1231                  ; $56 = __RAM(86),  pattern(22)
      1232                  ; $57 = __RAM(87),  pattern(23)
      1233                  ; $58 = __RAM(88),  pattern(24)
      1234                  ; $59 = __RAM(89),  pattern(25)
      1235                  ; $5A = __RAM(90),  pattern(26)
      1236                  ; $5B = __RAM(91),  pattern(27)
      1237                  ; $5C = __RAM(92),  pattern(28)
      1238                  ; $5D = __RAM(93),  pattern(29)
      1239                  ; $5E = __RAM(94),  pattern(30)
      1240                  ; $5F = __RAM(95),  pattern(31)
      1241                  
      1242                  ; $70 = __RAM(112),  pattern(32)
      1243                  ; $71 = __RAM(113),  pattern(33)
      1244                  ; $72 = __RAM(114),  pattern(34)
      1245                  ; $73 = __RAM(115),  pattern(35)
      1246                  ; $74 = __RAM(116),  pattern(36)
      1247                  ; $75 = __RAM(117),  pattern(37)
      1248                  ; $76 = __RAM(118),  pattern(38)
      1249                  ; $77 = __RAM(119),  pattern(39)
      1250                  ; $78 = __RAM(120),  pattern(40)
      1251                  ; $79 = __RAM(121),  pattern(41)
      1252                  ; $7A = __RAM(122),  pattern(42)
      1253                  ; $7B = __RAM(123),  pattern(43)
      1254                  ; $7C = __RAM(124),  pattern(44)
      1255                  ; $7D = __RAM(125),  pattern(45)
      1256                  ; $7E = __RAM(126),  pattern(46)
      1257                  ; $7F = __RAM(127),  pattern(47)
      1258                  
      1259                  ; $90 = __RAM(144),  pattern(48)
      1260                  ; $91 = __RAM(145),  pattern(49)
      1261                  ; $92 = __RAM(146),  pattern(50)
      1262                  ; $93 = __RAM(147),  pattern(51)
      1263                  ; $94 = __RAM(148),  pattern(52)
      1264                  ; $95 = __RAM(149),  pattern(53)
      1265                  ; $96 = __RAM(150),  pattern(54)
      1266                  ; $97 = __RAM(151),  pattern(55)
      1267                  ; $98 = __RAM(152),  pattern(56)
      1268                  ; $99 = __RAM(153),  pattern(57)
      1269                  ; $9A = __RAM(154),  pattern(58)
      1270                  ; $9B = __RAM(155),  pattern(59)
      1271                  ; $9C = __RAM(156),  pattern(60)
      1272                  ; $9D = __RAM(157),  pattern(61)
      1273                  ; $9E = __RAM(158),  pattern(62)
      1274                  ; $9F = __RAM(159),  pattern(63)
      1275                  
      1276                  ; $B0 = __RAM(176),  pattern(64)
      1277                  ; $B1 = __RAM(177),  pattern(65)
      1278                  ; $B2 = __RAM(178),  pattern(66)
      1279                  ; $B3 = __RAM(179),  pattern(67)
      1280                  ; $B4 = __RAM(180),  pattern(68)
      1281                  ; $B5 = __RAM(181),  pattern(69)
      1282                  ; $B6 = __RAM(182),  pattern(70)
      1283                  ; $B7 = __RAM(183),  pattern(71)
      1284                  ; $B8 = __RAM(184),  pattern(72)
      1285                  ; $B9 = __RAM(185),  pattern(73)
      1286                  ; $BA = __RAM(186),  pattern(74)
      1287                  ; $BB = __RAM(187),  pattern(75)
      1288                  ; $BC = __RAM(188),  pattern(76)
      1289                  ; $BD = __RAM(189),  pattern(77)
      1290                  ; $BE = __RAM(190),  pattern(78)
      1291                  ; $BF = __RAM(191),  pattern(79)
      1292                  
      1293                  ; $D0 = __RAM(208),  pattern(80)
      1294                  ; $D1 = __RAM(209),  pattern(81)
      1295                  ; $D2 = __RAM(210),  pattern(82)
      1296                  ; $D3 = __RAM(211),  pattern(83)
      1297                  ; $D4 = __RAM(212),  pattern(84)
      1298                  ; $D5 = __RAM(213),  pattern(85)
      1299                  ; $D6 = __RAM(214),  pattern(86)
      1300                  ; $D7 = __RAM(215),  pattern(87)
      1301                  ; $D8 = __RAM(216),  pattern(88)
      1302                  ; $D9 = __RAM(217),  pattern(89)
      1303                  ; $DA = __RAM(218),  pattern(90)
      1304                  ; $DB = __RAM(219),  pattern(91)
      1305                  ; $DC = __RAM(220),  pattern(92)
      1306                  ; $DD = __RAM(221),  pattern(93)
      1307                  ; $DE = __RAM(222),  pattern(94)
      1308                  ; $DF = __RAM(223),  pattern(95)
      1309                  
      1310                  ; $F0 = __RAM(240),  pattern(96)
      1311                  ; $F1 = __RAM(241),  pattern(97)
      1312                  ; $F2 = __RAM(242),  pattern(98)
      1313                  ; $F3 = __RAM(243),  pattern(99)
      1314                  ; $F4 = __RAM(244),  pattern(100)
      1315                  ; $F5 = __RAM(245),  pattern(101)
      1316                  ; $F6 = __RAM(246),  pattern(102)
    [/b]  1317                  ; $F7 = __RAM(247),  __INTPARAMFSR(0)
      1318                  ; $F8 = __RAM(248),  __INTPARAMFSR(1)
      1319                  ; $F9 = __RAM(249),  __INTPARAMFSR(2)
      1320                  ; $FA = __RAM(250),  __INTPARAMFSR(3)
      1321                  ; $FB = __RAM(251),  __INTPARAMFSR(4)
      1322                  ; $FC = __RAM(252),  __INTPARAMFSR(5)
      1323                  ; $FD = __RAM(253),  TRIS_A(0)
      1324                  ; $FE = __RAM(254),  TRIS_B(0)
      1325                  ; $FF = __RAM(255),  TRIS_C(0)
    




    With pattern··VAR·Byte(LED_COUNT) 'where LED_COUNT is 32
      1171                  ;**********************************************************************
      1172                  ; SX/B VARIABLE MEMORY MAP:  [noparse][[/noparse]B]=Byte; [noparse][[/noparse]b0-7]=Bit, [noparse][[/noparse]W]=Word, (#)=Array
      1173                  
      1174                  ; $00 = __RAM(0),  W[noparse][[/noparse]B],  IND[noparse][[/noparse]B]
      1175                  ; $01 = __RAM(1),  RTCC[noparse][[/noparse]B]
      1176                  ; $02 = __RAM(2),  PC[noparse][[/noparse]B]
      1177                  ; $03 = __RAM(3),  STATUS[noparse][[/noparse]B],  PA2[noparse][[/noparse]b7],  PA1[noparse][[/noparse]b6],  PA0[noparse][[/noparse]b5],  _TO[noparse][[/noparse]b4],  PD[noparse][[/noparse]b3],  Z[noparse][[/noparse]b2],  DC[noparse][[/noparse]b1],  C[noparse][[/noparse]b0]
      1178                  ; $04 = __RAM(4),  FSR[noparse][[/noparse]B]
      1179                  ; $05 = __RAM(5),  PORTA[noparse][[/noparse]B],  RA[noparse][[/noparse]B],  Clock[noparse][[/noparse]b0],  DataIn[noparse][[/noparse]b1],  Strobe[noparse][[/noparse]b2]
      1180                  ; $06 = __RAM(6),  RBC[noparse][[/noparse]W],  RBC_LSB[noparse][[/noparse]B],  PORTB[noparse][[/noparse]B],  RB[noparse][[/noparse]B]
      1181                  ; $07 = __RAM(7),  RBC_MSB[noparse][[/noparse]B],  PORTC[noparse][[/noparse]B],  RC[noparse][[/noparse]B]
      1182                  ; $08 = __RAM(8),  __PARAM1[noparse][[/noparse]B],  __WPARAM12[noparse][[/noparse]W],  __WPARAM12_LSB[noparse][[/noparse]B],  __REMAINDER[noparse][[/noparse]B],  __WREMAINDER[noparse][[/noparse]W],  __WREMAINDER_LSB[noparse][[/noparse]B]
      1183                  ; $09 = __RAM(9),  __PARAM2[noparse][[/noparse]B],  __WPARAM12_MSB[noparse][[/noparse]B],  __WPARAM23[noparse][[/noparse]W],  __WPARAM23_LSB[noparse][[/noparse]B],  __WREMAINDER_MSB[noparse][[/noparse]B]
      1184                  ; $0A = __RAM(10),  __PARAM3[noparse][[/noparse]B],  __WPARAM23_MSB[noparse][[/noparse]B],  __WPARAM34[noparse][[/noparse]W],  __WPARAM34_LSB[noparse][[/noparse]B]
      1185                  ; $0B = __RAM(11),  __PARAM4[noparse][[/noparse]B],  __WPARAM34_MSB[noparse][[/noparse]B],  __WPARAM45[noparse][[/noparse]W],  __WPARAM45_LSB[noparse][[/noparse]B]
      1186                  ; $0C = __RAM(12),  __PARAM5[noparse][[/noparse]B],  __PARAMCNT[noparse][[/noparse]B],  __WPARAM45_MSB[noparse][[/noparse]B]
      1187                  ; $0D = __RAM(13),  idx[noparse][[/noparse]B]
      1188                  ; $0E = __RAM(14),  idx2[noparse][[/noparse]B]
      1189                  ; $0F = __RAM(15),  temp1[noparse][[/noparse]B]
      1190                  
      1191                  ; $10 = __RAM(16),  tmpW1[noparse][[/noparse]W],  tmpW1_LSB[noparse][[/noparse]B]
      1192                  ; $11 = __RAM(17),  tmpW1_MSB[noparse][[/noparse]B]
      1193                  ; $12 = __RAM(18)
      1194                  ; $13 = __RAM(19)
      1195                  ; $14 = __RAM(20)
      1196                  ; $15 = __RAM(21)
      1197                  ; $16 = __RAM(22)
      1198                  ; $17 = __RAM(23)
      1199                  ; $18 = __RAM(24)
      1200                  ; $19 = __RAM(25)
      1201                  ; $1A = __RAM(26)
      1202                  ; $1B = __RAM(27)
      1203                  ; $1C = __RAM(28)
      1204                  ; $1D = __RAM(29)
      1205                  ; $1E = __RAM(30)
      1206                  ; $1F = __RAM(31)
      1207                  
     [b] 1208                  ; $30 = __RAM(48),  pattern(0)
      1209                  ; $31 = __RAM(49),  pattern(1)
      1210                  ; $32 = __RAM(50),  pattern(2)
      1211                  ; $33 = __RAM(51),  pattern(3)
      1212                  ; $34 = __RAM(52),  pattern(4)
      1213                  ; $35 = __RAM(53),  pattern(5)
      1214                  ; $36 = __RAM(54),  pattern(6)
      1215                  ; $37 = __RAM(55),  pattern(7)
      1216                  ; $38 = __RAM(56),  pattern(8)
      1217                  ; $39 = __RAM(57),  pattern(9)
      1218                  ; $3A = __RAM(58),  pattern(10)
      1219                  ; $3B = __RAM(59),  pattern(11)
      1220                  ; $3C = __RAM(60),  pattern(12)
      1221                  ; $3D = __RAM(61),  pattern(13)
      1222                  ; $3E = __RAM(62),  pattern(14)
      1223                  ; $3F = __RAM(63),  pattern(15)
      1224                  
      1225                  ; $50 = __RAM(80),  pattern(16)
      1226                  ; $51 = __RAM(81),  pattern(17)
      1227                  ; $52 = __RAM(82),  pattern(18)
      1228                  ; $53 = __RAM(83),  pattern(19)
      1229                  ; $54 = __RAM(84),  pattern(20)
      1230                  ; $55 = __RAM(85),  pattern(21)
      1231                  ; $56 = __RAM(86),  pattern(22)
      1232                  ; $57 = __RAM(87),  pattern(23)
      1233                  ; $58 = __RAM(88),  pattern(24)
      1234                  ; $59 = __RAM(89),  pattern(25)
      1235                  ; $5A = __RAM(90),  pattern(26)
      1236                  ; $5B = __RAM(91),  pattern(27)
      1237                  ; $5C = __RAM(92),  pattern(28)
      1238                  ; $5D = __RAM(93),  pattern(29)
      1239                  ; $5E = __RAM(94),  pattern(30)
      1240                  ; $5F = __RAM(95),  pattern(31)
      1241                  
     [color=red] 1242                  ; $70 = __RAM(112)
      1243                  ; $71 = __RAM(113)
      1244                  ; $72 = __RAM(114)
      1245                  ; $73 = __RAM(115)
      1246                  ; $74 = __RAM(116)
      1247                  ; $75 = __RAM(117)
      1248                  ; $76 = __RAM(118)
      1249                  ; $77 = __RAM(119)
      1250                  ; $78 = __RAM(120)
      1251                  ; $79 = __RAM(121)
      1252                  ; $7A = __RAM(122)
      1253                  ; $7B = __RAM(123)
      1254                  ; $7C = __RAM(124)
      1255                  ; $7D = __RAM(125)
      1256                  ; $7E = __RAM(126)
      1257                  ; $7F = __RAM(127)
      1258                  
      1259                  ; $90 = __RAM(144)
      1260                  ; $91 = __RAM(145)
      1261                  ; $92 = __RAM(146)
      1262                  ; $93 = __RAM(147)
      1263                  ; $94 = __RAM(148)
      1264                  ; $95 = __RAM(149)
      1265                  ; $96 = __RAM(150)
      1266                  ; $97 = __RAM(151)
      1267                  ; $98 = __RAM(152)
      1268                  ; $99 = __RAM(153)
      1269                  ; $9A = __RAM(154)
      1270                  ; $9B = __RAM(155)
      1271                  ; $9C = __RAM(156)
      1272                  ; $9D = __RAM(157)
      1273                  ; $9E = __RAM(158)
      1274                  ; $9F = __RAM(159)
      1275                  
      1276                  ; $B0 = __RAM(176)
      1277                  ; $B1 = __RAM(177)
      1278                  ; $B2 = __RAM(178)
      1279                  ; $B3 = __RAM(179)
      1280                  ; $B4 = __RAM(180)
      1281                  ; $B5 = __RAM(181)
      1282                  ; $B6 = __RAM(182)
      1283                  ; $B7 = __RAM(183)
      1284                  ; $B8 = __RAM(184)
      1285                  ; $B9 = __RAM(185)
      1286                  ; $BA = __RAM(186)
      1287                  ; $BB = __RAM(187)
      1288                  ; $BC = __RAM(188)
      1289                  ; $BD = __RAM(189)
      1290                  ; $BE = __RAM(190)
      1291                  ; $BF = __RAM(191)
      1292                  
      1293                  ; $D0 = __RAM(208)
      1294                  ; $D1 = __RAM(209)
      1295                  ; $D2 = __RAM(210)
      1296                  ; $D3 = __RAM(211)
      1297                  ; $D4 = __RAM(212)
      1298                  ; $D5 = __RAM(213)
      1299                  ; $D6 = __RAM(214)
      1300                  ; $D7 = __RAM(215)
      1301                  ; $D8 = __RAM(216)
      1302                  ; $D9 = __RAM(217)
      1303                  ; $DA = __RAM(218)
      1304                  ; $DB = __RAM(219)
      1305                  ; $DC = __RAM(220)
      1306                  ; $DD = __RAM(221)
      1307                  ; $DE = __RAM(222)
      1308                  ; $DF = __RAM(223)
      1309                  
      1310                  ; $F0 = __RAM(240)
      1311                  ; $F1 = __RAM(241)
      1312                  ; $F2 = __RAM(242)
      1313                  ; $F3 = __RAM(243)
      1314                  ; $F4 = __RAM(244)
      1315                  ; $F5 = __RAM(245)
      1316                  ; $F6 = __RAM(246)
    [/color][/b]  1317                  ; $F7 = __RAM(247),  __INTPARAMFSR(0)
      1318                  ; $F8 = __RAM(248),  __INTPARAMFSR(1)
      1319                  ; $F9 = __RAM(249),  __INTPARAMFSR(2)
      1320                  ; $FA = __RAM(250),  __INTPARAMFSR(3)
      1321                  ; $FB = __RAM(251),  __INTPARAMFSR(4)
      1322                  ; $FC = __RAM(252),  __INTPARAMFSR(5)
      1323                  ; $FD = __RAM(253),  TRIS_A(0)
      1324                  ; $FE = __RAM(254),  TRIS_B(0)
      1325                  ; $FF = __RAM(255),  TRIS_C(0)
    
    

    Thanks again for this very helpfull find!
    ·
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-01-31 18:59
    After looking at your program a while I don't think you need more than four bytes of display RAM. It seems that, from time to time, you want to take the pattern that's presently on the LEDs and shift it one way or another; no problem. I created a completely new program template for your 74HC595 hardware; the only thing left from your program is the DATA (some of which is now not necessary) and the connections (though I renamed them to match a 74x595 subroutine I had in place).

    The demo shows how to loop through the items in a table. A couple of your tables are simply doing shifts and rolls. I created routines that do this without having to read from the table more than once (the first element) -- and you can actually eliminate the table by using the PUT_DRAM routine. If you want to shift all the LEDs left, for example, call DSHIFT_LEFT then DRAM_2_LEDS. This is coded in assembly so that bits can move from one byte in the array to another -- basically, dRam is a 32-bit value. I also coded routines to "roll" the bits so that the LED on one end wraps around to the other side (is not lost in the bit bucket as with shifting). Both the shift and roll routines allow you to specify the number of bits to move and default to 1 if you don't pass a parameter.

    See if you can build your show with these new routines.

    [noparse][[/noparse]Edit] NoLatch constant fixed and order adjusted for $IFUSED.

    Post Edited (JonnyMac) : 1/31/2009 10:58:49 PM GMT
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2009-01-31 20:00
    Thank you for your program. When I compile it, it only turns on about 80% of the 32 LEDs on with no movement. Seems to be random. I don't know assembly language but will try to follow if I can but right now it doesn't do anything other than randomly turn on some LEDs.

    Is there anything different in the hardware setup. I previously attached my schematic (disreguard the +12v and ULN2803A usage). Eventually, I want to control about 150 or more LEDs which means I may have to move to an SX48.
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-01-31 21:38
    Okay, I uploaded a new version that is running on my PDB.

    Fixes:
    1) NoLatch constant was incorrect (you should have busted me on that one, Tim <grin>)
    2) Order of SUBs adjusted to play nice with $IFUSED
    3) (not a fix) changed DRAM_2_LEDS to DRAM_TO_LEDS, DATA_2_LEDS to DATA_TO_LEDS

    One note: On my setup I shift through the LSB '595 -- it looks like your hardware does this, too.

    Post Edited (JonnyMac) : 2/1/2009 12:00:49 AM GMT
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-02-01 00:10
    Now that everything seems to be working, let me point out a big memory savings: You have two big tables (Chaser4 and Chaser5) that take 224 bytes (~11% of the program space). You can replace them with these loops:

    Chase_4:
      PUT_DRAM %00000000, %00000000, %00000000, %00001111
      FOR idx = 1 TO 28
        DRAM_TO_LEDS
        DELAY_MS 100
        DSHIFT_LEFT
      NEXT
    
    Chase_5:
      PUT_DRAM %11110000, %00000000, %00000000, %00000000
      FOR idx = 1 TO 28
        DRAM_TO_LEDS
        DELAY_MS 100
        DSHIFT_RIGHT
      ENDIF
    


    Note that the PUT_DRAM at Chase_5 is only required if you want to call Chase_5 independent of Chase_4.
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2009-02-01 01:08
    JonnyMac,

    Your program is working great on my setup. Thank you for sharing! I need to follow closely your program to see what is happening. One thing that I don't immediately see is where to put the updated Chaser4 and 5 routines that you just posted? I don't see the Chaser 2 and 3 being used but I can probably figure that out after looking at your great program in more detail.

    Once again Thank you so much for your program.
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2009-02-01 02:04
    I was able to at least follow the routines in the MAIN and have them commented out. I found a couple of minor issues and fixed them (Chase4 and 5 from your last post) and an overrun in the programs·RollDEMO (Chaser4 DATA)·routine. It was set for 32 and I only have 28 statements so it wrapped arround. Now it is correct. I also added in the Chaser2 and Chaser3 DATA statement routines following your format. I also have the DEMO Routines commented out to see each one in action.

    Great job putting this together and thinking outside the box. Assembly language is a good thing when you know it.

    See attached updated SXB file.
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2009-02-01 03:45
    JonnyMac,

    I was trying to modify your code to use it with (16) 74HC595s for 128 LEDs. All I care about at the Moment is the Chaser4 sequence.

    However, I don't think the·logic I used in·your Assembly Language routines will work. Especially look at PUT DRAM·to start. There are only 4 (or 5) __PARAM statements available Not 16. How can I get arround this?

    See attached.

    Thanks.
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-02-01 03:48
    Again, my goal is not to rewrite your operational program, just to give you ideas to get YOU to think outside the box and write more efficient programs. There are many ways to skin a cat; I spend a lot of time experimenting so I've learned a few.

    Don't be concerned about the Assembly stuff; those are working routines. You don't find it necessary to fix SEROUT, do you? Of course not. So as you trust that SEROUT works please trust that I spent time coding these routines and testing them for use in my own projects -- now you can use them in yours.
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2009-02-01 03:50
    OK - Fair enough I will give it another look.

    Thanks.
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2009-02-01 18:25
    JonnyMac,

    I got it working to allow for my 128 LED requirement using (16) 74HC595s. Although I beleive it is possible to modify it to have up to 800 LEDs without running out of memory on an SX28 and probably double that on an SX48.

    I am currently only using your Chase4 and Chase5 routines that have been modified. All of the other routines are in place for future use - just commented.

    It can probably be cleaned up a bit but I believe it is working well.

    Thanks for sticking with me.
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-02-01 18:47
    You can't pass more than 5 parameters in SX/B so PUT_DRAM is out with 16 shift registers. I've updated all the Assembly routines to work with 16 registers; they have been tested very thoroughly -- please give them a fair try before attempting to modify them. The only routines not tested in this version are DRAM_TO_LEDS and DATA_TO_LEDS -- but these are very simple subs and I don't expect trouble.

    Since PUT_DRAM is gone I suggest you use LOAD_DRAM and an address of a table that holds the bits you want to load; this will probably make your listing cleaner, anyway. Run the attached demo in the Debugger to verify that the routines that load and manipulate the 16-byte dRam() array work as intended.


    FWIW: I don't consider myself an Assembly programmer; that said, between Guenther's book and the output from the SX/B compiler I have learned how to add Assembly segments into my programs where that would be the most efficient strategy. I don't see SX/B as a BASIC language, but as a BASIC/Assembly framework for programming the SX chip.
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-02-01 18:49
    I was re-running my demo when you posted -- have a look at the version I've attached above below.

    [noparse][[/noparse]Edit] I updated the shift and roll routines using looping but your linear versions may in fact be faster. I did what I did for the exercise as I'm trying to get better at Assembly -- you've got two ways to go; both work.

    [noparse][[/noparse]Edit] I updated my second demo with linear routines for loading, shifting and rolling as these are considerably faster (and easier to understand) than the loop versions.

    Post Edited (JonnyMac) : 2/1/2009 7:31:57 PM GMT
  • T&amp;E EngineerT&amp;E Engineer Posts: 1,396
    edited 2009-02-01 20:56
    Thank you for the updates.

    So from your last posting, I believe you stated that either my program or your program should work. I just wanted to make sure I wasn't missing something as I am repeating the PUT_DRAM_x routine 4 times to cover the 16 registers - which you are not using. First attempt at running your·2 programs produces no movement of the LEDs but I will look at it closer. Although, as long as my last post·attachement file will work, I would just as well·use that and bring in your other routines·(you modified for 16·registers) for future use.
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-02-01 21:23
    I think PUT_DRAM is a mistake with more that 4 registers. Use LOAD_DRAM and DATA statement; it will use less code and will keep your listings cleaner. The only thing I didn't [noparse][[/noparse]originally] test is DRAM_TO_LEDS and DATA_TO_LEDS so you'll need to check these on your system. Everything else works; I know that the shift and roll routines move bits through the array and you can see that running the demo in the debugger (the array is the column at $30).

    [noparse][[/noparse]Edit] I just reconnected a 74HC595 on my PDB and DRAM_TO_LEDS is working as expected. Remember, if you want to shift the LEDs you have to call a shift or roll routine and then update the outputs with DRAM_TO_LEDS. If you wan the display updated at the end of a shift or roll put DRAM_TO_LEDS right before the $ENDIF marker at the end of each of these routines.

    Time for a Super Bowl party in Beverly Hills -- I'm outta here!

    Post Edited (JonnyMac) : 2/1/2009 9:30:16 PM GMT
Sign In or Register to comment.