Sign in to follow this  
Followers 0
Van

Addressing memory using mathatic expressions?

14 posts in this topic

I have posted before that I am PC programmer with some PLC experience. I am reading the programming manual but have not seen anything that could answer my question (probably not looking in the right place). Is it possible to address memory using mathematics instead of hard coding it? Let me provide and example of what I would like to do. I have an output module (ex. OC211). This module has 16 bits (ex. 0.00 - 0.15). Through some other means the PLC receives information. Based on the data received by the PLC we would like to use mathematics to address certain memory locations. For example, lets say that I received the number six (6) in a memory location (say D1000). Would it be possible in ladder logic to address point "six" (0.06) using a mathematical expression versus hard coding? Here it is in suedo code: bit to set ( 0.00 + ( D2000 * 0.01 ) )

Share this post


Link to post
Share on other sites
http://forums.mrplc.com/index.php?autocom=downloads&showfile=195

Share this post


Link to post
Share on other sites
Thank You! It is very similar to C/C++. '*' is something I understand very well!

Share this post


Link to post
Share on other sites
DMPX would work nicely too.....

Share this post


Link to post
Share on other sites
OK. I'm having trouble understanding how to properly perform the math to do Indirect Addressing. Here is my setup: I have allocate some memory space to use as a circular buffer: D5900-D5999. Each buffer segment size is nine (9) continuous words. I have a FOR/NEXT loop that loops through each buffer segment and evaluates the first element (word) of each buffer segment to see if that buffer segment is available for use. For right now, there are only nine buffer segments. I am having trouble doing the multiplication and addition. I keep coming up with invalid memory addresses like 596A (i.e. HEX addresses) instead of it properly rolling over after 9 to next memory word location. In the FOR/NEXT I increment a multiplier starting at zero (0). I then take that multiplier and multiply it by nine (9) (the buffer segment size) and then add it to the starting memory location (D5900). Once I establish the base, I then attempt to create the remaining eight (8) element addresses by adding one (1) to the previous memory address. 0 (multiplier) X 9 (buffer segment size) = 0 (memory offset) 5900 (base memory address) + 0 (memory offset) = 5900 (first buffer element (word) ) 5900 + 1 = 5901 (second buffer element (word) ) 5901 + 1 = 5902 (third buffer element (word) ) ... and so forth to nine (5909). now, ZERO works great, however I have a problem when I want to use a multiplier greater than zero (0). Here is the mnemonic code: ' Circular Buffer.\nLocate an available memory space. FOR(512) XMT_SF_QUEUE_SIZE ' Check for invalid state. LDNOT XMT_SF BREAK(514) ' Increment Data Buffer Offset. LD XMT_SF ++(590) XMT_SF_DB_ADDR_MULT ' Compute and set memory offsets.\nThis is for use with indirect addressing. LD XMT_SF *(420) XMT_SF_DB_ADDR_MULT XMIT_SF_DB_SIZE XMT_SF_DB_ADDR_OFFSET +(400) XMT_SF_DB_ADDR_OFFSET XMT_SF_DB_BASE_MEM XMT_SF_DB_ADDR_STATE +(400) XMT_SF_DB_ADDR_STATE &1 XMT_SF_DB_ADDR_W01 +(400) XMT_SF_DB_ADDR_W01 &1 XMT_SF_DB_ADDR_W02 +(400) XMT_SF_DB_ADDR_W02 &1 XMT_SF_DB_ADDR_W03 +(400) XMT_SF_DB_ADDR_W03 &1 XMT_SF_DB_ADDR_W04 +(400) XMT_SF_DB_ADDR_W04 &1 XMT_SF_DB_ADDR_W05 +(400) XMT_SF_DB_ADDR_W05 &1 XMT_SF_DB_ADDR_W06 +(400) XMT_SF_DB_ADDR_W06 &1 XMT_SF_DB_ADDR_W07 +(400) XMT_SF_DB_ADDR_W07 &1 XMT_SF_DB_ADDR_CS ' Is this buffer (memory) space available for use? LD XMT_SF LD=(300) *XMT_SF_DB_ADDR_STATE XMT_SF_DB_STATE_AVAIL OR=(300) *XMT_SF_DB_ADDR_STATE #0000 ANDLD SET XMT_SF_DB_AVAIL BREAK(514) NEXT(513) LD XMT_SF ANDNOT XMT_SF_DB_AVAIL MOV(021) EC_XMT_SF_DB_FULL XMT_SF_ERROR_CODE Where am I going wrong?

Share this post


Link to post
Share on other sites
Probably, nothing wrong. Why do you monitor it in Hex format? Switch to decimal view. And if you are in wrong radix view, the values you enter manually online are also incorrect. Edited by Sergei Troizky

Share this post


Link to post
Share on other sites
What PLC are you using? If you are using one of the newer PLC's, with Structured text capability, you could do this very easily, expecially with your PC programming background. I don't have time right now, but can you post your cxp code. If I understand correctly, you have memory areas 5900 -> 5999 that you want to check, so 5900, 5910, 5920, 5930 etc? If one of these areas is available for use, then you want ot copy? 10 values into this segment? If I get a chance, I will see if I can get something done, will def help with the PLC model though, as this can dictate the best method.

Share this post


Link to post
Share on other sites
Thank you. I will double check my view (i.e. HEX vs DEC). I am using a CJ1M - CPU11 (and CPU12).

Share this post


Link to post
Share on other sites
@Sergei Troizky: You were right, there was nothing truly wrong with the math when viewed in decimal. Thank you for that hint. I did find that I was using the wrong indirect addressing operand. I was using "*" and should have been using "@". That made the difference and now it's working. I have two PLCs: development and production. Dev: is a CJ1M CPU11 Prod: is a CJ1M CPU12 The difference, from what I was told, is addressable space. The CPU12 has more memory than the CPU11. But don't take my word for it. I'm not an expert. I'm only repeating what the Omron dealer told me.

Share this post


Link to post
Share on other sites
How did you generate the mnemonic code? I only see ladder logic.

Share this post


Link to post
Share on other sites
In CX-Programer, RIGHT-CLICK on the program section and there is an option to view it in mnemonic.

Share this post


Link to post
Share on other sites
FYI, Using CX-Programmer v8.0, and a CJ2 PLC, addresses in the Ladder Editor can now be indexed either directly or indirectly. I.e. D100[10] - points to D110, likewise D100[D20] where D20 = 10 - points to D110, or D100[MySymbol], where my symbol = 10 - points to D110. This should make Vans' (and others) indirect addressing problems much easier to solve within Ladder, although as Scott alluded to, using ST could circumvent a lot of the issues.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0