Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Implementing a mathematical PI control for a reasonable "if" structure

Implementing a mathematical PI control for a reasonable "if" structure

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++cssvisual-studiodebugging
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Md Mubdiul Hasan
    wrote on last edited by
    #1

    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 ?

    M L 2 Replies Last reply
    0
    • M Md Mubdiul Hasan

      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 ?

      M Offline
      M Offline
      markkuk
      wrote on last edited by
      #2

      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 ?

      Comparison operators - cppreference.com[^]

      M 1 Reply Last reply
      0
      • M markkuk

        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 ?

        Comparison operators - cppreference.com[^]

        M Offline
        M Offline
        Md Mubdiul Hasan
        wrote on last edited by
        #3

        Yes. Seems logical.

        1 Reply Last reply
        0
        • M Md Mubdiul Hasan

          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 ?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          1. x -= y means subtract y from x and store the result in x. 2. The same for addition. 3. If not equals. 4. if equals. A single = sign means assign the value on the right to the variable on the left.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups