This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Does it possible to produce repeat pattern by Random Number Generator of CC254x

Other Parts Discussed in Thread: CC2543, CC2544

Hello,

My hardware is the CC2543/44/45 and i use the random number generator to create unique address for each device.

Does it generate repeat pattern when i use the pseudo-random numbers generator?

Does it generate repeat pattern when i use the CRC16 to generate random number?

//-----code of the pseudo random number generator as below.

//----------------------------------------------------------------------------

    RNDL = seed;
    RNDL = seed;

  
    /* Main loop, generating pseudo-random numbers. */
    while(1)
    {
        /* Clock the LFSR once (13x unrolling) to generate pseudo-random bytes. 
         * Note the LFSR is clocked automatically when read from the [RFPSRND]
         * register.
         */
        ADCCON1 = (ADCCON1 & ~ADCCON1_RCTRL) | ADCCON1_RCTRL_LFSR13;
  
        /* Waiting for operation to complete (RCTRL = 00). */
        while (ADCCON1 & ADCCON1_RCTRL_COMPLETE);
  
        /* Storing the random number, debug to see the value. Done in two statements
        * to define the order of volatile accesses.
        */
        rndNumber1 = RNDL; 
        rndNumber |= (RNDH << 8);
    
        // Breakpoint used to read out rndNumber with the debugger.
        NOP();
    }

//----------------  end of the pseudo random number generator

//-----code of the CRC16 random number generator as below.

   RNDL = seed;
    RNDL = seed;

    /* Main loop, CRC16 calculation */
    while(1)
    {
    	  //  CRC16 calculation
        RNDH = number;  
  
        /* Storing the random number, debug to see the value. Done in two statements
        * to define the order of volatile accesses.
        */
        rndNumber = RNDL;
        //rndNumber |= (RNDH << 8);
    
        // Breakpoint used to read out rndNumber with the debugger.
        NOP();
    }

//----------------  end of the CRC16 random number generator

  • If you use the same seed all the time the pattern will reproduce eventually. You can instead use the radio to generate a seed to implement a true random number generator. If you only add a single seed and then just shift through the LFSR, the following pattern will be predictable when the seed is known.

    I will look into the time it takes for the bit sequence to repeat, it depends on the seed. What is the seed you are using?
  • Hello Eirik,

    Thanks for your reply.

    I use the same seed for now. But i am a little confuse that  you say it depend on the seed. you mean that even i use the same random generator algorithm, the different seed will get the different times of number repeat.( ex: Seed_A =>100 times it will repeat , Seed_B=> 500 times it will repeat.)

    Anyways my seed is set as below

    RNDL = 0x69;
    RNDH = 0x39;

    When i use the same seed and shift through the LFSR by pseudo or CRC16. How many times it will get the repeat pattern?( just like 1000 times it will repeat.) 

    I want to know the random number distribution. 

    thanks~!

    BR,

    Jack 

     

  • Hello Jack,
    To retrieve a series of pesudeorandom values you only need the following code where you will get a fresh new value from the least significatn byte of the LFSR each time. Reading the RFPSRND register is equivalent to reading RNDL, then writing 01 to ADCCON1.RCTL.

    RNDL = seed;
    RNDL = seed;

    /* Main loop, generating pseudo-random numbers. */
    while(1)
    {
    pseudoRandomNumber = RFPSRND;

    /* Waiting for operation to complete (RCTRL = 00). */
    while (ADCCON1 & ADCCON1_RCTRL_COMPLETE);

    // Breakpoint used to read out rndNumber with the debugger.
    NOP();
    }


    For some very simple explanations on LFSR look here:
    http://www.ti.com/lit/an/scta036a/scta036a.pdf

    There is also some interesting points mentioned in this thread:
    http://e2e.ti.com/support/wireless_connectivity/f/156/p/70903/257879#257879

    Read more about the generator in the CC2544 user guide in section Implement in "15.1 Introduction". Below you see the LFSR structure:


    The period of the pattern (number of values before repetition) depends on the feedback taps and the initial state (seed value). For a 16-bit LFSR it is theoretical possible to achieve a maximum pattern size of 2^16 which is called a maximum length sequence or m-sequence for short (pseudonoise PN). But this only happens for a LFSR with a certain configuration for the feedback taps/polynomial. The polynomial describing the taps must be a primitive polynomial which the CRC-16 is not. Therefore the sequence length produced before repetition occurs will be less than (2n-1) where n is the number of bits in the LFSR.

    For a general implementation to find the period of the pseudo-random pattern see my suggested code thtat follows. I have not tested it so there is a chance there is an error. By doing this you can find out how long the sequence of numbers are before it repeats. But for each clocking the LFSR is shifted 13 times meaning that you will need to perform the operation below 13 times and then read out the LSB (bit0 to bit 7 in LFSR) to get the values that are produces in the CC2544 application. So you can then divide the pattern length by 13 to get the actual sequence of pseudo-random bytes if you only read out the least significant Byte from the LFSR.

    A few notes to consider also is that 0x0000 or 0x8003 always leads to an unchanged value in the LFSR meaning that you will get an infinite sequence of either 0x0000 or 0x8003. When using the LFSR in random generator mode the LFSR will be unrolled 13 times for each clocking operation meaning that you will need to run the procedure within the do-while (seen below) 13 times before you read ou the least significant byte to get the same values as retrieved in the CC254x application.

    // CC254x Pseudo Random generator based on 16 bit LFSR with CRC-16 polynomial XOR tap configuration.
    uint16_t seed = 0xACE1; /* Any seed different from 0x0000 and 0x8003 will work. */
    uint16_t lfsr = seed;
    unsigned bit0, bit2, bit15;
    unsigned period = 0;

    /* For pseudo-random sequence generation each clocking of the LFSR results in 13 shifts with feedback.
    * The in_bit is equal to 0 for pseudo-random generation.
    * To simulate the pseudo-random generator in CC254xm, go through the procedure below 13 times before reading out the least significant bit (lfsr & 0x0F). */
    do
    {
    /* taps: 15 2; feedback polynomial: x^15 + x^2 + 1 */
    bit0 = (lfsr >> 15) & 0x01;
    bit2 = bit0 ^ ((lfsr >> 1) & 0x01)
    bit15 = ((lfsr >> 14) ^ bit0) & 0x01;
    lfsr = ((lfsr << 1) & 0x7B) | ( (bit15 << 15) | (bit2 << 2) | bit0);
    ++period;
    } while (lfsr != seed);

    while(1);

    You can run this code on any machine or you can for example use use matlab to calculate and store your sequence. I just googled and found this which might be of use, but i have not tested it:
    www.mathworks.com/.../76060-linear-feedback-shift-register-algorithm

  • Hello Eirik,

    Thank you for providing the requested information.
    And i will try to calculated the period of the pattern by your suggestion.

    BR,
    Jack