Hello people, I have finally solved the pot trouble. The fact that some pots didn’t reach 127 was a hardware problem, but what really was awkward was why they didn’t reach zero, sometimes.
That happened with ALL of them, and it did happen when I moved the pots SLOWLY down. It never happened in any pot when moved quickly down. Many other tests done, I concluded that it was not a soldering problem.
So, having no clues for something that puzzled me, I opted for the software solution.
I modified the MIOS_AIN_NotifyChange in main.asm (mb64) in order to have a small dead band up and down the pot and sliders way. The deadband is really small (32 of all 1024 steps in a 10bit ADC conversion), but was enough to fix the issue. Nonetheless, the code is adaptable to greater deadbands.
I’ll paste it here. It’s full of comments, heh, I think it’s more comments than code, actually. I wrote most of them to help myself in tracking what I was doing, it may be useful to someone, or maybe it’s useful for me that someone takes a look at it.
I’m really happy because it works, and because I learnt a lot while doing it. I did various versions, and this is the best of them, because it does the scaling from the whole 10bits the Pic delivers. That means that MB64 still doesn’t skip any value from 0 to 127, and that there are not “difficult” values to be output.
Here, the code:
;; --------------------------------------------------------------------------
;; This function is called by MIOS when a pot has been moved
;; Input:
;; o Pot number in WREG and MIOS_PARAMETER1
;; o lower byte value in MIOS_PARAMETER2
;; o upper byte value in MIOS_PARAMETER3
;; --------------------------------------------------------------------------
USER_AIN_NotifyChange
;;Reading= 1023 (max)
;;Scaled = ( Reading - 31 ) * (33 /32). I’m dividing by powers of two, to use bit shifts, so the next smaller ratio would be (65/64).
;; That would permit a smaller deadband, but maxreading (1023)*65 goes beyond the 2^16 (two byte) limit.
;;I will split the 31 values deadband in 16 low and 15 high.
;;Easier just to take into account the low deadband here, and limit higher than 127 values at the end of the process
; * if reading < (16) then reading = 16
; * for reading to be < 16, MIOS_PARAMETER3 must be 0, and MIOS_PARAMETER2 <=16
; *if MIOS_PARAMETER3 not zero, goto CONTINUE1
movlw 1;; w==127
IFGEQ MIOS_PARAMETER3, ACCESS, rgoto CONTINUE1
;*if MIOS_PARAMETER2 <=16 then MIOS_PARAMETER2 =16
movlw 16 ;
IFGEQ MIOS_PARAMETER2, ACCESS, rgoto CONTINUE1
movlw 16 ;
movwf MIOS_PARAMETER2
CONTINUE1
;----------------------------substract 16
;I substract 16 to put values on the range 0 - 1007. (That’s an 8 bit substraction from a 16 bit value. I took a model of a 16bit substraction and optimized it a little bit)
; movf SourceL,W ; ;;;;;;;THIS IS THE MODEL 16 bits---------------------
; subwf DestL; ;;;;;;of 16 bit substraction
; movf SourceH,W;
; btfss STATUS,C
; incfsz SourceH,W
; subwf DestH ; --------------------------------------------------------------------
movlw 16 ; ---------------------------------------------
subwf MIOS_PARAMETER2, F;substracts 16 from MIOS_PARAMETER2
movlw 0
btfss STATUS,C ; if result was positive or zero, SKIPs next instruction
decf MIOS_PARAMETER3, F; if negative, we need to substract 1 to the upper byte.
;; NOT NECESSARY________________ I’ll limit output to 127 after calculation is done
;;* if reading > (1023-15) then reading = 15
;; ______________________________
; * ---------------------multiply reading by 33.
; Result = upper byte*33+lower byte*33 (upper byte in MIOS_PARAMETER3 and lower byte in MIOS_PARAMETER2)
; * I know MIOS_PARAMETER3 will never be > 3 so, 3*33 = 99, I don’t need to care about PRODH
movf MIOS_PARAMETER3, W
mullw 33
;;movff PRODH, TMP1 -----------> Don’t care about PRODH
movff PRODL, TMP2; So, I have MIOS_PARAMETER3 * 33 in TMP2
movf MIOS_PARAMETER2, W ; Now, I multiply lower byte *33
mullw 33 ; Result in PRODH:L
; -------------------------------But I will have to divide by 256 (see below) so, I don’t care about PRODL, now.
;movf PRODL, W;----------PRODL would hold a resolution I won’t use
;addwf TMP2, F ;
movf PRODH, W; So, let’s add Original upper byte * 33 + the upper byte of the product of (ORIGINAL lower byte*33)
addwf TMP2, F;
; ----------------------* divide by 32.
;I should immediately divide by 8, so that’s a 256 divide, I can Just keep my upper byte.
; Keeping just the upper byte of my multiplication implies dividing by 32 and then by 8. That’s just what I needed
movff TMP2, MIOS_PARAMETER2 ;
;------------------------Now, let’s limit output to 127
; * if MIOS_PARAMETER2 > 127 then MIOS_PARAMETER2 =127
; If MIOS_PARAMETER2<=127 then goto CONTINUE 3
movlw 127;; w=127
IFLEQ MIOS_PARAMETER2, ACCESS, rgoto CONTINUE2
movlw 127
movwf MIOS_PARAMETER2 ;MIOS_PARAMETER2=127
CONTINUE2
;; FIN PABLO, end of my code
;; now: pot number in MIOS_PARAMETER1
;; 7-bit value in MIOS_PARAMETER2
#if DEFAULT_ENABLE_DRUMS
;; if drum trigger (MIOS_PARAMETER1 < 8) :
;; branch to the DRUMS module
movlw 8-1
IFLEQ MIOS_PARAMETER1, ACCESS, goto DRUMS_AIN_NotifyChange
#endif
;; else continue with MB64 pot handler
;; (expects number of pot in WREG)
movf MIOS_PARAMETER1, W
goto MB64_POT_Handler