I know HOW it works but trying to change it into C is being problematic..
The 10 bit ADC result is thrown through a "rolling average" and it's result should be representative of a 12 bit answer!!
I just can't make it work in C
It is written for the H8 532 Processor FBB0 through FBDE are ram locations FBB0~FBBE are the 10 bit results BEFORE the average and are 12 bit after!!!
Can anyone identify this simple algorithm??
The 10 bit ADC result is thrown through a "rolling average" and it's result should be representative of a 12 bit answer!!
I just can't make it work in C
It is written for the H8 532 Processor FBB0 through FBDE are ram locations FBB0~FBBE are the 10 bit results BEFORE the average and are 12 bit after!!!
Can anyone identify this simple algorithm??
Code:
; averaging
;
AVERAGING: MOV:G.B #H'08:8,R4 ; 8 inputs
MOV:G.W #H'FBB0:16,R5 ; ADCresults : FBB0 ~ FBBE
MOV:G.W #H'FBD0:16,R6 ; Rolling Sum : FBD0 ~ FBDE
AVERAGING1: MOV:G.W @R6,R2
MOV:G.W @R6,R3 ; Get rolling sum
SHLR.W R3
SHLR.W R3
SHLR.W R3 ; Divide by 8
SUB.W R3,R2 ; Remove from rolling sum
ADD:G.W @R5,R2 ; Add ADC result
MOV:G.W R2,@R6 ; Store rolling sum
SHLR.W R2
SHLR.W R2
SHLR.W R2 ; Divide by 8
MOV:G.W R2,@R5 ; Averaged ADC result
ADD:Q.W #2,R5 ; Next ADC result
ADD:Q.W #2,R6 ; Next rolling sum
ADD:Q.B #-1,R4 ;
BNE AVERAGING1
JMP @H'22A8 ; Done..