cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Erimads
New Contributor II

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
Len_CONSULTRON
Honored Contributor II

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
MotooTanaka
Esteemed Contributor

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

Len_CONSULTRON
Honored Contributor II

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

Erimads
New Contributor II

Thanks for the answers both solution works for me now.