 |
By: Anonymous: Mike Mitchell () on Thursday, March 08 2012 @ 12:43 PM PST (Read 843 times)
|
|
|
Anonymous: Mike Mitchell |
| Anonymous: Mike Mitchell |
|
I found this bit of code from the Menorah kit intriguing:
flickercounter += 23 ; // Rate of counter increase
if ((flickercounter & 127) < 64) { // ***Worlds crappiest pseudorandom number generator!*** //
I replaced it with a linear feedback shift register:
@@ -127,7 +127,7 @@
uint8_t LED0, LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8;
unsigned int CycleCountLow, CycleCountOverflow;
- unsigned int flickercounter=0;
+ uint16_t lfsr=0xace1; // linear feedback shift register
unsigned int flickerPrescale=0;
unsigned int brightStep = 1;
@@ -468,10 +468,9 @@
j = 0;
while (j < 9) {
- flickercounter += 23 ; // Rate of counter increase
-
- if ((flickercounter & 127) < 64) { // ***Worlds crappiest pseudorandom number generator!*** //
-
+ // linear feedback shift register as a pseudorandom bit generator
+ lfsr = (lfsr >> 1) ^ ((-(lfsr & 1)) & (uint16_t)0xb400);
+ if (lfsr & 1) {
if (LEDsFlicker[j] < (brightmax - brightStep) ) {
LEDsFlicker[j] += brightStep;
|
|
|
|
|
|
 |
By: Windell (offline) on Thursday, March 08 2012 @ 04:47 PM PST
|
|
|
Windell |
| Windell |
|
Any advantage to this version? How does it look in comparison?
Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/
|

Evil Scientist
 Status: offline
Registered: 06/15/06 Posts: 1932
Sunnyvale, CA
|
|
|
|
|
 |
By: Anonymous: Mike Mitchell () on Friday, March 09 2012 @ 07:58 AM PST
|
|
|
Anonymous: Mike Mitchell |
| Anonymous: Mike Mitchell |
|
The original flicker to me looked more like a pulsation than a flicker, with all 9 LEDs almost
synchronized. That is because checking the sixth bit of the "Worlds crappiest
pseudorandom number generator" generates a sequence of only 128 bits before it repeats:
1 1 0 0 0 1 1 1 0 0 0 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 1 1 1 0 0
0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 0 0 0 1 1 1 0 0 0 1 1 0
0 0 1 1 1 0 0 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 0 0 0 1 1
1 0 0 0 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 0 1
The 16-bit linear feed back shift register generates a sequence of 65535 bits before it
repeats. The result looks much more like a random flicker.
|
|
|
|
|
|
 |
By: brand (offline) on Friday, March 09 2012 @ 11:41 PM PST
|
|
|
brand |
| brand |
|
Retracting a boneheaded question. Apologies for the inconvenience....
Take care,
brad
|

Apprentice
Status: offline
Registered: 02/27/12 Posts: 10
|
|
|
|
|