please dont rip this site

PIC Microcontoller Input / Ouput Method

Median Filtering A2D results

From Louis Nel

; This document describes the assembly code routine
;to determine the average of 16 medians determined from 15 values each
; The code was used with a PIC16F876 running
;at 4MHz. The missing part of the code is the Median
;routine by Mehmet Çetin at
;The routine is perhaps excessive, but fixed
;my unstable adc values which the Median routine
;on it's own fixed partially

cblock 		0x20
			avg0		;average low byte
			avg1		;average high byte
			resultl		;result low byte same as in Median routine
			resulth		;result high byte same as in Median routine
; This routine determines the average
;of 16 medians that was determined
;using 15 ADC values each

AvgMedian 	Movlw	d'16'
			movwf temp
			clrf avg0
			clrf avg1
Alternative1 decf temp,1
			call StartADC			; Get 15 values
			call median				; Get median of the 15 values
			bcf status,c
			movf resultl,0
			addwf avg0,1			;add low byte to avg0
			btfss status,c
			goto Alternative2
			incf avg1,1
Alternative2 movf resulth,0
			addwf avg1,1			;add high byte to avg1
			movf temp,0
			btfss status,z
			goto Alternative1		;Get next median
			goto Divide16
Divide16	bcf status,c
			rrf avg0,1				;Divide2
			bcf status,c
			rrf avg1,1
			btfss status,c
			goto Alternative3
			bsf avg0,7
Alternative3 bcf status,c
			rrf avg0,1				;Divide 4
			bcf status,c
			rrf avg1,1
			btfss status,c
			goto Alternative4
			bsf avg0,7
Alternative4 bcf status,c
			rrf avg0,1				;Divide 8
			bcf status,c
			rrf avg1,1
			btfss status,c
			goto Alternative5
			bsf avg0,7
Alternative5 bcf status,c
			rrf avg0,1				;Divide 16
			bcf status,c
			rrf avg1,1
			btfss status,c
			goto Alternative6
			bsf avg0,7
Alternative6	movf avg0,0				; Put average value back in result
			movwf resultl
			movf avg1,0
			movwf resulth

;Reading 15 ADC values
;succesively from AN0
startADC	movlw d'15'				;for 15 analog values
			movwf temp0
StartB1		decf temp0,1
			movlw b'01000001'		; Fosc/8, AN0
			movwf adcon0
			call dely           			;acquision time to charge capacitor
	        	bsf adcon0,2           	 	;set GO bit in ADCON0
	        	call test 				; Test to see when done and prepares values for Median
			movf temp0,0
			btfss status,z
			goto startB1

test    		btfsc adcon0,2         	;test go flag to see if AD is done/cleared
        		goto test
convert		bsf status,5            		;goto bank1 Begin 
	        	bcf status,6
			movf adresl,0
			bcf status,5				;go to bank0
			movwf resultl			;temp 
			movf adresh,0
			movwf resulth
tablez  		movlw high tablezz
	        	movwf 0Ah               	;movwf PCLATH
	        	movlw low tablezz
	        	addwf temp0,0           	;add low byte to place
			incf 0Ah,1				
	        	movwf 02h               	;Increment PCL
tablezz 		goto A1
	        	goto A2
			goto A3
			goto A4
			goto A5
			goto A6
			goto A7
			goto A8
			goto A9
			goto A10
			goto A11
			goto A12
			goto A13
			goto A14
			goto A15
A1			movf resultl,0
			movwf analog1l
			movf resulth,0
			movwf analog1h
A2 			movf resultl,0
			movwf analog2l
			movf resulth,0
			movwf analog2h	
A3 			movf resultl,0
			movwf analog3l
			movf resulth,0
			movwf analog3h	
A4			movf resultl,0
			movwf analog4l
			movf resulth,0
			movwf analog4h	
A5 			movf resultl,0
			movwf analog5l
			movf resulth,0
			movwf analog5h		
A6			movf resultl,0
			movwf analog6l
			movf resulth,0
			movwf analog6h
A7			movf resultl,0
			movwf analog7l
			movf resulth,0
			movwf analog7h
A8			movf resultl,0
			movwf analog8l
			movf resulth,0
			movwf analog8h
A9			movf resultl,0
			movwf analog9l
			movf resulth,0
			movwf analog9h
A10			movf resultl,0
			movwf analog10l
			movf resulth,0
			movwf analog10h
A11			movf resultl,0
			movwf analog11l
			movf resulth,0
			movwf analog11h
A12			movf resultl,0
			movwf analog12l
			movf resulth,0
			movwf analog12h
A13	 		movf resultl,0
			movwf analog13l
			movf resulth,0
			movwf analog13h	
A14			movf resultl,0
			movwf analog14l
			movf resulth,0
			movwf analog14h
A15			movf resultl,0
			movwf analog15l
			movf resulth,0
			movwf analog15h

file: /Techref/microchip/med-a2d.htm, 4KB, , updated: 2005/2/3 18:03, local time: 2024/6/19 04:09,

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF=""> PIC Microcontoller Input / Ouput Method Median Filtering A2D results</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2024 contributors:
o List host: MIT, Site host, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!