Jump to content

SEQ_CORE_GenRandomNumber problem...


Alkex
 Share

Recommended Posts

Hi all,

I am working on a funky 14x10 dot matrix display for my next midibox and would like to program a random pattern animation.

I am using a  matrix of 14 anodes X 10 cathodes and would like to set the anodes high randomly at each Cathode shift, so I need a 1-14 random integer, but can't work the SEQ_CORE_GenRandomNumber...

I would greatly appreciate it if someone could guide me through this fonction ...

thanks in advance!

Best regards

Alkex

Link to comment
Share on other sites

Hi Alkex,

the usage of this function is very easy - each time you are calling it, a new random number will be put into SEQ_RANDOM_SEED_L and SEQ_RANDOM_SEED_H - you can extract a bit or a bitfield from these registers like you want. E.g., if you need a 7bit value, write:


    SET_BSR SEQ_BASE
    movf SEQ_RANDOM_SEED_L, W, BANKED
    andlw 0x7f      ; masks 7bit from the low-byte
[/code] In MBSEQ V3, I've optimized the function in following way:
[code]
;; --------------------------------------------------------------------------
;;  This function generates a new random number
;;  OUT: new random number in SEQ_RANDOM_SEED_[LH]
;; --------------------------------------------------------------------------
SEQ_CORE_GenRandomNumber
        SET_BSR SEQ_BASE
        movf    SEQ_RANDOM_SEED_L, W, BANKED
        mulwf  SEQ_RANDOM_SEED_H, BANKED
        movf    TMR0L, W
        addwf  PRODL, W
        movwf  SEQ_RANDOM_SEED_L, BANKED
        movlw  0x69
        addwfc  TMR1L, W
        addwfc  PRODH, W
        movwf  SEQ_RANDOM_SEED_H, BANKED
        return

by using the values of two different timers, the randomness is higher

Best Regards, Thorsten.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...