Posted 3 Oct 2008 For some calculations I need to use real numbers for precision. The problems for me appears when I'm trying to display these numbers on HMI. On HMI I can display only data registers which are INT or DINT. If I'm using real_to_dint() function it approximates the real value to nearest integer and I loose all the information I need. There is a trick to show these real numbers on HMI? And a question related to structured text programming. How can I assign to a data register a DINT value? Example: I have val defined as a DINT variable. D200:=val; doesn't work, I receive the type mismatch error. If I use D200:=dint_to_int(val); it's OK. So, how can I make that the value from val to be written in D200 and D201? I'm using structured text this time, because it's easier to implement the calculations. Share this post Link to post Share on other sites
Posted 3 Oct 2008 Go on give us a clue, which HMI ? Share this post Link to post Share on other sites
Posted 3 Oct 2008 (edited) You can write a little program: With the EBCD instruction its possible to extract the mantissa and exponent. so are able to write a little program to seperate the values before and after the comma. Or if your display can display strings just use the ESTR instrcution to convert real to string Edited 3 Oct 2008 by Gambit Share this post Link to post Share on other sites
Posted 3 Oct 2008 (edited) This is not tested: val1 defined as DINT K8M0 := val1; D200 := k4M0; D201 := K4M16; Edited 3 Oct 2008 by Veganic Share this post Link to post Share on other sites
Posted 3 Oct 2008 (edited) thank both Gambit and Veganic. Veganic, the code is working. I know that k8 is for 32-bit data and k4 for 16-bit data, but exactly does it do? Let me see if I get it K8M0 := val1; writes all bites from M0 to M32 with the binary value of val1 D200:=K4M0; D200 is initialized with binary M0 to M16 D201:=K4M16; D201 is initialized with binary M16 to M32 This is the only solution to move val1 to D200 and D201? In ladder DMOV is enough (eg. DMOV val1 D200 - and it knows what to do). Also, I didn't succeed to use the dmov_m() function with data registers in structured text. dmov_m(m8000, D100, D200); does not work. I receive invalid parameter error. Edited 3 Oct 2008 by wizard Share this post Link to post Share on other sites
Posted 3 Oct 2008 (edited) I haven't tested it. Does it work? The idea is : val1 is 32 bit each M is 1 bit. Each K "stands for" 4 bits. K1M0 stands for M0,M1,M2,M3 K2M0 stands for M0,M1,M2,M3,M4,M5,M6,M7. and so on. say val1 = 11101010101010101010101010101010 (32 bit binary reading Bit 0 to Bit 31 - sort of back to front but you get the idea) then K8M0 = 32 bits (8*4 =32) So when K8M4 :=Val1 then M0 =1, M1 =1, M3=1, M4 = 0......M31=0. Take this as two 16 bit words, M0 to M15 is K4M0 and M16 to m31 is K4M16. So D200 = K4M0 = 1110 1010 1010 1010 and D201 = K4M1 = 1010 1010 1010 1010 Edit : let me know if that's not clear. Edited 3 Oct 2008 by Veganic Share this post Link to post Share on other sites
Posted 3 Oct 2008 Great, now it's more than clear for me. This is the only solution to move val1 to D200 and D201? In ladder DMOV is enough (eg. DMOV val1 D200 - and it knows what to do). Also, I didn't succeed to use the dmov_m() function with data registers in structured text. dmov_m(m8000, D100, D200); does not work. I receive invalid parameter error. Share this post Link to post Share on other sites
Posted 3 Oct 2008 Hopefully someone will be along with a better solution but it's the simplest I could come up with. Share this post Link to post Share on other sites
Posted 7 Oct 2008 Hello, Solution 1: Define a global variable with type DINT and address D200. Then all you need to do in ST is: GlobalVar := val; Solution 2: Use the IEC address with DMOV_M, as it contains size information (the D after %M means its a double word): DMOV_M(TRUE, val, %MD0.200); This is tested in GX IEC Developer. Share this post Link to post Share on other sites
Posted 7 Oct 2008 Great solution, exactly what I was looking for. Share this post Link to post Share on other sites
Posted 7 Oct 2008 I don't have FX3 software yet so was using Q-series. Neither of those option work with the Q. Share this post Link to post Share on other sites
Posted 8 Oct 2008 What software are you using? In GX IEC Developer both solutions work with all Mitsubishi series. Both code lines are compiled to the following machine code (on Q-series): LD SM400 DMOV D6144 D200 (Where D6144 is the address of the variable "val".) Share this post Link to post Share on other sites
Posted 8 Oct 2008 (edited) Plain GX Developer. Edit : solution 1 works. Edited 8 Oct 2008 by Veganic Share this post Link to post Share on other sites