Searching \ for '[PIC]: Need help with 24F/30F/33F PICs extendedpre' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Need help with 24F/30F/33F PICs extendedpre'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Need help with 24F/30F/33F PICs extendedpre'
2008\07\14@100906 by Electron

flavicon
face

Dear Vitaliy,


At 05.59 2008.07.14, you wrote:
{Quote hidden}

I received many answers (for which I'm grateful), but none addressed my request,
although I think was quite clear. But since you're asking explicitly, I will
gladly answer, thinking I'm not boring at least you. ;)


>AFAIK, few applications require more than 8-bit precision.

Well, when you use a 24bit ADC then you in the first instance needed precision.
However, I've done my math and by maximixing precision (shifting left the data
before division to get maximum precision even from 32bit), I've been able to make
it work satisfactorily with 32bit math. This is what I produced, I've tested it
beside a PC running the same formula, and it works the same (that was my main
concern). In the hope it may be useful to anyone I'm posting it here:

; if (adc<=min) then out=0
                       MOV.W           #adc_h,W2
                       MOV.W           #min_h,W3
                       MOV.W           [W2--],W0
                       MOV.W           [W3--],W1
                       CP.W            W0,W1
                       BRA             LTU,1f
                       BRA             GTU,2f
                       MOV.W           [W2],W0
                       MOV.W           [W3],W1
                       CP.W            W0,W1
                       BRA             GTU,2f
1:                      CLR.W           W0
                       BRA             5f
2:
; if (adc>=min) then out=65535
                       MOV.W           #adc_h,W2
                       MOV.W           #max_h,W3
                       MOV.W           [W2--],W0
                       MOV.W           [W3--],W1
                       CP.W            W0,W1
                       BRA             GTU,3f
                       BRA             LTU,4f
                       MOV.W           [W2],W0
                       MOV.W           [W3],W1
                       CP.W            W0,W1
                       BRA             LTU,4f
3:                      MOV.W           #0xFFFF,W0
                       BRA             5f
4:
; out=((adc-min)*256)/((max-min)/256)
                       MOV.W           max_l,W0                  ; W1:W0 = max - min
                       MOV.W           min_l,W2
                       SUB.W           W0,W2,W0
                       MOV.W           max_h,W1
                       MOV.W           min_h,W2
                       SUBB.W          W1,W2,W1
                       LSR.W           W0,#8,W0                  ; W3 = W1:W0 / 256
                       SL.W            W1,#8,W1
                       IOR.W           W1,W0,W3
                       MOV.W           adc_l,W0                  ; W1:W0 = adc - min
                       MOV.W           min_l,W2
                       SUB.W           W0,W2,W0
                       MOV.W           adc_h,W1
                       MOV.W           min_h,W2
                       SUBB.W          W1,W2,W1
                       SL.W            W1,#8,W1                  ; W1:W0 *= 256
                       LSR.W           W0,#8,W2
                       IOR.W           W2,W1,W1
                       SL.W            W0,#8,W0
                       REPEAT          #17
                       DIV.UD          W0,W3
                       BRA             NOV,5f
                       MOV.W           #0xFFFF,W0                ; overflow DIV, set out to 65535 (happens only on few top values)
5:

Cheers,
Mario


>
>Vitaliy
>
>-

2008\07\14@151630 by olin piclist

face picon face
Electron wrote:
> I received many answers (for which I'm grateful), but none addressed
> my request, although I think was quite clear.

If everyone mistunderstood the question, just maybe you should consider the
question was poorly worded.

I still don't understand how this isn't just a scaling problem after a
subtraction.

> However, I've done my math and by maximixing precision (shifting left
> the data
> before division to get maximum precision even from 32bit), I've been
> able to make
> it work satisfactorily with 32bit math.

Sounds exactly like one of the suggestions I made.  I guess my answer wasn't
clear enough.


********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000.

2008\07\14@180634 by Tamas Rudnai

face picon face
I think we have to find out what OP wanted to say from the equations, which
was:

> out=(adc-min)*65536/(max-min);

So I guess max-min could be less or greater than 65536, but even then the
number have to be evenly scaled over the full 16bit range, right?

Multiply by 2^16 is equal to shift by 16 bits, so the storage needed from
the 24 bits is 24+16 bit, which is 40. You have 32 and 64 bit sizes
supported by C30 so I guess you have no other choice than use 64 bit. But I
think you would need to cast at least the constant to 64bit number to make
sure it will use that:

out=(adc-min)*(unsigned long long)65536/(max-min);

or

out=(adc-min)*65536ULL/(max-min);

whichever way you like.

Tamas




On Mon, Jul 14, 2008 at 8:18 PM, Olin Lathrop <spam_OUTolin_piclistTakeThisOuTspamembedinc.com>
wrote:

{Quote hidden}

> -

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