Simple random numbers

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Erimads
Level 2
Level 2
5 sign-ins First solution authored First like received

I am trying to get som random numbers from the PRS hardware.

But I get the same number every time.

How du I get different numbers ?

Ran1=PRS_Read();
Ran2=PRS_Read();
Ran3=PRS_Read();
Ran4=PRS_Read();
Ran5=PRS_Read()*256;

There is no PRS_Step() finction in Psoc_creator 4.4 as I can see.

Regards Erik

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Erik,

The PSoC GCC compiler also supports the ANSI rand() function.   This doesn't require any UDB resources like the PRS does.

I added the rand() call into moto-san's project.

Basic changes:

  • Added #include "stdlib.h"
  • Added the rand() to the snprintf() call.
Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

3 Replies
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi, 

 

Wow, I did not know that there is a component "PRS"!

Thank you for your asking 😉

 

It seems that most likely you forgot to call PRS_Start() before using PRS_Read().

I tested with CY8CKIT-059.

schematic

002-schematic.JPG

Pins

003-Pins.JPG

main.c

#include "project.h"
#include "stdio.h"
#define STR_BUF_LEN 64
char str[STR_BUF_LEN+1] ;

void print(char *str)
{
    UART_PutString(str) ;
}

int main(void)
{
    uint8_t prs_value = 0 ;
    
    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;
    print("\x1b[2J\x1b[;H") ;
    print("PSoC 5LP PRS Test ") ;
    snprintf(str, STR_BUF_LEN, "(%s %s)\n\r", __DATE__, __TIME__) ;
    print(str) ;
    
    PRS_Start() ;

    for(;;)
    {
        prs_value = PRS_Read() ;
        snprintf(str, STR_BUF_LEN, "%02X\n\r", prs_value) ;
        print(str) ;
        CyDelay(500) ;
    }
}

Tera Term log (uart output)

001-Tera_Term-Log.JPG

moto

lock attach
Attachments are accessible only for community members.
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Erik,

The PSoC GCC compiler also supports the ANSI rand() function.   This doesn't require any UDB resources like the PRS does.

I added the rand() call into moto-san's project.

Basic changes:

  • Added #include "stdlib.h"
  • Added the rand() to the snprintf() call.
Len
"Engineering is an Art. The Art of Compromise."

Thanks for the answers both solution works for me now.