Created
October 26, 2017 23:57
-
-
Save ednisley/a2b935a1e6b38e238ff07f3569752e41 to your computer and use it in GitHub Desktop.
Arduino Pseudo-Random White Noise Source
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Quick test for random bit generation timing | |
// Ed Nisley KE4ZNU - 2017-10-25 | |
// Observe output bit on an oscilloscope | |
// LFSR info https://en.wikipedia.org/wiki/Linear-feedback_shift_register | |
// This code uses the Galois implementation | |
// Coefficients from https://users.ece.cmu.edu/~koopman/lfsr/index.html | |
#define PIN_RND 13 | |
#include <Entropy.h> | |
uint32_t Rnd; | |
byte LowBit; | |
void setup() { | |
Serial.begin(57600); | |
Serial.println("Random bit timing"); | |
Serial.println("Ed Nisley KE4ZNU - 2017-10-25"); | |
Entropy.initialize(); | |
pinMode(PIN_RND,OUTPUT); | |
uint32_t Seed = Entropy.random(); | |
Serial.print("Seed: "); | |
Serial.println(Seed,HEX); | |
randomSeed(Seed); | |
do { | |
Rnd = random(); | |
} while (!Rnd); // get nonzero initial value | |
} | |
void loop() { | |
// digitalWrite(PIN_RND,Rnd & 1); // about 55 us/bit | |
// Rnd = random(); | |
LowBit = Rnd & 1; | |
digitalWrite(PIN_RND,LowBit); // about 6 us/bit | |
Rnd >>= 1; | |
Rnd ^= LowBit ? 0x80000057ul : 0ul; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More details on my blog at http://wp.me/poZKh-78y