;Compiler V3.5.2.7 ; With Filler[50] enabled. fails => Testing,278,278,213,164,127,100,79,64,52,44,37,32,278,278,278,278 ; With Filler[50] disabled. correct => Testing,278,278,213,164,127,100,79,64,52,44,37,32,94,140,174,200 Device = 16F916 ;8K Words,352 Ram, 256 EEPROM, 24IO, 8*10bitADC, LCD 16Seg, Comparator, 44pin TQFP @ CONFIG_REQ = 0 ; Override Compiler's configuration settings Asm- __Config 0x3094 ;FOSC_INTOSCIO & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_ON & CPD_OFF & BOREN_OFF & IESO_OFF & FCMEN_OFF & DEBUG_OFF Endasm- Declare Xtal = 4 Declare Keep_Hex_File = On Declare Rsout_Pin PORTA.4 ;Debug pin Declare Rsout_Mode 0 ;Connect to logic I/F lead Declare Serial_Baud 9600 Declare Rsout_Pace 0 ' Dim Filler[50] As Word ;Enable this line to make program fail Dim DigFilterIn As Word ;Current value. Input value to [all] filter(s) Dim DigFilDiff As Word ;Deviation of current value from smothed one Dim DigFilDiff_High As DigFilDiff.HighByte ;Point to high byte of DigFilDiff Word Dim DigFilterSign As Bit ;Sign of change 1=negative [Sign bit for Word value] Dim DigFilterOut As Word ;Smothed output from digital filter Dim DigFilterAcc As Word ;Accumulator for Filter Boot: ;Power on reset OSCCON = %01100000 ;4Mhz PORTA = %00010000 TRISA = %11101111 CMCON0 = %00000111 ; Make digital I/O, Comparator mode off, low power LCDCON = %00000000 ;Turn off "default" LCD functions for PortC PIC Hardware GoTo Main DigFil: DigFilDiff = DigFilterIn << 4 ;Calc difference from current smothed value DigFilDiff = DigFilDiff - DigFilterAcc ;Calc difference from current smothed value DigFilterSign = DigFilDiff_High.7 ;Get Sign of the diference (Topbit of word is signbit) DigFilDiff = Abs DigFilDiff ;Magnitude the difference DigFilDiff = DigFilDiff + 3 ;1/4 of the difference, or 1 or 0 (Dither adjust) DigFilDiff = DigFilDiff >> 2 ;1/4 of the difference, or 1 or 0 (Dither adjust) If DigFilterSign = 0 Then ;+ve change DigFilterAcc = DigFilterAcc + DigFilDiff ;Update smothed value Else ;-Ve DigFilterAcc = DigFilterAcc - DigFilDiff ;Update smothed value EndIf DigFilterOut = DigFilterAcc >> 4 ;/16 Generate new smoothed output value from filter RSOut ",",Dec DigFilterOut Return Init_Filter: ;Preload filter with current measuremet DigFilterOut = DigFilterIn ;Same as input value on init DigFilterAcc = DigFilterIn << 4 ;x16 Initialise accumulator starting value Return Main: RSOut "\r\nTesting" DigFilterIn =278 GoSub Init_Filter DataSet: DigFilterIn = 278 : GoSub DigFil DigFilterIn = 278 : GoSub DigFil ; DigFilterIn = 18 : GoSub DigFil DigFilterIn = 18 : GoSub DigFil DigFilterIn = 18 : GoSub DigFil DigFilterIn = 18 : GoSub DigFil DigFilterIn = 18 : GoSub DigFil DigFilterIn = 18 : GoSub DigFil DigFilterIn = 18 : GoSub DigFil DigFilterIn = 18 : GoSub DigFil DigFilterIn = 18 : GoSub DigFil DigFilterIn = 18 : GoSub DigFil ; DigFilterIn = 278 : GoSub DigFil DigFilterIn = 278 : GoSub DigFil DigFilterIn = 278 : GoSub DigFil DigFilterIn = 278 : GoSub DigFil ; While 1=1 Nop Wend End