Other Parts Discussed in Thread: TMS320F28069M, CONTROLSUITE
Hello,
I am programming microcontroller TMS320F28069M in order to read the value from a Hall capteur which sends to me 2 signals analogic sin and cos.
We can consider that the signals have the form:
S = A1. sin(Angle) + offset 1 and C = A2. cos(Angle) + offset 2
You can see a part of my code here
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
#include "math.h"
float16 gVoltage0[3]; //float16 = double
float16 gVoltage1[3];
float16 sinteta;
float16 costeta;
float16 gAngle0;
float16 gVerifier;
int16 gAngle;
Uint16 gcount;
...............
...............
gVoltage0[2] = (gVoltage0[2]/Adc_ValeurBits)*Adc_ValeurTension - Adc_Offset1;
gVoltage1[2] = (gVoltage1[2]/Adc_ValeurBits)*Adc_ValeurTension - Adc_Offset2;
// Valeurs de cosinus et sinus
sinteta = gVoltage0[2]/Adc_Ampli1;
costeta = gVoltage1[2]/Adc_Ampli2;
// Calibration des valeurs des cosinus
gVerifier = (sinteta)*(sinteta) + (costeta)*(costeta);
if ( (gVerifier > (1+Adc_CalibVerifier)) || (gVerifier <(1-Adc_CalibVerifier)))
{
if (costeta < 0)
{
costeta = - sqrt(1-sinteta*sinteta);
}
else costeta = sqrt(1-sinteta*sinteta) ;
}
// Calcul d'angle
gAngle0 = (atan2(sinteta,costeta)*180)/PI;
gAngle = ((int16) gAngle0) % 180 ;
"float16" is actually "double" data type
The results through Debug:
So, I used the atan2 function to calculate the angle, but the problem is that values of the Angle are expanded to its limits of data type. You can see that "Angle0" has the value of 1.231e+9, far more away its true value -41.76 degree. I tried the steps to calculate angle with atan2 in different program ( C-free 4.0) and it works well without problems in CCS.
What do I have to do to solve this problem ? Add or include some special libraries to CCS
Thanks,
Max