please dont rip this site

SX Microcontroller Math Method

An 8bit software random number generator.

Andrew Warren [fastfwd at ix.netcom.com] of Fast Forward Engineering - San Diego, California says

Load a register called "RANDOM" with any non-zero value, then call this routine each time you'd like a new pseudo-random value:
LFSR:	mov	W, <<RANDOM
	mov	W, <<RANDOM
	snb	RANDOM.4
	xor	W, #1
	snb	RANDOM.5
	xor	W, #1
	snb	RANDOM.3
	xor	W, #1
	mov	RANDOM, W
	retw	#0

Scott Dattalo says:

[with the double left shift at the start of this routine,] Andy is implementing 'roll left' where the most significant bit of RANDOM will get copied to least significant position. This is how it works. The first
shift will copy the most significant bit of RANDOM into the carry. What ever was in the carry prior to the first shift will get copied into the least significant bit position - but we don't care. Also, since the destination is the W register, the variable RANDOM is unaffected. The second shift repeats the same rotate operation, but this time the carry has been initialized to the MS bit of random. So this second rotate will copy the MS bit into the least significant bit. All of the other bits are of course shifted left one bit position. See?

Or, if you prefer, you can use this routine (written by Marv Isaacman) instead:

MARV:	mov	W, #$1D
	clrb	C
	rl	RANDOM
	snb	C
	xor	RANDOM, W
	retw	#0

Hardware white noise generator

, design by dr. Imre Bartfai, 8/30/1999


 +--------------------------------------------------------------------- Vdd
 |                           220k                    220k               5V
 |                       +---\/\/\---+           +---\/\/\---+------+
 |                       |           |           |           |      |
 |                       |    |\     |           |    +------+      \
 | EFT317 PNP      +-----+----|- \   |           |    |             / 220k
 |      C          |     |    |    >-+----| |----+    |     |\      \
 |   |/            \  +-------|+ /        47n    |    +-----|- \    |
 +--B|        220k /  |  |    |/                 |    |     |    >--+
     |\            \  |  |  1/2 LM358            +----------|+ /    |
       |E          |  |  |                       |    |     |/      \
       +----| |----+--+  +                       +    +             /  47k
       |    47n    |     |                       |    | 1/2 LM358   \
       \           \     \                       \    \             |
  4k7  /        1M /     / 2k2                1M /    / 2k2         + out
       \           \     \                       \    \
       |           |     |                       |    |
       +-----------+-----+-----------------------+----+---------------- Vss

 Standard TTL can not be driven, but CMOS (and maybe LS) are o.k.
 The power supply must be filtered thoroughly due to the high gain!

Linear congruential sequence generator by Nikolai Golovchenko:

;Rnew = Rold * 221 + 53
;221 = 256 - 32 - 4 + 1
;256 can be eliminated
;so we need to calculate Rnew = Rold * (1 - 32 - 4) + 53 using
;truncating arithmetic
;or Rnew = Rold * (-32 - 3) + 53

        clrb    C
        rl      RANDOM                  ;RANDOM' = 2*RANDOM and carry contains the original MSb
        mov     W, <>RANDOM       
        and     W, #$E0                 ;W = 16*RANDOM'=32*RANDOM
        rr      RANDOM                  ;restore RANDOM
        add     W, RANDOM               
        add     W, RANDOM
        add     RANDOM, W               ;RANDOM'' = 32*RANDOM + 3*RANDOM
        not     RANDOM                  ;RANDOM''' = 255-RANDOM'' = -1 - RANDOM''
        mov     W, #54
        add     RANDOM, W               ;RANDOM''''=-1 - 32*RANDOM - 3*RANDOM + 54

See also:


file: /Techref/SCENIX/lib/math/rand_sx.htm, 4KB, , updated: 2004/6/10 13:40, local time: 2024/11/24 00:18,
TOP NEW HELP FIND: 
18.218.38.67:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/TECHREF/SCENIX/lib/math/rand_sx.htm"> SX Microcontroller Math Method - Random </A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .