Stefanho Posted February 27, 2005 Report Posted February 27, 2005 Hello,i've got the following question:What is the best solution to scale the controller resolution from 0-127 to 0-100?I think this should be no problem. ??Greetings,Stefan Quote
TK. Posted February 27, 2005 Report Posted February 27, 2005 Hi Stefan,here an excerpt from the midibox64 application:;; --------------------------------------------------------------------------;; This function scales a 7bit value depending on a min and max value;; If the min value is greater than the max value, they will be;; automatically converted to realise a reversed scaling;; Input:;; o 7bit value in WREG;; o min value in MB64_POT_MIN_VALUE;; o max value in MB64_POT_MAX_VALUE;; Output:;; o scaled value in WREG and MIOS_PARAMETER1;; USES: MIOS_PARAMETER1 and MIOS_PARAMETER2;; --------------------------------------------------------------------------MB64_POT_ScaleValue ;; save pot value in MIOS_PARAMETER1 movwf MIOS_PARAMETER1 SET_BSR MB64_BASE ;; send min value if min == max movf MB64_POT_MIN_VALUE, W, BANKED IFNEQ MB64_POT_MAX_VALUE, BANKED, rgoto MB64_POT_ScaleValueDo movwf MIOS_PARAMETER1 rgoto MB64_POT_ScaleValue_EndMB64_POT_ScaleValueDo ;; set MIOS_PARAMETER2[0] if min > max bcf MIOS_PARAMETER2, 0 movf MB64_POT_MAX_VALUE, W, BANKED IFLEQ MB64_POT_MIN_VALUE, BANKED, rgoto MB64_POT_ScaleValue_NoConv bsf MIOS_PARAMETER2, 0MB64_POT_ScaleValue_NoConv ;; scaled value-1 = ((current value+1) * (max-min+1)) / 128 ;; swap max/min if MIOS_PARAMETER2[0] set ;; multiply current value * (max-min+1) IFSET MIOS_PARAMETER2, 0, rgoto MB64_POT_ScaleValue_InvMB64_POT_ScaleValue_NoInv movf MB64_POT_MIN_VALUE, W, BANKED subwf MB64_POT_MAX_VALUE, W, BANKED rgoto MB64_POT_ScaleValue_Cont1MB64_POT_ScaleValue_Inv movf MB64_POT_MAX_VALUE, W, BANKED subwf MB64_POT_MIN_VALUE, W, BANKED ;; rgoto MB64_POT_ScaleValue_Cont1MB64_POT_ScaleValue_Cont1 addlw 1 mulwf MIOS_PARAMETER1, ACCESS ; multiply with current value ;; divide result by 128 (result >> 7) ;; good trick: just shift the upper bit of the low byte into the high byte rlf PRODL, W rlf PRODH, W andlw 0x7f ;; add min or max value depending on MIOS_PARAMETER2[0] btfss MIOS_PARAMETER2, 0 addwf MB64_POT_MIN_VALUE, W, BANKED btfsc MIOS_PARAMETER2, 0 addwf MB64_POT_MAX_VALUE, W, BANKED ;; store result in MIOS_PARAMETER1 movwf MIOS_PARAMETER1MB64_POT_ScaleValue_End movf MIOS_PARAMETER1, W ;; return immediately if inversion bit not set IFCLR MIOS_PARAMETER2, 0, return ;; else inverse the result subwf MB64_POT_MIN_VALUE, W, BANKED addwf MB64_POT_MAX_VALUE, W, BANKED movwf MIOS_PARAMETER1 return[/code]Note: MB64_BASE is the base pointer to the page where MB64_POT_MIN_VALUE and MB64_POT_MAX_VALUE are located.Best Regards, Thorsten. Quote
Stefanho Posted February 28, 2005 Author Report Posted February 28, 2005 Hi,great news! Thank you! ;D I tested it with an encoder. Worked very well.Next step are motorfaders. Cheers,Stefan Quote
Stefanho Posted March 2, 2005 Author Report Posted March 2, 2005 Hello again,i've tested it with my motorfaders. If i move a fader it works as expected.But when i send a controller-message the fader jumps to the non scaled position (values 0..127). I use the Midibox64e application. I think, i have to modify "MB64E_FADER_Move" from "mb64e_fader.inc" ?The values, which are send to the midibox, range from 0..100.Regards,Stefan Quote
TK. Posted March 2, 2005 Report Posted March 2, 2005 Hi Stefan,yes, you have to scale back the value from 0-100 to 0-127Best Regards, Thorsten. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.