I was playing with DT_Analog, and random variable set to 0 when I call GetADC.
This was happen only with long variable enabled.
So quick look and here is what happened:
Code:
#IF __LONG__
DTadAccum VAR LONG ; local - 32-bit sample accumulator
#ELSE
DTadAccum VAR WORD[2] ; local - 32-bit sample accumulator
#ENDIF
If I use PBPL then assembler use this line
DTadAccum VAR LONG ; local - 32-bit sample accumulator
And that is fine... Just declaring LONG var.
But later in code when Darrel clears accumulator:
Code:
DTadAccum = 0 : DTadAccum[1] = 0 ; clear the accumulator
So where is located DTadAccum[1]?
- 4 bytes after DTadAccum, and where was located my variables that get cleared after calling GetADC? You guessed...
Solution:
Replace
Code:
DTadAccum = 0 : DTadAccum[1] = 0 ; clear the accumulator
with
Code:
#IF __LONG__
DTadAccum = 0 ; clear the accumulator
#ELSE
DTadAccum = 0 : DTadAccum[1] = 0 ; clear the accumulator
#ENDIF
And that's all.
Bookmarks