Message-ID: <353909C9.5959BE7E@xs4all.nl> Date: Sat, 18 Apr 1998 22:15:12 +0200 From: marcel X-Mailer: Mozilla 4.04 (Macintosh; I; PPC) MIME-Version: 1.0 To: "PICLIST@MITVMA.MIT.EDU" Subject: Re: 12 bit A to D +comparing References: <35390843.754E569@xs4all.nl> Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353" Content-Transfer-Encoding: 7bit marcel wrote: > I still have great difficulty on the folowing > it seems carry does not affect high byte > i am also not shure on testing for zero > i realy need help on this. > I am reading 12 bit of data from an potentiometer when it is in the > middle > it should give something like 0x0800 "hex" > when i turn left it decreases and when i turn right it increases > > I can get the data msb first in the registers datahi and datalo but > the LTC1286 allows also to read LSB first > > Maximum icrement or decrement must be no more than 0x7F > > Can annyone help me with this? > > Storlox equ 0x10 > Storhix equ 0x11 > ;Storloy equ 0x12 > ;Storhiy equ 0x13 > TmpReg1 equ 0x14 > TmpReg2 equ 0x15 > datalo equ 0x16 > datahi equ 0x17 > > movlw 0x30 > movwf datalo > movlw 0x01 > movwf datahi > movlw 0x20 > movwf Storlox > movlw 0x01 > movwf Storhix > clrf TmpReg1 > clrf TmpReg2 > > sub16 > > movf datalo,W ; subtract lsbs > subwf Storlox,W > movwf TmpReg1 > movf datahi,W ; subtract msbs > btfss status,C ; including any carry > incfsz Storhix,W > subwf datahi,W > movwf TmpReg2 > btfsc status,C ; new smaller? > goto smaller ; yes > goto larger ; no > > smaller movf TmpReg1,W > addwf TmpReg2,W > btfsc STATUS,Z > goto zero > bcf STATUS,Z > decf Storlox > goto sub16 > > larger incf Storlox > goto sub16 > > zero incf Storlox > goto sub16 > > I am totaly confused with carry's not going well > this makes me think to do somting in two complement like this > also totaly confusing > > Storlox equ 0x10 > Storhix equ 0x11 > ;Storloy equ 0x12 > ;Storhiy equ 0x13 > TmpReg1 equ 0x14 > TmpReg2 equ 0x15 > datalo equ 0x16 > datahi equ 0x17 > > movlw 0x30 ; new lowByte > movwf datalo ; > movlw 0x01 ; new highByte > movwf datahi > movlw 0x20 ; old lowByte > movwf Storlox > movlw 0x01 ; old highByte > movwf Storhix > clrf TmpReg1 ; Store diff > clrf TmpReg2 ; Store diff > > comf datalo,W ; two complement lowbyte > addlw 0x01 > movwf datalo > ;btfsc STATUS,C > ;incfsz datahi > comf datahi,W ;two complement higbyte > addlw 0x01 > movwf datahi > > cmp16 > movf datalo,W ; datalo>W > addwf Storlox,W ; add oldlobyte > movwf TmpReg1 ; store difference > movf datahi,W ; get new higbyte > btfsc STATUS,C ; test carry ifso > incfsz Storhix,W ; incf oldhighbyte > addwf Storhix,W > movwf TmpReg2 > btfss STATUS,C > goto smaller ; yes > goto larger ; no > > smaller movf TmpReg1,W > addwf TmpReg2,W > btfsc STATUS,Z > goto zero > bcf STATUS,Z > decf Storlox > goto cmp16 > > larger incf Storlox > goto cmp16 > > zero nop ; incf Storlox > goto zero > > I realy need help on this > > Marcel Elektronic workshop > Amsterdam