Searching \ for '[Fwd: 12 bit A to D +comparing]' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: '12 bit A to D +comparing]'.

Exact match. Not showing close matches.
PICList Thread
'[Fwd: 12 bit A to D +comparing]'
1998\04\18@171537 by marcel

picon face
part 0 4358 bytes content-type:text/plain; charset=us-ascii; x-mac-type="54455854"; (decoded 7bit)

Message-ID: <>
Date: Sat, 18 Apr 1998 22:15:12 +0200
From: marcel <>
X-Mailer: Mozilla 4.04 (Macintosh; I; PPC)
MIME-Version: 1.0
Subject: Re: 12 bit A to D +comparing
References: <>
Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854";
Content-Transfer-Encoding: 7bit

marcel wrote:

{Quote hidden}

1998\04\19@124044 by Mike Keitz

picon face
On Sat, 18 Apr 1998 22:19:07 +0200 marcel <marbelspamspam_OUTXS4ALL.NL> writes (many

>> 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.

Subtraction on the PIC tends to confuse me.  I generally just use two
routines: "add" and "negate" (two's complement).  The "add" routine uses
the recently-discussed 'add with carry' sequence:

; Add 16-bit numbers A and B together, result in B (B=A+B).
       movfw   al
       addwf   bl,f
       movfw   ah
       incfsz  ah,w
       addwf   bh,f

The two's complement routine is straightforward as well:

; Negate (2's complement) 16-bit number in B (B = - B)
       comf    bl
       comf    bh
       incf    bl,f
       incf    bh,f
[Note that this routine can be extended to more bytes by adding another
complement instruction to the top and another incf / skpnz at the bottom.
But that isn't important right now.]

Using two's complement representation, an ordinary add will combine
positive and/or negative numbers correctly.  Positive numbers are just
binary numbers with the most significant (sign) bit zero.  Negative
numbers have the sign bit of one.  This makes it very easy to tell if a
result is positive or negative:

       btfsc   nh,7            ;Test high bit of n (sign bit)
       goto    num_neg         ;It's negative
       goto    num_pos         ;It's positive

The other bits in a negative number are not exactly the value in binary.
The "negate" routine will of course turn a negative number into a
positive one, also clearing the sign bit.

So to implement the "slew rate limiter" logic, do something like this
(not optimized at all):

A = oldval
B = newval
call negate  (B = - newval)
call add  (B = oldval - newval) -- Difference in reading
C = B (save difference for later)
If B positive, call negate (B = -|B|)
A = max change (0x80 in this case)
call add (B = max change - |difference|)
[If B negative now, difference is too large.  Setup to alter oldval
 by either the actual difference (C) or the maximum depending on if
 the difference is too large]

[If B negative]
A = oldval
B = max change
If C positive, call negate (make B = - max change)
call add
oldval = B

[If B positive- difference OK.  Note if you still have a copy of newval,
it could just be copied.]
A = oldval
B = C (oldval - newval)
call negate  (B = newval - oldval)
call add (B = oldval + newval - oldval = newval)
oldval = B

This should work, or at least get close.

You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at
Or call Juno at (800) 654-JUNO [654-5866]

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...