;***************************************************************** ;* Filename: DeltaSig.asm ;*****************************************************************;* Author: Dan Butler ;* Company: Microchip Technology Inc. ;* Revision: 1.00 ;* Date: 02 December 1998 ;* Assembled using MPASM V2.20 ;***************************************************************** ;* Include Files: ;* p16C622.inc V1.01 ;*****************************************************************;* Provides two functions implementing the Delta Sigma A2D. ;* InitDeltaSigA2D sets up the voltage reference and comparator ;* in the "idle" state. ;* DeltaSigA2D runs the actual conversion. Results provided in ;* result_l and result_h. ;* See An700 figure 2 for external circuitry required. ;*****************************************************************;* What's changed ;* ;* Date Description of change ;* ;***************************************************************** #include <p16C622.inc> cblock result_l result_h counter:2 endc ; ; ; InitDeltaSigA2D bsf STATUS,RP0 movlw 0xEC movwf VRCON bcf PORTA,3 ;set comparator pin to output bcf STATUS,RP0 movlw 0x06 ;set up for 2 analog comparators with common reference movwf CMCON return ; ; Delta Sigma A2D ; The code below contains a lot of nops and goto next instruction. These ; are necessary to ensure that each pass through the loop takes the same ; amount of time, no matter the path through the code. ; DeltaSigA2D clrf counter clrf counter+1 clrf result_l clrf result_h movlw 0x03 ; set up for 2 analog comparators with common reference movwf CMCON loop btfsc CMCON,C1OUT ; Is comparator high or low? goto complow ; Go the low route comphigh nop ; necessary to keep timing even bcf PORTA,3 ; PORTA.3 = 0 incfsz result_l,f ; bump counter goto eat2cycles ; incf result_h,f ; goto endloop ; complow bsf PORTA,3 ; Comparator is low nop ; necessary to keep timing even goto eat2cycles ; same here eat2cycles goto endloop ; eat 2 more cycles endloop incfsz counter,f ; Count this lap through the loop. goto eat5cycles ; incf counter+1,f ; movf counter+1,w ; andlw 0x04 ; Are we done? (We're done when bit2 of btfsc STATUS,Z ; the high order byte overflows to 1). goto loop ; goto exit eat5cycles goto $+1 ; more wasted time to keep the loops even nop ; goto loop ; exit movlw 0x06 ; set up for 2 analog comparators with common reference movwf CMCON return end