I would like to use the N2HET on the RM48 MCU to measure angular velocity (i.e. shaft rpm), where the frequency of the tach signal can have a relatively wide range - from hundreds to tens of thousands rpm. I definitely want to avoid firing off interrupts on every edge. I wrote the following HET program, containing 5 instructions:
; Edge counter
EDGE0_Detect ECNT { prv=ON, pin=IO_PIN0, event=RISE, reg=A, irq=OFF, data=0 }
; Signaling counter
EDGE0_Signal CNT { reg=B, max=NUMLR_IN_IRQ, data=0 }
; At signaling time
EDGE0_IsSignal BR { next=PIN0_End, cond_addr=EDGE0_Save, event=ZERO, irq=ON }
; Save edge counter value
EDGE0_Save ADD { src1=A, src2=ZERO, dest=IMM, data=0, hr_data=0 }
; Reset edge counter
EDGE0_Reset MOV32 { remote=EDGE0_Detect, type=IMTOREG&REM, reg=A, data=0, hr_data=0 }
The program counts signal edges as they occur and, at a lower fixed frequency of my choice (defined by NUMLR_IN_IRQ parameter), fires off an interrupt, saves the counter value, and resets the edge counter. The interrupt handler in my program will then read the counter value from the data field of EDGE0_Save and divide it by (NUMLR_IN_IRQ * LRPeriod) to obtain the number of edges per unit of time.
I was wondering if this or similar can be accomplished with less than 5 HET instructions.
Thanks,
Marius