Sometimes when you post an idea someone else comes along and shows you something you missed. Is their a faster way to perform this? I'm planning to use pre solved values for m and b.
Y=mX+b
(Fractional Interger Compensation)=2^16 Used to avoid floating point math
For analog input
X=Input value(from ADC)
m=(Fractional Interger Compensation)*(Maximum output-Minimum output)/(Maximum input-Minimum input)
b=-(Fractional Interger Compensation)*Minimum input
Y=Output Value (to memory)
For analog output
X=Input value(from memory)
m=(Fractional Interger Compensation)*(Maximum output-Minimum output)/(Maximum input-Minimum input)
b=-(Fractional Interger Compensation)*Minimum input
Y=Output value (to DAC)
The Math
RAW_working=Input value
RAW_working=RAW_working*m
RAW_working=RAW_working+b
Result=RAW_working/(2^16) No processing required as result is located in upper half of RAW_working
16 bit Input_Reading Located within RAW_working (Low bytes)
32 bit RAW_working
16 bit Result Located within RAW_working (high bytes)
32 bit signed m
32 bit signed b
___________________________
This message was ported from CCS's old forum
Original Post ID: 13507
Tomi Guest
Re: Linear Analog Calibration
Posted: Wed Apr 09, 2003 1:57 am
Yes, it is fast and simple. I use a same method with some differences:
1. I use Y = (1+m)*X + b so if the linearity error is zero (m=0) then no math necessary but an addition.
2. "m" is defined as N/8192 (I use 16-bit arithmetics because the original code was developed for 12CE519 / CCS C V2.61? , no int32 ).
So to divide the value by 2: N=-4096, to double it: N=8192, to keep unchanged: N=0, etc.
But with V3.XXX and int32 you are right, N/65536 is much simpler (and I use it, too ).
:=Sometimes when you post an idea someone else comes along and shows you something you missed. Is their a faster way to perform this? I'm planning to use pre solved values for m and b.
:=
:=Y=mX+b
:=(Fractional Interger Compensation)=2^16 Used to avoid floating point math
:=
:=For analog input
:=X=Input value(from ADC)
:=m=(Fractional Interger Compensation)*(Maximum output-Minimum output)/(Maximum input-Minimum input)
:=b=-(Fractional Interger Compensation)*Minimum input
:=Y=Output Value (to memory)
:=
:=For analog output
:=X=Input value(from memory)
:=m=(Fractional Interger Compensation)*(Maximum output-Minimum output)/(Maximum input-Minimum input)
:=b=-(Fractional Interger Compensation)*Minimum input
:=Y=Output value (to DAC)
:=
:=The Math
:=RAW_working=Input value
:=RAW_working=RAW_working*m
:=RAW_working=RAW_working+b
:=Result=RAW_working/(2^16) No processing required as result is located in upper half of RAW_working
:=
:=16 bit Input_Reading Located within RAW_working (Low bytes)
:=32 bit RAW_working
:=16 bit Result Located within RAW_working (high bytes)
:=32 bit signed m
:=32 bit signed b
___________________________
This message was ported from CCS's old forum
Original Post ID: 13526
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum