beautypg.com

Setcoefficients – Sensoray 118 User Manual

Page 23

background image

Sensoray Model 118 Smart A/D™ Instruction Manual

21

Commands: Channel Configuration

6.2.4 SetCoefficients

Defines linearization coefficients for a channel that was
previously declared for sensor type Custom Resistive
Sensor
(CRS).

Three coefficients are specified. The three values belong
to a polynomial of the following form:

The Smart A/D™ measures CRS channels by performing
an autoranging measurement of the sensor resistance.
The measured resistance is then transformed into
user-defined units by means of the above second-degree
polynomial expression. The resulting value is converted
to a 16-bit integer and stored in onboard memory. This is

the value that is returned to the host when the

GetSensorData

or

GetAllSensors

commands are

executed.

Declaring a channel as type CRS is practical for resistive
sensors subject to the following constraints:

Sensor resistance must not exceed the maximum
resistance that can be measured by the Smart A/D™.

A quadratic linearization polynomial is sufficiently
accurate for the application.

Each coefficient is expressed in the 4-byte form used
internally by the Smart A/D. The the

SendReal

function

(see Section 5.3) takes care of translating the coefficients
into the required internal format.

Driver

// Set the coefficients for the specified channel. The coefficients are

// passed to the driver function through an array.

VOID SetCoefficients( USHORT BasePort, UCHAR Channel, DOUBLE *pCoeffs )

{

SendByte( BasePort, Channel | CMD_SET_COEFFS );

for ( USHORT nCoef = 0; nCoef < 3; nCoef++ )

SendReal( BasePort, *pCoeffs++ );

}

Example

// Set the coefficients for channel 2, which is connected to a linear slide

// potentiometer whose position, P, is a function of resistance, R, as

// follows: P = -0.0023 * R^2 + 12.6 * R + 0.45. After executing this command,

// the GetSensorData and GetAllSensors commands will return the value P from

// this channel in the form of a signed 16-bit integer.

DOUBLE Coeffs[] = { -0.0023, 12.6, 0.45 };

SetCoefficients( MyBasePort, 2, Coeffs );

Command: (192 + Chan),(A0),(A1),(A2),(A3),(B0),(B1),(B2),(B3),(C0),(C1),(C2),(C3)

Response:

None

f R

( )

aR

2

bR

c

+

+

=

This manual is related to the following products: