TI中文支持网
TI专业的中文技术问题搜集分享网站

是CCS的buge 还是其他什么原因?

定义一个联合体:

typedef union FACTORY_TEST
{
uint16_t  All[4];
struct

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}code;
}FACTORYT;

FACTORYT FactoryTest

FactoryTest.code.IQ_FullScale_V = 160;
FactoryTest.code.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 160.0;

显然结果不是期望的·Value = 1.0

不用联合,直接用结果:

typedef struct FACTORY_TEST
{

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}FACTORYT;

FACTORYT FactoryTest

FactoryTest.IQ_FullScale_V = 160;
FactoryTest.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 1..0;

是期望的结果。

CCS 为6.2,编译器为c2000_15.12.3.LTS

dsp为 F28069M

出现这一问题的原因是什么?是否是CCS自身编译器的问题?

min zhou2:

上面写错了,是:

_iq  Value_Mb = (_iq)(FactoryTest.code.IQ_FullScale_V);_iq  Value_Ma = (_iq)(FactoryTest.code.ADC_FullScale_V1); 

_iq  Value_Mb = (_iq)(FactoryTest.IQ_FullScale_V);_iq  Value_Ma = (_iq)(FactoryTest.ADC_FullScale_V1); 

用后者,结果正确

定义一个联合体:

typedef union FACTORY_TEST
{
uint16_t  All[4];
struct

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}code;
}FACTORYT;

FACTORYT FactoryTest

FactoryTest.code.IQ_FullScale_V = 160;
FactoryTest.code.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 160.0;

显然结果不是期望的·Value = 1.0

不用联合,直接用结果:

typedef struct FACTORY_TEST
{

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}FACTORYT;

FACTORYT FactoryTest

FactoryTest.IQ_FullScale_V = 160;
FactoryTest.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 1..0;

是期望的结果。

CCS 为6.2,编译器为c2000_15.12.3.LTS

dsp为 F28069M

出现这一问题的原因是什么?是否是CCS自身编译器的问题?

Seven Han:

您用c2000_16.9.1.LTS编译器试试!

定义一个联合体:

typedef union FACTORY_TEST
{
uint16_t  All[4];
struct

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}code;
}FACTORYT;

FACTORYT FactoryTest

FactoryTest.code.IQ_FullScale_V = 160;
FactoryTest.code.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 160.0;

显然结果不是期望的·Value = 1.0

不用联合,直接用结果:

typedef struct FACTORY_TEST
{

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}FACTORYT;

FACTORYT FactoryTest

FactoryTest.IQ_FullScale_V = 160;
FactoryTest.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 1..0;

是期望的结果。

CCS 为6.2,编译器为c2000_15.12.3.LTS

dsp为 F28069M

出现这一问题的原因是什么?是否是CCS自身编译器的问题?

Seven Han:

回复 min zhou2:

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1);

改为

_iq  Value_Mb = (_iq)(FactoryTest.IQ_FullScale_V);_iq  Value_Ma = (_iq)(FactoryTest.ADC_FullScale_V1);

定义一个联合体:

typedef union FACTORY_TEST
{
uint16_t  All[4];
struct

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}code;
}FACTORYT;

FACTORYT FactoryTest

FactoryTest.code.IQ_FullScale_V = 160;
FactoryTest.code.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 160.0;

显然结果不是期望的·Value = 1.0

不用联合,直接用结果:

typedef struct FACTORY_TEST
{

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}FACTORYT;

FACTORYT FactoryTest

FactoryTest.IQ_FullScale_V = 160;
FactoryTest.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 1..0;

是期望的结果。

CCS 为6.2,编译器为c2000_15.12.3.LTS

dsp为 F28069M

出现这一问题的原因是什么?是否是CCS自身编译器的问题?

min zhou2:

回复 Seven Han:

上面说过:

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1);

是写错了,测试程序是:

_iq  Value_Mb = (_iq)(FactoryTest.IQ_FullScale_V);_iq  Value_Ma = (_iq)(FactoryTest.ADC_FullScale_V1);

这问题很奇怪!!!!

定义一个联合体:

typedef union FACTORY_TEST
{
uint16_t  All[4];
struct

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}code;
}FACTORYT;

FACTORYT FactoryTest

FactoryTest.code.IQ_FullScale_V = 160;
FactoryTest.code.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 160.0;

显然结果不是期望的·Value = 1.0

不用联合,直接用结果:

typedef struct FACTORY_TEST
{

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}FACTORYT;

FACTORYT FactoryTest

FactoryTest.IQ_FullScale_V = 160;
FactoryTest.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 1..0;

是期望的结果。

CCS 为6.2,编译器为c2000_15.12.3.LTS

dsp为 F28069M

出现这一问题的原因是什么?是否是CCS自身编译器的问题?

min zhou2:

回复 min zhou2:

你们能否试试?

定义一个联合体:

typedef union FACTORY_TEST
{
uint16_t  All[4];
struct

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}code;
}FACTORYT;

FACTORYT FactoryTest

FactoryTest.code.IQ_FullScale_V = 160;
FactoryTest.code.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 160.0;

显然结果不是期望的·Value = 1.0

不用联合,直接用结果:

typedef struct FACTORY_TEST
{

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}FACTORYT;

FACTORYT FactoryTest

FactoryTest.IQ_FullScale_V = 160;
FactoryTest.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 1..0;

是期望的结果。

CCS 为6.2,编译器为c2000_15.12.3.LTS

dsp为 F28069M

出现这一问题的原因是什么?是否是CCS自身编译器的问题?

min zhou2:

回复 min zhou2:

我换成V6.4.12编译器,问题相同!!

原因到底在哪儿?

定义一个联合体:

typedef union FACTORY_TEST
{
uint16_t  All[4];
struct

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}code;
}FACTORYT;

FACTORYT FactoryTest

FactoryTest.code.IQ_FullScale_V = 160;
FactoryTest.code.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 160.0;

显然结果不是期望的·Value = 1.0

不用联合,直接用结果:

typedef struct FACTORY_TEST
{

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}FACTORYT;

FACTORYT FactoryTest

FactoryTest.IQ_FullScale_V = 160;
FactoryTest.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 1..0;

是期望的结果。

CCS 为6.2,编译器为c2000_15.12.3.LTS

dsp为 F28069M

出现这一问题的原因是什么?是否是CCS自身编译器的问题?

Jun Zhang10:

回复 min zhou2:

你的iq是iq几?

定义一个联合体:

typedef union FACTORY_TEST
{
uint16_t  All[4];
struct

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}code;
}FACTORYT;

FACTORYT FactoryTest

FactoryTest.code.IQ_FullScale_V = 160;
FactoryTest.code.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 160.0;

显然结果不是期望的·Value = 1.0

不用联合,直接用结果:

typedef struct FACTORY_TEST
{

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}FACTORYT;

FACTORYT FactoryTest

FactoryTest.IQ_FullScale_V = 160;
FactoryTest.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 1..0;

是期望的结果。

CCS 为6.2,编译器为c2000_15.12.3.LTS

dsp为 F28069M

出现这一问题的原因是什么?是否是CCS自身编译器的问题?

min zhou2:

回复 min zhou2:

在ccs 7.2 下,编译器16.9.9.LTS下问题依旧,说明CCS本身就有这一问题!!

定义一个联合体:

typedef union FACTORY_TEST
{
uint16_t  All[4];
struct

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}code;
}FACTORYT;

FACTORYT FactoryTest

FactoryTest.code.IQ_FullScale_V = 160;
FactoryTest.code.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 160.0;

显然结果不是期望的·Value = 1.0

不用联合,直接用结果:

typedef struct FACTORY_TEST
{

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}FACTORYT;

FACTORYT FactoryTest

FactoryTest.IQ_FullScale_V = 160;
FactoryTest.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 1..0;

是期望的结果。

CCS 为6.2,编译器为c2000_15.12.3.LTS

dsp为 F28069M

出现这一问题的原因是什么?是否是CCS自身编译器的问题?

Jun Zhang10:

回复 min zhou2:

见最后一个帖子

定义一个联合体:

typedef union FACTORY_TEST
{
uint16_t  All[4];
struct

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}code;
}FACTORYT;

FACTORYT FactoryTest

FactoryTest.code.IQ_FullScale_V = 160;
FactoryTest.code.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 160.0;

显然结果不是期望的·Value = 1.0

不用联合,直接用结果:

typedef struct FACTORY_TEST
{

uint16_t   IQ_FullScale_Hz; 
uint16_t   IQ_FullScale_V; 
uint16_t   ADC_FullScale_V1; //1V为单位
uint16_t   ADC_FullScale_V2; //1V为单位

}FACTORYT;

FACTORYT FactoryTest

FactoryTest.IQ_FullScale_V = 160;
FactoryTest.ADC_FullScale_V1 = 160;

_iq  Value_Mb = (_iq)(Factory_Code.IQ_FullScale_V);
_iq  Value_Ma = (_iq)(Factory_Code.ADC_FullScale_V1); 

float_t  V_a = (float_t)(Value_Ma);
float_t  V_b = (float_t)(Value_Mb);

float_t  Value = V_a/V_b;

运行后显示:Value = 1..0;

是期望的结果。

CCS 为6.2,编译器为c2000_15.12.3.LTS

dsp为 F28069M

出现这一问题的原因是什么?是否是CCS自身编译器的问题?

min zhou2:

回复 Jun Zhang10:

在试用了几个版本的ccs和多个版本的编译器后似乎可以得出:

  CCS在处理union结构(定点,浮点结构未试过),转为浮点数进行运算时,出错!

1、电机控制程序,人机交互的定值或控制参数一般都试用16位定点数表示,所以定点转浮点数是可能发生的转换过程。

2、union结构无论是16位数,还是32位数,转为浮点数,运算(只试验了浮点除法)结果出错。

3、将定点数赋值给浮点结构,浮点数显示是正确,单涉及运算时(只试验了浮点除法),结果出错

         几乎可以得出结论:

        ccs 在处理union结构时,有问题!

赞(0)
未经允许不得转载:TI中文支持网 » 是CCS的buge 还是其他什么原因?
分享到: 更多 (0)