Exact match. Not showing close matches.
'[PIC]: Need help with 24F/30F/33F PICs extendedpre'
At 05.59 2008.07.14, you wrote:
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
1: CLR.W W0
; if (adc>=min) then out=65535
3: MOV.W #0xFFFF,W0
MOV.W max_l,W0 ; W1:W0 = max - min
LSR.W W0,#8,W0 ; W3 = W1:W0 / 256
MOV.W adc_l,W0 ; W1:W0 = adc - min
SL.W W1,#8,W1 ; W1:W0 *= 256
MOV.W #0xFFFF,W0 ; overflow DIV, set out to 65535 (happens only on few top values)
> 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
> 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
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014. Gold level PIC consultants since 2000.
I think we have to find out what OP wanted to say from the equations, which
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);
whichever way you like.
On Mon, Jul 14, 2008 at 8:18 PM, Olin Lathrop <embedinc.com> olin_piclist
More... (looser matching)
- Last day of these posts
- In 2008
, 2009 only
- New search...