| ??? 05/20/08 18:12 Read: times |
#154970 - How I solved my Midi Controller LSB Flicker/Flutte Responding to: ???'s previous message |
Hello, Sorry, I'm very noob to everything about microcontrollers, but some time ago I had the same problem with my midi controller, asked help here and received the best help I could in the world... Hans Van Pelt teached me a slack algorithm, http://www.8052.com/forum/read.phtml?id=144532
I will post the code I'm using today, I hope this helps: LinearControl is a feature I coded to interpolate the values, setting lin=0 it is disabled... setting lin>0 the controller will interpolate the previous value to the new one...
dir: dbit 1
.......
READPot:
CALL READADC ; Read ADC Value in A
MOV TH,A
MOV TP,@R0 ; Remember previous value
CLR C
SUBB A,TP ; Current - Previous
MOV dir,C
JNC ABSEND ; If carry: result was negative, CPL IT!
CPL A
INC A
ABSEND: CJNE A,#2,TRESADC ; Compare change to deadzone
TRESADC:JC INCI ; less than value. ignore
MOV A,lin
CJNE A,#0,LinearControl
MOV A,TH
JMP SEND0
LinearControl:
MOV A,TP
JNB dir,IncV
CLR C
SUBB A,#2
JMP SEND0
IncV: ADD A,#2
SEND0: MOV @R0,A ; Update ram value with new one
CALL SEND
|



