Forum Index > Projects > Larson Scanner kit and LED Menorah kit support
 Menorah flicker
 |  Printable Version
By: Anonymous: Mike Mitchell () on Thursday, March 08 2012 @ 12:43 PM PST (Read 1087 times)  
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

Any advantage to this version? How does it look in comparison?


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: Anonymous: Mike Mitchell () on Friday, March 09 2012 @ 07:58 AM PST  
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

Retracting a boneheaded question. Apologies for the inconvenience....

Take care,
brad


Forum Apprentice
Apprentice


Status: offline

Registered: 02/27/12
Posts: 10

Profile Email    
   



 All times are PDT. The time is now 10:37 PM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to Post 
Filtered HTML Allowed 
Censored Content 

Evil Mad Scientist Forum Archives — Read only!

Please visit our new forums for new discussions.


DIY Hardware for Electronic Art


The Original Egg-Bot Kit


Octolively
Interactive LED kits


Meggy Jr RGB
LED matrix game
development kit.


Business-card sized
AVR target boards


Peggy 2
LED Pegboard kits

My Account






Lost your password?