Hi there,
I recently stuck trying to implement my Matlab code in Labview for one DAQ project. The code itself is attached, but I will break it down so you can quickly point out where I made a mistake. Sorry that I didn't attach any decent screenshots, because I assume that there will be too many of them in one post.
global Torqueflag
global TorquePrev
global k
global NTOffset
TorqueMechS = GTorque*
TorquePhz = TorquePhase/4;
Tmax = 2500;
Torquemax = Tmax/0.65
ShaftOffset = 0;
NTOffset = 0;
WReached = 0;
LastCycleFlag=0;
ATororder = 0;
TorqueOrder = TorquePrev;
Tlim = 0.8*Torquemax;
WLimit = Tlim*pi;
This part of the code depicts initialization of some variables. I’ve decided to use a sequence structure with the initialization part in the first frame and then divided my code into two additional frames. For the variables, I was using local variables.
The cycle “If Trigger ==1” I’ve decided to omit, for now, just to make the code a little bit tidier. With regards to the second if cycle “if TorqueFlag==1” I used a case structure with a for loop where I put the equation for the TorqueOrder calculation and then the “break condition” cycle to exit the “if Torqueloop”.
After the cycle is finished and TorqueFlag = 0, the second part of the main loop starts executing – right now in the “False case structure”. All the if cycles are also there to check the system’s conditions and its parameters.
Overall it is a pretty simple code, but I think I made a mistake in the implementation of the n-count (Increment). The number of iterations should increase only in case of the “if TorqueFlag=1” when we are trying to reach the condition TorqueOrder<Tlim… So I implemented the outer loop as a while loop with shift registers, and it was working fine. I don't have my hardware system right now, so I was checking the code by inputting some constant values to the code, to verify its behavior.
However, I’ve noticed a bigger problem when I decided to test the code with the saved feedbacks from one of my simulations (the same code). So I have five save channels with the sample rate of 1ms. I input these signal to the designed code. I’ve never done, so after checking the forum, I found a really neat solution with the use of a for loop with the timing of 1ms that will mimic real generation of the signal. I’ve tried different combinations of for and while loops but could not make these two codes work together. I assume that either my iterations count has been implemented in the wrong way, or I need to do smth with all the for and while loops in the code. When I was troubleshooting the code, I’ve noticed that when the “k” reaches 17/18 cycles (it should be like this according to the math model), it resets to zero, and the whole cycle starts again. It causes some crazy oscillations in the output.
When I was checking the code on its own, I did not observe these issues. After counting the required number of cycles, the code switches to the “false case structure” and executes there.
I know that it is a long description of the problem and the code, but hopefully, it will help to save you some time. I have been trying to crack the code for the last few days and does not seem like I am getting any closer. Thank you and have a great day!