Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC generate random number using feedback shift register

Status
Not open for further replies.

the_merovingian

Member level 1
Joined
Jul 25, 2009
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
UK
Activity points
1,558
I'm interesting in generating some random numbers for one of my projects.

I have stumbled across the following code snippet:

https://www.phanderson.com/PIC/16C84/random.html

It appears to use feedback shift registers to generate a pseudo random sequence.

Does anyone have any thoughts / comments / better examples?

Many thanks in advance.
 

Thanks, I assume you're talking about:

https://www.microchip.com/forums/tm.aspx?m=445200&mpage=1&key=&#445200

In which they reference AN544 (Math Utility Routines):

https://ww1.microchip.com/downloads/en/AppNotes/00544d.pdf

Code:
0311      Random16
0311 1A19          rlcf   RandHi,W
0312 0C19          xorwf  RandHi,W
0313 1B0A          rlcf   WREG, F   ; carry bit = xorwf(Q15,14)
          ;
0314 1D19          swapf  RandHi, F
0315 1C18          swapf  RandLo,W
0316 230A          rlncf  WREG, F
0317 0C19          xorwf  RandHi,W  ; LSB = xorwf(Q12,Q3)
0318 1D19          swapf  RandHi, F
0319 B501          andlw  0x01
031A 1B18          rlcf   RandLo, F
031B 0D18          xorwf  RandLo, F
031C 1B19          rlcf   RandHi, F
031D 0002          return

I only needed 8bit number (above generates 16bits) but that's a good starting point thanks.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top