[sdiy] IIR Shift Filter problem - help with bug spotting in PIC ASM

Steve Lenham steve at bendentech.co.uk
Fri Mar 10 12:14:11 CET 2017


As I posted at around the same time, I reckon that you CAN mess with the
STATUS reg. However, it would be worth putting it to the test. How about
trying the following? It rotates the borrow bit in without inverting it,
then inverts the top four bits of the result instead:

WaveformSmoothing:
	; Subtract FILTER from new INPUT
	movf	FILTER_LO, w
	subwf	INPUT_LO, f	; INPUT = INPUT - FILTER
	movf	FILTER_HI, w
	subwfb	INPUT_HI, f

	; Borrow is zero if result required borrow (negative result)
	
	; Do the downshifts (x 1/16th effectively)
	rrf	INPUT_HI, f	; Rotate the borrow flag in unchanged
	rrf	INPUT_LO, f
	asrf	INPUT_HI, f	; Propagate it down to lower bits
	rrf	INPUT_LO, f
	asrf	INPUT_HI, f
	rrf	INPUT_LO, f
	asrf	INPUT_HI, f
	rrf	INPUT_LO, f	; 4 shifts total

  	movlw	0xF0
	xorwf	INPUT_HI, f	; Invert the four copies of borrow

	; Add it to FILTER
	movf	INPUT_LO, w
	addwf	FILTER_LO, f
	movf	INPUT_HI, w
	addwfc	FILTER_HI, f
	; We now have a smoothed copy of our INPUT in FILTER

This should at least narrow down where the problem lies. Do let us know
what happens - I should be working but am becoming obsessed with this :-)

Steve L.



On 10/03/2017 10:32, Tom Wiltshire wrote:
> Aha! Thanks! I'll give it a try.
>
> I didn't know you can't mess with the STATUS register. Why not? Why
> make the STATUS register available if I can't muck about with it?
>
> Tom
>
> On 10 Mar 2017, at 09:59, Roman Sowa <modular at go2.pl> wrote:
>
>> It struck me this morning when I looked at it again.
>>
>> You cannot xorwf the carry/borrow bit, that will never work. Only
>> clrc or setc can do that.
>>
>> I'm talking about this part:
>> ======================================================
>>
>> ; Borrow is zero if result required borrow (negative result) ; Flip
>> the state of the borrow flag movlw	0x01 xorwf	STATUS, f		; Borrow
>> set if negative
>> =======================================================




More information about the Synth-diy mailing list