Program HELP!

So here is the my situation.
I have a program for a Wind Turbine that controls the Power in relation to the voltage. The MPPT Settings page in the HMI allows for 20 settings for Voltage and 20 Settings Power. For example - 330Volts = 0Watts, 400Volts = 3300Watts.
1 - 330V 0W
2 - 335V 100W
3 - 340V 200W
4 - 345V 300W
5 - 350V 400W
6 - 355V 550W
7 - 360V 700W
8 - 365V 900W
9 - 370V 1100W
10 - 375V 1350W
11 - 380V 1600W
12 - 385V 2000W
13 - 390V 2300W
14 - 395V 2700W
15 - 400V 3300W
16 - 410V 3800W
17 - 420V 4200W
18 - 430V 4800W
19 - 440V 5200W
20 - 450V 55000W

Each setting in the HMI is labeled 1-20. The PLC is a Xinje PLC and I believe I found the code in the program that controls the power being asked.
Now what I would like to do is modify the code to accomplish the following
Using the original 20 MPPT Settings I would like to make settings into 5 different Categories. 1-4, 5-8, 9-12,13-16,17-20.
Then what I need to happen is that it will run through the settings for 1-4 and not go setting 5-8 until Voltage is at or over 470V for more than 2 Seconds. Then the same thing for setting 5-8, Once voltage is at or over 470 for more than 2 seconds go to setting 9-12.
Now, it needs to go down when voltage is at or below 370V for over 2 seconds.
So if in settings 13-16 and voltage goes below 370 then go to setting 9-12.

There is one other thing I would like to do but this is where I would like to start.

Here is the Code that I believe reads the Table for Voltage and Power tells what to output. I am not familiar at all with Programming and do not even know where to start.
ANY HELP IS APPRECIATED!

void MPPT( WORD W , BIT B)
{
int i;
int count=W[4];

float v = FW[0];
float * p = &FW[2];

float * vTable = &FW[6];
float * pTable = &FW[6+count*2];

*p = 0;//Less than not find Back 0

for(i=0;i<count-1;i++)
{
if(v == vTable[i])
{
*p = pTable[i];
return;
}
else if(v == vTable[i+1])
{
*p = pTable[i+1];
return;
}
else if(v>vTable[i] && v<vTable[i+1])
{
*p = (pTable[i+1]-pTable[i])* (v-vTable[i]) / (vTable[i+1]-vTable[i])+pTable[i];
return;
}
}

}
So my new MPPT Settings would look like this in HMI.
1 - 330V 0W
2 - 400V 200W
3 - 470V 400W
4 - 500V 600W
5 - 330V 0W
6 - 400V 400W
7 - 470V 800W
8 - 500V 1200W
9 - 330V 0W
10 - 400V 800W
11 - 470V 1600W
12 - 500V 2400W
13 - 330V 0W
14 - 400V 1600W
15 - 470V 2800W
16 - 500V 4000W
17 - 330V 000W
18 - 400V 2800W
19 - 470V 4200W
20 - 500V 5400W
bump
closed account (D80DSL3A)
It looks to me that this MPPT() function adjusts the power by finding what vTable values that the current voltage falls between, and then interpolates in that range.
There isn't anything in the code related to timing. It appears to just provide an ability to interpolate the power value.
The formula for the interpolated value appears to be correct. I wouldn't mess with this code.
This function adjusts the value of FW[2].

I wish I could help more. I'm a commercial electrician but I've never worked with PLC's, except to make wiring connections to them.
I should probably get into what you're doing! I wish I was working with you.
Last edited on
I am also an electrician wishing they had taught C++ more in school.
This was one reason I quit engineering school because I was completely lost.

What we are doing is very fun and also very frustrating. So many problems between inverter's and PLC and too many other things to list. If I can work through this program to do what I have explained above it will fix most of my issues. I HOPE!...
I understand what you are saying on adjusting the value of FW[2].
But really I would like it to adjust FW[2] between 1-4 settings first until the voltage and time criteria is met then go up to settings 5-8. Same idea for when going down between the settings.

I am just hoping that maybe rewording the question may make it more understandable.
closed account (D80DSL3A)
I don't see how the code you posted could do what you want. It's just a routine for interpolating values within the range that v currently falls.. There may be something in the constants between [] in the 1st few lines:
1
2
3
4
5
6
7
int count=W[4];

float v = FW[0];
float * p = &FW[2];

float * vTable = &FW[6];
float * pTable = &FW[6+count*2];

but I wouldn't mess with these values without understanding more about what's stored where in the FW array.
The functionality you wish to affect probably lies outside of the MPPT() function posted.
Last edited on
There is also this in the program. But I think that the MPPT Function is only used to communicate to the Inverter. So it uses the number returned from MPPT to output a special code to the inverter. I don't see anything else in the program that uses the MPPT Code.
Most of the program is ladder logic. And I only see 4 function blocks.
So I was just assuming that adjusting the MPPT function would not affect the output functions for communicating to the Inverter.

void FTO4B( WORD W , BIT B)
{

char * val = (char*)&W[0];

W[2] = val[0];
W[3] = val[1];
W[4] = val[2];
W[5] = val[3];
}
void CRC16( WORD W , BIT B )
{

typedef struct crc16 {
unsigned char bcclo, bcchi;
} crc16;

// We start at 0xff,0xff. Some methods/devices start at 0x00,0x00 instead.
#define CRC16_INIT(X) do { (X).bcclo=0xff; (X).bcchi=0xff; } while(0)

#define CRC16_NEXT(X,C) do { \
unsigned char _new=(C),_tmp; \
_new^=(X).bcclo; \
_tmp=_new<<4; \
_new=_tmp^_new; \
_tmp=_new>>5; \
(X).bcclo=(X).bcchi; \
(X).bcchi=_new^_tmp; \
_tmp=_new<<3; \
(X).bcclo=(X).bcclo^_tmp; \
_tmp=_new>>4; \
(X).bcclo=(X).bcclo^_tmp; \
} while(0)

#define CRC16_FINISH(X) do { (X).bcclo^=0xff; (X).bcchi^=0xff;}while(0)


int i;
int c;
crc16 crc;

CRC16_INIT(crc);

c = W[0];
for(i=1;i<=c;i++)
{

CRC16_NEXT(crc,W[i]);
}

CRC16_FINISH(crc);

W[c+1]=crc.bcclo;
W[c+2]=crc.bcchi;

}
Topic archived. No new replies allowed.