Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Trying to understand this snippet!

Status
Not open for further replies.

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
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??
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..
 
For anyone who took a look at this, I have missed a big part!!

The ADC was set up in scan mode ( I missed that ) each channel is rotated, byte swapped AND summed before the averaging routine..... It's going to take me a while longer to sort!!

Sorry for anyone who tried to make sense of this... If you are interested I'll post the answer some time soon..
 
Ian, I am interested and did take more than a passing glance at it. Of course, I have no experience with Hitachi syntax; although, the comments helped. I think I see what it is doing from an algorithm standpoint, but I didn't want to make a fool of myself, so I will wait.

John
 
Status
Not open for further replies.
Back
Top