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
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.