Jump to content

Recommended Posts

Posted

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

Posted

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...