I am encountering a problem with processing shaft sensor signals.
When I am using the IQ math, there is a highly repeatable error in the output for several calls into the library.
_IQatan2PU
_IQdiv
_IQmpy
The following software is an implementation where an average sampling is desired.
The average is normalized and passed into the IQ math calls to determine shaft position.
First, two sinusoidal signals in quadrature from a magnetic sensor is sampled via AD7 & 8.
Then, the sample is normalized by dividing by the sampling mean.
Next, the two signals, one sine, the other cosine, are passed into the IQ math library
_IQatan2PU()
The return should be a absolute signal from -1 to 1 IQ24 depicting the shaft position from 0⁰ to 360⁰.
For purposes of elimination, I tried different IQ math functions to get similar results.
The example depicted is a _IQmpy of the same signal.
I am using the CAN peripheral to output signal information as close to real time as possible.
The Vector Canoe CAN protocol analyzer output depicts some form of saturation that is not understood.
Here the cal_shaft_ShaftPosition signal data depicts a simple multiply of the normalized cosine shaft signal.
#define SHAFT_LIMIT_SENSOR (0.01)
#define MAX_VELOCITY_SAMPLE_PWR (3)
#define MAX_VELOCITY_SAMPLE (1<<MAX_VELOCITY_SAMPLE_PWR)
CalShaft.Sine.ShaftPositionAccum += (long)ilg2_vdc1.ADC_conv8;
CalShaft.Cosine.ShaftPositionAccum += (long)ilg2_vdc1.ADC_conv7;
if ((CalShaft.NumVelocitySample++ % MAX_VELOCITY_SAMPLE) == 0)
{
CalShaft.Sine.DeltaShaftPosition = _IQmpyI32(scaler, (CalShaft.Sine.ShaftPositionAccum)>>MAX_VELOCITY_SAMPLE_PWR ) - CalShaft.sensor_offset;
CalShaft.Cosine.DeltaShaftPosition = _IQmpyI32(scaler, (CalShaft.Cosine.ShaftPositionAccum)>> MAX_VELOCITY_SAMPLE_PWR)- CalShaft.sensor_offset;
if ( (CalShaft.Cosine.DeltaShaftPosition < _IQ(SHAFT_LIMIT_SENSOR)) &&\
(CalShaft.Cosine.DeltaShaftPosition >= _IQ(0.0)))
{
CalShaft.Cosine.DeltaShaftPosition = _IQ(SHAFT_LIMIT_SENSOR);
}
else if ( (CalShaft.Cosine.DeltaShaftPosition > _IQ(-SHAFT_LIMIT_SENSOR)) &&\
(CalShaft.Cosine.DeltaShaftPosition <= _IQ(0.0)))
{
CalShaft.Cosine.DeltaShaftPosition = _IQ(-SHAFT_LIMIT_SENSOR);
}
else
{
}
if ( (CalShaft.Sine.DeltaShaftPosition < _IQ(SHAFT_LIMIT_SENSOR)) &&\
(CalShaft.Sine.DeltaShaftPosition >= _IQ(0.0)))
{
CalShaft.Sine.DeltaShaftPosition = _IQ(SHAFT_LIMIT_SENSOR);
}
else if ( (CalShaft.Sine.DeltaShaftPosition > _IQ(-SHAFT_LIMIT_SENSOR)) &&\
(CalShaft.Sine.DeltaShaftPosition <= _IQ(0.0)))
{
CalShaft.Sine.DeltaShaftPosition = _IQ(-SHAFT_LIMIT_SENSOR);
}
else
{
}
CalShaft.ShaftPosition = _IQmpy(CalShaft.Cosine.DeltaShaftPosition, CalShaft.Cosine.DeltaShaftPosition);
// CalShaft.ShaftPosition = _IQmpy(CalShaft.Sine.DeltaShaftPosition, CalShaft.Sine.DeltaShaftPosition);
// CalShaft.ShaftPosition = _IQmpy(CalShaft.Sine.DeltaShaftPosition, CalShaft.Sine.DeltaShaftPosition) +\
// _IQmpy(CalShaft.Cosine.DeltaShaftPosition,CalShaft.Cosine.DeltaShaftPosition);
// CalShaft.ShaftPosition = _IQdiv(CalShaft.Sine.DeltaShaftPosition, CalShaft.Cosine.DeltaShaftPosition);
// CalShaft.ShaftPosition = _IQatan2PU((CalShaft.Sine.DeltaShaftPosition), \
// (CalShaft.Cosine.DeltaShaftPosition));
CalShaft.Sine.PriorAccum = CalShaft.Sine.ShaftPositionAccum;
CalShaft.Cosine.PriorAccum = CalShaft.Cosine.ShaftPositionAccum;
CalShaft.Sine.ShaftPositionAccum = 0;
CalShaft.Cosine.ShaftPositionAccum = 0;
Code Composer Studio 3.3.38.2
Integrated Development 5.98.0.219 Texas Instruments
Bios 5.31.02
Code Generation tools 5.2.3
IQ Math Library version: 15a
Linker/Cmd file configuration for IQ math:
IQmath: LOAD = FLASHC,
RUN = RAMH0,
LOAD_START(_IQmathLoadStart),
LOAD_END(_IQmathLoadEnd),
RUN_START(_IQmathRunStart),
PAGE = 0
IQmathTables : > ROM PAGE = 0, TYPE = NOLOAD /* Math Tables In ROM */
IQmathTablesRam : > FLASHC PAGE = 0
Compiler Settings:
"C:\Program Files\Texas Instruments\C2000 Code Generation Tools 5.2.3\bin\cl2000" -g -pdsw225 -fr"../../CC_Build/Debug/obj" -i"../../src/include" -d"_DEBUG" -d"LARGE_MODEL" -ml -v28 -@"../../tools/code composer/Debug.lkf"
Linker Settings:
-z -a -c -m"../../CC_Build/Debug/DDM VW ProtoType.map" -o"../../CC_Build/Debug/DDM VW ProtoType.out" -stack0x100 -w -x -i"../../src/lib" -i"C:/CCStudio_v3.3.38.2/C2000/xdais/lib" -i"C:/CCStudio_v3.3.38.2/bios_5_31_02/packages/ti/bios/lib" -i"C:/CCStudio_v3.3.38.2/bios_5_31_02/packages/ti/rtdx/lib/c2000" -i"C:/Program Files/Texas Instruments/C2000 Code Generation Tools 5.2.3/lib" -l"Flash2808_API_V302.lib" -l"IQmath.lib"