CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Linear Analog Calibration

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Linear Analog Calibration
PostPosted: Tue Apr 08, 2003 12:25 pm     Reply with quote

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
PostPosted: Wed Apr 09, 2003 1:57 am     Reply with quote

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

:=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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group