Why does this execute differently when plugged into the BDM?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Why does this execute differently when plugged into the BDM?

772 次查看
admin
Specialist II

I have a line of code running on a 9S12XEP that seems to run differently when the micro is plugged into the BDM than it does when it isn't plugged into the BDM.

 

 

signed int P_gain_tb = 500;signed int P_val_tb = 0;signed long int PID_tb_result = 0;...PID_tb_result = ((P_gain_tb) * (long)(P_val_tb));

 

When the BDM is plugged in and the BDM resets the micro, the code evaluates as I expect. That is P_gain_tb * a positive value between 0 and 1000 for P_val_tb = a positive value for PID_tb_result. And if P_val_tb is negative, the line of code evaluates so that PID_tb_result is negative.

 

The problem is when i run the micro without being plugged into the BDM (reset the micro myself), the exact opposite happens. Somehow it evaluates negative when it should be positive, and vise versa.

 

How is this related to the BDM at all? I'm going crazy.

 

Brad

标签 (1)
0 项奖励
回复
2 回复数

422 次查看
admin
Specialist II

Never mind, I guess you can't initialize a variable outside a function with this compiler...

0 项奖励
回复

422 次查看
Lundin
Senior Contributor IV

Sure you can. It depends on what startup file you picked when creating the project: "minimal" or "ANSI". If you picked ANSI then the intialization of globals/static would work as specified in the C standard.

 

No matter which option you pick, it is best to never initalize any global/statics at all, but to set them in runtime.

0 项奖励
回复