What size are all the different arrays?
In the Grid Evalutaion section, precalculating the Array index values and replacing the AND-logic with nested IF/THEN saves Another bunch of cyclesIt's not nearly as elegant but it does increase the performance a bit. All in all that 1024 iteration FOR/NEXT loop took 265ms to execute on my test board, now it's 67. Obviously I don't know if it still WORKS so it might all be for nothing :-)Code:'Grid Evaluation CntPlus33 VAR WORD CntPlus32 VAR WORD CntPlus31 VAR WORD CntPlus1 VAR WORD CntMinus33 VAR WORD CntMinus32 VAR WORD CntMinus31 VAR WORD CntMinus1 VAR WORD CntPlus33 = Counter + 33 CntPlus32 = Counter + 32 CntPlus31 = Counter + 31 CntPlus1 = Counter +1 CntMinus33 = Counter - 33 CntMinus32 = Counter - 32 CntMinus31 = Counter - 31 CntMinus1 = Counter - 1 IF led[CntMinus1] > 0 THEN IF counter > 0 THEN Colour[population] = led[CntMinus1] population = population + 1 ENDIF ENDIF IF led[CntPlus1] > 0 THEN IF counter < 1023 THEN Colour[population] = led[CntPlus1] population = population + 1 ENDIF ENDIF IF botedge = 0 THEN IF led [CntMinus33] > 0 THEN Colour[population] = led[CntMinus33] population = population + 1 ENDIF IF led [CntMinus32] > 0 THEN Colour[population] = led[CntMinus32] population = population + 1 ENDIF IF rigedge = 0 and led [CntMinus33] > 0 THEN Colour[population] = led[CntMinus33] population = population + 1 ENDIF ENDIF IF topedge = 0 THEN IF led [CntPlus31] > 0 THEN Colour[population] = led[CntPlus31] population = population + 1 ENDIF IF led [CntPlus32] > 0 THEN Colour[population] = led[CntPlus32] population = population + 1 ENDIF IF rigedge = 0 and led [CntPlus33] > 0 THEN Colour[population] = led[CntPlus33] population = population + 1 ENDIF ENDIF
/Henrik.
I'm very grateful for all these interesting replies. Thank you.
There are three basic 1024 element byte arrays.
Led var byte[1024] used to hold the current generation of cells
LedNew var byte [1024] used to to hold the next generation of cells (This is copied into the Led array after evaluation is completed)
NeoLed var byte [1024] used to hold the NeoPixel led data.
This third array is required because the layout of the NeoPixels grid is one continuous string of 1024 leds arranged like a snakes and ladders board.
This is different to the other two arrays which are a conventional X/Y grid layout, so the Led data has to be parsed and re-organised to display correctly on the neopixel grid.
How are people timing the loops etc.
I would be interested in that code so I can see what difference changes make.
There's also an array called colour, how large is that?
For this I just toggle an output and measure it with the scope but for more precise measurements I use one of the onboard timers. Reset it, start it, execute code, stop it, output its value.
Doing that it's important to have SOME idea about what you're measuring in order to set up the timer with proper prescaling value to make sure you don't overflow, giving you false readings.
I incorporated all those ideas and it is now running at over 13hz v 3hz before. Well done Team!
The Colour Array is only 8 elements and holds the colour of any adjacent cells to the one being tested.
Which of these two is technically quickest? Both seem to work well but I haven't got timing set up yet.
orCode:Temp = Counter // 32 If Temp = 0 THEN lefedge = 1 ENDIF IF Temp = 31 THEN rigedge = 1 ENDIF
Code:Temp = Counter & 65504 If Temp = 0 THEN lefedge = 1 ENDIF IF Temp = 31 THEN rigedge = 1 ENDIF
Here we have it at 13hz..
Last edited by retepsnikrep; - 23rd May 2020 at 13:48.
hmm i think i got that the wrong way round
try Temp = Counter & 31
the bitwise and is faster than a // which uses a divide
i wonder about led/LedNew arrays as byte . a cell is either dead or not dead a bit can store that info
Warning I'm not a teacher
Great that it all still works!
I timed it and Richards is a quite a bit quicker. On my test setup it went from 67 to 48ms which is not surprising since, generally speaking, anything involving division is a killer.
I also found that I had missed one AND statement, replaced that with nested IFs and I'm now measuring 44.7ms
That all works and I changed the AND statements.
Maybe 15hz nowbut I need to do some proper timing.
The arrays also store LED RGB colour and brightness information so one bit is not sufficient.I wonder about led/LedNew arrays as byte . a cell is either dead or not dead a bit can store that info
The colour of a new cell is dependent on the adjacent three populated cells that spawn it.
Bookmarks