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 …
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