pbosscha

Hi,

Fairly new to OpenPLC / PLC languages, so please forgive ignorance…

On a non-linear sensor I’d like to convert measured voltage levels to an actual process value (mbar, celcius etc.). The idea is to use a 20 point table, which is loaded via SCADABR, and perform an interpolation process in Structured Text. I have many sensors that need to run through this process, so I’d like to use a generic object that can be reused.

The problem I’ve run into is that Arrays cannot be referenced to any physical address (Matiec limitation), and I also cannot find a nice method to either point at holding registers (no pointers?), or to transfer multiple holding registers into an array.  

Any ideas?

Reply 0 0
thiagoralves
My idea would be to create a function block that does that. It should declare an internal array with 20 positions and populate this array with data from holding registers, preferably from contiguous positions in the holding registers address space, like from %QW10 to %QW30 or something.

This function block should also receive the current electrical reading and, based on the 20 points, spit out the correct reading.

Function blocks behave like objects. They can be reused in your code with different data
Reply 0 0
pbosscha

Thanks for that solution Thiago.
I suppose I was hoping for a simpler and neater solution, with only a single connection pointing to (the start of) a block of table data.
See attached for first attempt.. so now I'll have about 20 blocks (the number of sensors) with many connections each, a bit of editing, but so be it..
Reply 0 0
thiagoralves
No, that's not what I meant. I was thinking about a function block with only a single connection point like you said. You can declare all the 20 %MDx variables as global on your Config0->Res0 parameters, like this:
Capture.png    
Just make sure that you locate them on the %QWx address. There is a bug with %MDx address and global variables that I still need to fix. But essentially, %QWx and %MDx are the same thing if you use a number high enough that is out of your hardware analog outputs. So start somewhere in %QW30 and you will be safe.

Then, inside your Interpolation function block, you just access these variables as External, so you don't have to "wire" all of them on the ladder diagram:
Capture2.png 
Do your mathematical magic inside that function block, and then when you drag it into your ladder program, it will only have one input and one output:
Capture3.png
Reply 0 0
pbosscha
Ok, I see the advantages, was certainly quicker to configure.
But.. this does not give code re-use, would now need 20 function blocks, all doing the same, but each using a different section of holding registers ?
Reply 0 0
thiagoralves
Ah, so the points must be different for each function block. Hmm.. that's a more challenging thing to work with. Maybe you could define as global all the range of points you will need for all the blocks and then have a parameter as input of the block that tells the block which range it should work with. Then, you can reuse the same block multiple times, just giving it the input parameter that will differentiate one from another
Reply 0 0
pbosscha
Only now saw your comment on %MDxx having a bug, would %QWxx go further than 1023 ? 
The thing is that I need quite a bit of memory for all the tables, and was hoping to use the %MD range
Reply 0 0
thiagoralves
No, it won't. After 1023 you start in the %MDx address range. But, are you planning on creating more than 1023 variables on your program? That's huge, and requires a lot of typing! =)

Anyway, the %MDx bug is only related to global variables. You can use it just fine as local variables on your program.
Reply 0 0
pbosscha
Clarification request; on the reference page "Modbus Address Mapping" the Input and Holding register ranges are listed to go up to 99 (%IW99 and %QW99). But then MODBUS address says 0-1023, and your previous comment seems to confirm this. Can I assume that it's supposed to be %IW1023 and %QW1023 ?
Reply 0 0
thiagoralves
Yes, that’s correct, it goes up to 1023. Initially it was going only up to 99, but then I increased the range and forgot to update the table properly, sorry
Reply 0 0
Reply