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 ;http://www.piclist.com/techref/microchip/math/medfilsort-mc.htm ;The routine is perhaps excessive, but fixed ;my unstable adc values which the Median routine ;on it's own fixed partially cblock 0x20 temp temp0 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 endc ;*************************************** ; 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 return ;************************ ;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 return 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 skpnc 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 return A2 movf resultl,0 movwf analog2l movf resulth,0 movwf analog2h return A3 movf resultl,0 movwf analog3l movf resulth,0 movwf analog3h return A4 movf resultl,0 movwf analog4l movf resulth,0 movwf analog4h return A5 movf resultl,0 movwf analog5l movf resulth,0 movwf analog5h return A6 movf resultl,0 movwf analog6l movf resulth,0 movwf analog6h return A7 movf resultl,0 movwf analog7l movf resulth,0 movwf analog7h return A8 movf resultl,0 movwf analog8l movf resulth,0 movwf analog8h return A9 movf resultl,0 movwf analog9l movf resulth,0 movwf analog9h return A10 movf resultl,0 movwf analog10l movf resulth,0 movwf analog10h return A11 movf resultl,0 movwf analog11l movf resulth,0 movwf analog11h return A12 movf resultl,0 movwf analog12l movf resulth,0 movwf analog12h return A13 movf resultl,0 movwf analog13l movf resulth,0 movwf analog13h return A14 movf resultl,0 movwf analog14l movf resulth,0 movwf analog14h return A15 movf resultl,0 movwf analog15l movf resulth,0 movwf analog15h return
file: /Techref/microchip/med-a2d.htm, 4KB, , updated: 2005/2/3 17:03, local time: 2024/12/30 10:02,
3.146.206.87:LOG IN
|
©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? <A HREF="http://massmind.ecomorder.com/techref/microchip/med-a2d.htm"> PIC Microcontoller Input / Ouput Method Median Filtering A2D results</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to massmind.ecomorder.com! |
.