Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    After reading your answer, I did some searching and realize that your answer is based on, quoted from wikipedia, "pseudo-random binary sequence (PRBS) generated by a linear feedback shift register (LFSR)". Any pointers to non-pure-maths (and simple) information on how to choose the "polynomial" (bit 24, 25, 29 and 31 in your example) so as to achieve the white-noise property? Commented Dec 28, 2014 at 18:29
  • The en.wikipedia.org/wiki/Linear_feedback_shift_register article points to tables of good polynomials for different bit-length shift registers at xilinx.com/support/documentation/application_notes/xapp052.pdf . The main difference between a good polynomial and a less good one is whether the length of the cycle until it repeats is as long as possible (2^n-1 is the max). users.ece.cmu.edu/~koopman/lfsr/index.html points to a table with 67,108,864 equally good 32 bit alternatives. Commented Nov 24, 2015 at 15:10
  • I think you need to edit unsigned long int newr; to be unsigned long int reg, newr; (and add const int speakerPin = 8;) Commented Jun 22, 2018 at 0:12
  • I'd really like to understand this anwser, but there is no explanation as to whats going on here. I don't know what the "reg" keyword is, nor what these bitwise operations are accomplishing, or why they aren't just defined, as they appear to be constants. On an Arduino, how is this better than using the "random" function with the values between the min and max frequency? Commented Feb 4, 2019 at 22:03
  • Also the shift register reg must be (a) defined as either a global or as static and (b) assigned an non-zero value. I used global: uint32_t reg = 0xfeedfaceUL ; . The solution in the answer by Dave X works without changes. Commented May 12, 2019 at 9:25