3–332
Motorola Sensor Device Data
For More Information On This Product,
Go to: www.freescale.com
{
unsigned int cntr; /* free running timer system counter */
unsigned int r0; /* difference between cntr and input capture 1 register */
unsigned int r1; /* difference between cntr and input capture 2 register */
unsigned int r2; /* difference between cntr and input capture 3 register */
unsigned long difference; /* the difference between the upper and lower
instrument amplifier outputs */
unsigned long int pfs; /* result defined as percent of full scale relative to
the reference voltage */
if (polarity == 1) /* set the hc4053 configuration */
PORTB &= 0xfe; /* polarity = 1 means + output of sensor */
else PORTB |= 0x1; /* is connected to the upper opamp */
delay(); /* this will allow the hc4053 to stabilize and the cap
to discharge from the previous conversion */
TFLG1=0X07; /* clear the input capture flags */
cntr=TCNT; /* get the current count */
PORTA &= 0X7F; /* turn the fet off */
while ((TFLG1 & 0X7) < 7); /* loop until all three input capture
flags are set */
r0 = TIC1 – cntr; /* reference voltage */
r1 = TIC2 – cntr; /* top side of the inst. amp */
r2 = TIC3 – cntr; /* lower side of the inst. amp */
PORTA |= 0X80; /* turn the fet on */
if (polarity == 1)
difference = ( r1 + 1000 ) – r2;
else difference = ( r2 + 1000 ) – r1;
pfs = (difference * 10000) / r0;
if (difference > 32767) /* this will cover up the case
where the a to d computes a
negative value */
pfs=0;
}
return ( pfs );
atod() /* computes the a/d value in terms of % full scale */
{
unsigned long int x,y,z;
x = convert(1); /* normal */
y = convert(0); /* reversed */
z = (x + y)>>1 ; /* 2x difference / 2 */
return(z); /* z is percent of full scale */
}
integrate() /* returns the a/d value in terms of % full scale and computes
offset from calibration values */
{
unsigned long int j;
int i;
j=0;
for (i=0; i<20; ++i)
j +=atod();
j = (j/20) – ADZERO; /* null out the xdcr zero input offset */
return(j);
}
cala2d() /* returns the average of 50 raw a/d conversions this is only
used by the calibration functions */
{
unsigned long int j;
int i;
j=0;
for (i=0; i<50; ++i)
{ j +=atod(); }
j=j/50;
return(j);
}
/* ################################################################### */
cvt_bin_dec ( unsigned int arg )
{
char i;
for ( i=0; i < 6; ++i )
F
Freescale Semiconductor, Inc.
n
.