Jan 23, 2013
By David Van Ess
The way I have previously built pseudo random number generators is to take a register of some width and toggle some bits if the MSBit is 1. Then circular rotate left (MSBit becomes LSBit). The bits needed to be toggled, differ with the length of the register.
That is:
forever{
if( MSBit == 1) toggle some bits;
circular rotate left
}
This implementation has the problem that if the register value is zero, it remains zero. This means for an 8 bit register, you get pseudo random values between 1 and 255.
Instead I changed the process so that the bits are toggled if the MSBit is 0.
forever{
if( MSBit != 1) toggle some bits;
circular rotate left
}
It can be implements with two of the datapath registers
A0 = (A0 ^ D) <<1 (so conneted to si)
A0 = A0 <<1 (so connected to si)
Add two more states of A0=0 and you have a fix is case the register somehow gets a ff value.
Gawd I love datapaths!
Now the dead value is all ones and the PSoC logic starts up logic low. So for an 8 bit register, you get random values between 0 and 254. This is nicer for density signal generation. You do not have to initialize this hardware as it will start up with its initial values.