samedi 20 octobre 2018

Galois pseudo random number generator doen't work for 16-bit maximal-period in code composer studio

I am using MSP430FR5969 microcontroller with code composer studio IDE to make a pseudo-random number generator. I referred to this wikipedia page for that. It works fine with 8-bit but in case of 16-bit, the control doesn't go the lines after the do-while loop but instead go back to initialization block (for example: if I place a breakpoint at line uint16_t period = 0, it hits it).

Can someone explain this behavior?

Here is my code:

#include <stdint.h>
#include <msp430fr5969.h>
int main(void)
{
uint16_t lfsr = 0xACE1;  //any non-zero value is fine
uint16_t period = 0;
do
{
   /* taps: 16 14 13 11; characteristic polynomial: x^16 + x^14 + x^13 +   x^11 + 1 */
    unsigned lsb = lfsr & 1;
    lfsr >>= 1;                /* Shift register */
    if (lsb)
            lfsr ^= 0xB400;
    ++period;
} while(lfsr != ACE1);  //loop until random number becomes equal to starting value

return 0;
}

Thank you!




Aucun commentaire:

Enregistrer un commentaire