LPC Demo Board Lessons
© 2005 Microchip Technology Inc. DS51556A-page 31
3.2.11 Lesson 11: Indirect Data Addressing
The FSR (File Select Register) allows the specifying of a file register address. A
subsequent read or write to the INDF (Indirect File register) refers to the file register
addressed by the FSR.
This may be used to implement a moving average filter. The moving average keeps a
list of the last n values and averages them together. The Filter needs two parts: A
circular queue and a function to calculate the average.
FIGURE 3-11: MOVING AVERAGES
Calculating averages in a mid-range PICmicro is best accomplished by using the FSR
to keep track of where the next value will be inserted. This ensures the oldest value is
always overwritten with the newest and doesn’t waste time moving values within the
memory.
EXAMPLE 3-10: FILE SELECT REGISTER EXAMPLE
Time
Average
n 105 102 101 104 99 103 105 107 103
n + 1 106 105 102 101 104 99 103 105 103
n + 2 110 106 105 102 101 104 99 103 104
Newest value inserted here
The rest move down one
Conceptual View
Implementation View
Time
Average
n 107 105 101 104 99 101 102 105 103
n + 1 106 105 102 101 99 101 102 105 103
n + 2 106 110 103 99 99 101 102 105 104
Pointer to oldest value
Older value overwritten, pointer advanced
Pointer advanced
;insert new value into a queue, enter with new value in
;Wreg
MOVF temp ;save the latest value
MOVF QueuePointer,w
MOVWF FSR ;load FSR with the queue pointer
MOVF temp,w
MOVWF INDF ;Write the latest value to the queue