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)
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.
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.
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.
But really I would like it to adjust FW 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.
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
float v = FW;
float * p = &FW;
float * vTable = &FW;
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.
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.