To make 10bit A/d into 8-bit, just shift right twice. That's it. --Bob At 11:33 PM 7/16/2003 -0500, you wrote: >Andy, just one question. How would you change the code to handle a 10-bit >a/d sample? Probably not necessary in the case where I'm determining fuel >level (1/256 is plenty of resolution), but I'm curious if it can be done >yet kept simple. I suppose I could really make the fuel gauge rock-steady >by using this algorithm along with sampling around 250ms or so... > >Regards, Bob > >Andrew Warren wrote .. > > Bob Japundza wrote: > > > > > I have been thinking about the tanks sloshing around as being > > > noisy signal, and that is one of the reasons why I've been > > > contemplating the median filter. Do you have a better suggestion? > > > > Seems to me that a straight low-pass filter would work well. > > > > > I tried an analog low-pass RC filter, and didn't have good luck > > > with it, because of the low resistance of the senders (30-240 ohm > > > Stewart-Warner float types) and not to mention it made me nervous > > > to have large caps tied to the fuel senders, in an airplane, no > > > less. > > > > Try a digital low-pass filter. Given a series of input samples > > in the range 0-255, this code (all 7 words of it) should perform > > a 256-sample moving-window average and give you the filtered > > result in AVEHI. > > > > ; Run this on every input sample. Enter with the new input > > ; sample in NEW. Exits with filtered result in AVEHI, and > > ; NEW unchanged. > > ; > > ; Might want to initialize AVEHI to something reasonable at > > ; program start; if it were me, I'd probably just initialize > > ; AVEHI to the first input sample. > > ; > > ; (WIDTH-1)*AVE + NEW > > ; AVE = ------------------- > > ; WIDTH > > > > AVEHI EQU [ANY FILE REGISTER] ;Holds the average [0-255]. > > AVELO EQU [ANY FILE REGISTER] ;Holds the fractional part > > ;of the average. > > NEW EQU [ANY FILE REGISTER] ;Holds the new sample. > > > > FILTER256: > > > > MOVF AVEHI,W > > SUBWF NEW,W > > SKPC > > DECF AVEHI > > ADDWF AVELO > > SKPNC > > INCF AVEHI > > > > -Andy > > > > === Andrew Warren -- aiw@cypress.com > > === Principal Design Engineer > > === Cypress Semiconductor Corporation > > === > > === Opinions expressed above do not > > === necessarily represent those of > > === Cypress Semiconductor Corporation > > > > -- > > http://www.piclist.com hint: PICList Posts must start with ONE topic: > > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > >-- >http://www.piclist.com hint: The list server can filter out subtopics >(like ads or off topics) for you. See http://www.piclist.com/#topics --------------- NOTICE 1. This account can accept email & attachments up to 10M in size. 2. Federal Monitors: At request of client, some attachments are encrypted. Please DO NOT delay traffic; please reply with credentials for password. -------------- -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics