# plat933x

MrPLC Member

9

0 Neutral

• Rank
Newbie

## Profile Information

• Gender Male
• Country Poland
1. ## Continuous sine wave problem

Okay, I started implementation with help of your last post. I will try to ask you with some doubts to avoid unnecessary corrections and getting lost in a code.  In attachment 1 you can see a code with dAngle, k, and Xi-2 and Xi-1 variables. Later, I assigned these values into PLC's registers with 5 registers break. Is it written in a good way? Should I put some while loop here? If it's true, where should I put index in? The second part was to make a new network in PLC program which is showed in att.2. Is this ladder combination made good? What I observed so far is issue that "REAL_TO_DINT_E" block does not convert values 4.371144 into 4. What is more, 'Sinewave' network in POU part of program is coloured red after compilation. Do you see there: in HMI code or in PLC ladder some obvious mistakes made by me?   Not sure if it's really challenging task or I'm still serious newbie in PLC&HMI stuff... Pls help. Greetings, J
2. ## Continuous sine wave problem

I have tried to implement your code with following points: "1) For that purpose is need to accumulate a scan time, i.e. at each scan is need to add a time of previous scan, which is stored in D8010 (0,1ms units).  2) The accumulated value (DINT) is need convert to into REAL then to multiply with Frequency value [0,1Hz units].  3) Because a time value is represented in 0,1ms and a frequency value is represented in 0,1Hz it is need to compare the result with 100000 (the equivalent for 2*PI angle). If the calculated value is greater than or equal to 100000, then is need to reset the accumulated value of scan time. 4) The result of previous calculation is need to multiply with 2*PI/100000. Thus we get x-operand. 5) The result of previous calculation is need to multiply with itself to get x2. The result  of this operation is important to save separately of x, both and of other values, because it will be used in following calculations.  6) x2 is need to multiply with x and the result to divide with -6. Thus we get -x3/3! and can add it to x. Thus we get a x - x3/3! in the cell, where x stored. 7) -x3/3 is need to multiply with x2 and to divide with -20. Thus we get x5/5! and can add it to x. Thus we get a x - x3/3! + x5/5! in the cell, where x stored. 8) Then the result is need to multiply with the signal amplitude (the digital value that should be transferred to the channel of analog output module) and finally to convert it into INT. " I prepared code according to your advices, you can find it in attachment 1. It would be too easy to work for the first try ... What I wrote in a wrong way? Can you see some obvious mistakes in my code? Ahead on the question "data types: word vs float", when I wrote code on floats as you recommended, I received some noises between -32768 to 32767. After that I changed floats to word and received chart like in attachment 2. It looks more like sawtooth. Did I make too less polynomials in the formula for Taylor series(now it's y = x-x^3/3!+x^5/5!)? I wondered about scan time of PLC, what do you think, is it possible to change scan time with M8039 and register D8039 to achieve changing of frequency of sine in much simplier way - regarding to attachment 3 and 4? For example when I use sine wave function with 1 Hz frequency and scan time D8039 = 100ms, changing value of D8039 from 100 ms to 200ms will change frequency on 0.5 Hz? Greetings, J
3. ## Continuous sine wave problem

Inntele, Huge thanks to you for interesting in this issue and your efforts. I will try to implement each method and gonna see if it does work. If you get some new idea please share it here. Greetings, J
4. ## Continuous sine wave problem

It's Mitsubishi FX3GE-24MR with GXWorks 2 software.  The HMI is a Graphic Operation Terminal 1000 Series, GT15 wih GTDesigner 3.  Greetings
5. ## Continuous sine wave problem

Thanks for fast reply Inntele, The main goal of application is to obtain on PLC output mathematic functions. As I mentioned before, everything is correct with: constant function, trapeze function, exponential function. Every function is implemented as executable script in GOT + PLC blocks. Every function values have a place as registers in PLC's memory. I assumed that every function will execute in loop with 1500 iterations. First value - function_value[1] is placed in D2000. The last one, function_value[1500] is placed in D3499. Between these registers are particular values, estimated from script. In picture 1 you can see one period of exponential function received from script. In real system, one period of function will execute during some time "t", e.g. t = 0.8 sec. So if we have 'task time' = 20 sec, function will repeat n times. In picture 2 you can see torque and current measurements from NI DAQ during control with exp function.  In sine wave function, user can decide about: amplitude, offset and frequency of function. A trouble appeared with frequency. I should obtain sine function which is repeatable every "t" time, depending on frequency entered by user. If we meet with situation like in picture 3(sine with f=1,4Hz), repeating of such function will cause deformed chart, so its useless. I worked with script showed on picture 4, but maybe its concept is bad? I wondered about line 4 in that script, I am not sure every index of function should be multiplied by coefficient = 2pi/no of elements? I have an idea but have no clue at this moment how to accomplish it.  To abandon loop with 1500 elements and obtain values from incrementing index, where sin(1) and sin(5000) will still be between <-1,1> (gonna be trouble with storing it, memory problem)... ...Or just quit present concept of script and make a new one to receive in analog output sine function with online changing of its frequency. I really hope this time you could understand better nature of the problem. Greetings, J. P.S. To clarify your doubts - yes we have array of 1500 elements between D2000 and D3499. These data represents one period of some function, when its constant, it will be one value stored in each of 1500 registers, when its sine, its gonna change between <-A,A> where A is amplitude. Array is always filled with integers because I send to D2000 data type "word". There is no approx of values. In registers D3500 - D4000 I stored the same values as in D2000 - D2500 to show you in clear way that repeated chart will be deformed (in good case values between e.g. D3495 and D3505 should be similar to smoothly continue shape of sine wave).
6. ## Continuous sine wave problem

I changed index from 1 to 0, but still it doesn't work properly. I wrote another script, with same formulas and structure to fill registers starting from D3500 with same values as D2000-D3499 to show you better what kind of problem I work with. I extended simulating screen with additional window representing D3500-D4000. These little breaks are connections between screens. You can see that in D3500 register gets from script, array value no.1. I would like to get continuous sine wave chart, so in D3500 value should be equal to 89.  I guess the problem is putting sine function into array. It's periodic function, it doesn't need to be repeated. If we estimate function y=10*sin(t), it doesn't matter if we get t=1 or t=1000, values will still be between <-10,10>.  Any ideas how to implement that idea into GTDesigner script or GXWorks ladders? Thank you in advance, J
7. ## Continuous sine wave problem

Hi,  I encountered specific problem during work with PLC&HMI application. The main task of that system is controlling torque changes of induction motor with inverter&analog PLC output. There are few built-in functions to change torque: exponential, constant, trapeze and unlucky sine. All functions are implemented as array of 1500 values. When array reaches 1499 element, it comes back on first position and so on. It works without any problem for exp, constant, trapeze and sine wave with natural numbers of frequency e.g. 1Hz, 3Hz etc. The trouble appears when we want to control torque with float value of frequency and unfortunately its the most important part of that project. When the float value frequency is chosen, the last element of array is totally different than the first one. In result, in every period of array, appears drop of value. Check the attachments to comprehend what's going on. The first image shows GXWorks restriction of index. The second image shows how does it look on simulate screen, where it's representation of PLC registers D2000 - D3499. On third and fourth images you see values of registers in Device Memory Batch of GXWorks. Fifth image shows the script which I work on. Do you have any ideas how to implement float values of frequency in correct way? I should make an opportunity to online change of sine frequency in continuous way between 0 and 10 Hz, with 0.2Hz step. I will be very grateful for any advice.  Greetings, J
8. ## GT Designer3 Script Problem

First of all, big thanks for you @kaare_t for quick and right answer. I've based my new-edited script on your advices and it worked, but I have another stranger issue regarding to script's results. I used exactly your script and got weird results which you can see in attachements in this post. I plotted 50 points starting from D2000 to show more clear what is the problem.  Att.1. Why the obtained chart is so irregular with many peaks?It looks more similar to sawtooth wave. I must get more smooth sine wave chart. Is it some kind of problem with sampling frequency? Att.2. Values in registers are in range of -32768 to 32767, i guess it's from Signed Word range, but is it possible to get, on chart, values e.g. in range 0-100? Should i make some conversion in GXWorks with received in D2000-D3499 values? Att.3. On another screen i made script with exponential function instead of sine. You can see that all I got is something near rising sawtooth function. What is the simpliest way to get exp function with GOT's script? I'm working with GOT1000 GT15-S and Mitsubishi FX3GE-24MT. Greetings, J.
9. ## GT Designer3 Script Problem

Hi,  I encountered a specific problem during work with GXWorks2 & GTDesigner3. In my part of group project I need to receive from proper script, array of values of sine wave. I need to get 1500 values of sine wave and fill registers in GXWorks and have no idea why my script does not run. I'm using simple while loop with no errors statement from Syntax Check. My script should calculate sine values from index 0 to 1500, and substitute it to registers D2000 - D3499. Look in attachments for better understanding my trouble.  I'm looking forward to hearing from you as soon as possible.  Greetings, Jan P.S. I'm new in Mitsubishi Equipment programming so if it's some kind of beginner's problem - please be merciful for me.