piclist 1998\04\18\170527a >
Thread: 12 bit A to D +comparing
www.piclist.com/techref/index.htm?key=bit+comparing
picon face BY : marcel email (remove spam text)



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

<35390843.754E569@xs4all.nl> 7bit

See also: www.piclist.com/techref/index.htm?key=bit+comparing
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) 12 bit A to D +comparing

month overview.

new search...