=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Date: Mon, 18 Oct 1999 20:17:26 From: "Nikolai Golovchenko"To: "pic microcontroller discussion list" Subject: Re: 12c508 "random delay" -------------------------------------------------------------------------------- Hi Kev. >I need to generate a "random" delay between 0.5 and 10 second using 12c508 >int osc, prescaled at whatever! I think that you need an n-bit random number generator that would satisfy the number of steps in the interval. Here is an 8-bit example (sorry, no code). I came across it somewhere in TI's MSP430 application notes some time ago. rnd(n) = rnd(n-1)*mult+inc n - iteration number rnd(0)= 123 - seed number mult = 221 - multiplier inc = 53 - prime number (I modeled this in MATLAB. Looks ok) Note, that result may be greater than 8 bit. Just leave only lower 8 bits. This will generate pseudo-random sequence. Addition is not a problem. Multiplication too can be found in Microchip's apps. Bye.