I simiplified your program and had it oputput to the terminal
Code:
Baud con i9600
Tx con s_out
tens var long
tensMax var long
tenscur var long
n var word
test:
gosub Mesurtension
SEROUT Tx, Baud, [dec tens," "]
gosub Mesurcourant
SEROUT Tx, Baud, [dec tenscur,13]
goto test
Mesurtension:
tensmax=0
FOR n=0 TO 19
;adin16 p0,tens
tens = 65535
tens = tens>>4
tensmax=tensmax+tens
NEXT
tens=tensmax/20*586/100
return
Mesurcourant:
;adin16 p3,tens
tens = 65535
tens = tens>>2
tenscur=tens*1000
return
The output is:
23996 16383000
I replaced the adin16 with the maximum 16bit value which is: 65535
The math checks out exactly like it should. This would indicate the problem is in the adin16 command or inte analog values being sent to it.
I'm looking at the ADIN command now.