Implementing a mathematical PI control for a reasonable "if" structure
-
Hello There, I am a newbie here. I just want to know few things those are really hard to track down. I am trying to debug a existing F/W code mostly written in c or c++. This IDE and compiler is from a particular DSP/MCU company. This code is a complex one and F/W and S/W mixed together. Some codes are not even understandable because I have very limited knowledge in syntax, pointer datatype and flags etc. Manuals and examples can give some ideas. Now lets talk a specific problem, .c file includes some header dependencies like those are customized, made for particular reason.
#include "DSP28x_Project.h"
#include "Register.h"
#include "CLA.h"
#include "LED.h"Mentioned register file is customized. I am not going to describe in detail. Before I post a portion of code I should explain a little. In this PI control we are trying to play with register values which may bring the channel voltage that relates with current in terms of different conditional case. Here we go,
Register[CURENT_LIMIT_STATUS] = CURRENT_LIMIT_STATUS_NULL;//need to know what is the current limit status in load
if(bSysRun)// This register tells to RUN the system { Voltage\_ch1 -= Current\_T\_ch1 \* Register\[LINE\_DROP\_SCALE\]; // multiplied by a scale vaule Voltage\_ch1 = Voltage\_ch1 < 0 ? 0 : Voltage\_ch1;// less then 0, means no load if(Register\[USE\_LOADSHARE\] != 0) { Voltage\_ch1 -= Register\[LOADSHARE\_DIFF\_CURRENT\] \* Register\[LOAD\_SHARE\_SCALE\_V\];//330 no register multiplied by load share scale Current\_BP -= Register\[LOADSHARE\_DIFF\_CURRENT\] \* Register\[LOAD\_SHARE\_SCALE\_B\];// BAT positive end current with same load share current if(Register\[RUN\_MODE\] == MODE\_SOLAR) { Voltage\_ch2 += Register\[LOADSHARE\_DIFF\_CURRENT\] \* Register\[LOAD\_SHARE\_SCALE\_B\];// } }
What I did not understand as follows, 1. Subtract AND assignment operator, what -= means ? 2. what += means ? 3. What does !=0 means in if structure ? 4. What double equals == means ?
-
Hello There, I am a newbie here. I just want to know few things those are really hard to track down. I am trying to debug a existing F/W code mostly written in c or c++. This IDE and compiler is from a particular DSP/MCU company. This code is a complex one and F/W and S/W mixed together. Some codes are not even understandable because I have very limited knowledge in syntax, pointer datatype and flags etc. Manuals and examples can give some ideas. Now lets talk a specific problem, .c file includes some header dependencies like those are customized, made for particular reason.
#include "DSP28x_Project.h"
#include "Register.h"
#include "CLA.h"
#include "LED.h"Mentioned register file is customized. I am not going to describe in detail. Before I post a portion of code I should explain a little. In this PI control we are trying to play with register values which may bring the channel voltage that relates with current in terms of different conditional case. Here we go,
Register[CURENT_LIMIT_STATUS] = CURRENT_LIMIT_STATUS_NULL;//need to know what is the current limit status in load
if(bSysRun)// This register tells to RUN the system { Voltage\_ch1 -= Current\_T\_ch1 \* Register\[LINE\_DROP\_SCALE\]; // multiplied by a scale vaule Voltage\_ch1 = Voltage\_ch1 < 0 ? 0 : Voltage\_ch1;// less then 0, means no load if(Register\[USE\_LOADSHARE\] != 0) { Voltage\_ch1 -= Register\[LOADSHARE\_DIFF\_CURRENT\] \* Register\[LOAD\_SHARE\_SCALE\_V\];//330 no register multiplied by load share scale Current\_BP -= Register\[LOADSHARE\_DIFF\_CURRENT\] \* Register\[LOAD\_SHARE\_SCALE\_B\];// BAT positive end current with same load share current if(Register\[RUN\_MODE\] == MODE\_SOLAR) { Voltage\_ch2 += Register\[LOADSHARE\_DIFF\_CURRENT\] \* Register\[LOAD\_SHARE\_SCALE\_B\];// } }
What I did not understand as follows, 1. Subtract AND assignment operator, what -= means ? 2. what += means ? 3. What does !=0 means in if structure ? 4. What double equals == means ?
Md Mubdiul Hasan wrote:
1. Subtract AND assignment operator, what -= means ? 2. what += means ?
Assignment operators - cppreference.com[^]
Md Mubdiul Hasan wrote:
3. What does !=0 means in if structure ? 4. What double equals == means ?
-
Md Mubdiul Hasan wrote:
1. Subtract AND assignment operator, what -= means ? 2. what += means ?
Assignment operators - cppreference.com[^]
Md Mubdiul Hasan wrote:
3. What does !=0 means in if structure ? 4. What double equals == means ?
Yes. Seems logical.
-
Hello There, I am a newbie here. I just want to know few things those are really hard to track down. I am trying to debug a existing F/W code mostly written in c or c++. This IDE and compiler is from a particular DSP/MCU company. This code is a complex one and F/W and S/W mixed together. Some codes are not even understandable because I have very limited knowledge in syntax, pointer datatype and flags etc. Manuals and examples can give some ideas. Now lets talk a specific problem, .c file includes some header dependencies like those are customized, made for particular reason.
#include "DSP28x_Project.h"
#include "Register.h"
#include "CLA.h"
#include "LED.h"Mentioned register file is customized. I am not going to describe in detail. Before I post a portion of code I should explain a little. In this PI control we are trying to play with register values which may bring the channel voltage that relates with current in terms of different conditional case. Here we go,
Register[CURENT_LIMIT_STATUS] = CURRENT_LIMIT_STATUS_NULL;//need to know what is the current limit status in load
if(bSysRun)// This register tells to RUN the system { Voltage\_ch1 -= Current\_T\_ch1 \* Register\[LINE\_DROP\_SCALE\]; // multiplied by a scale vaule Voltage\_ch1 = Voltage\_ch1 < 0 ? 0 : Voltage\_ch1;// less then 0, means no load if(Register\[USE\_LOADSHARE\] != 0) { Voltage\_ch1 -= Register\[LOADSHARE\_DIFF\_CURRENT\] \* Register\[LOAD\_SHARE\_SCALE\_V\];//330 no register multiplied by load share scale Current\_BP -= Register\[LOADSHARE\_DIFF\_CURRENT\] \* Register\[LOAD\_SHARE\_SCALE\_B\];// BAT positive end current with same load share current if(Register\[RUN\_MODE\] == MODE\_SOLAR) { Voltage\_ch2 += Register\[LOADSHARE\_DIFF\_CURRENT\] \* Register\[LOAD\_SHARE\_SCALE\_B\];// } }
What I did not understand as follows, 1. Subtract AND assignment operator, what -= means ? 2. what += means ? 3. What does !=0 means in if structure ? 4. What double equals == means ?