dleecefft
Hi folks, 

I am fairly new to Open PLC and ladder logic but managed to get the traffic light example to work using On Delay Timer function blocks.  I have a working version built using pyModbus and a python loop, trying to port that idea into a proper PLC. 

Is there a  way to read a value from a holding register and convert that into a preset timer value? I was not able to find anything in the forums and online tutorials show the manual setting of a variable but I want to be able to change the timing remotely by adjusting the holding register value.  It looks like the 61131 spec is expecting  a string like data structure T#number followed by second or millisecond.  I didn't see any built-in function to convert this, but I am also struggling to understand how to retrieve data from a holding register an use it in a program so any leads in this area are appreciated.

Thanks in advance,
Reply 0 0
thiagoralves
Hi @dleecefft welcome to OpenPLC forum. Yes, you can use a holding register to set your timer's PT. Holding registers on OpenPLC are located in variables %QWx and %MWx, where %QW represents physical analog outputs and %MW are memory areas not associated with any physical input or output. You can check this table to learn more about modbus addressing:  https://www.openplcproject.com/reference/modbus-slave/

Since holding registers are 16-bit integer values, you first need to convert that value into a TIME variable. That's the type of variable your timer's PT input is expecting. Just use one of the conversion blocks in the editor (like INT_TO_TIME or UINT_TO_TIME) to convert from one type to the other. Keep in mind that this conversion is done to seconds, which means UINT 3 => T#3s. If you want your precision to be in milliseconds, one trick you can use is to convert your UINT or INT value to REAL (floating point), then divide by 1000.0, and then convert it to time (REAL_TO_TIME). This will give you a TIME value in the range of milliseconds from your original input.

By the way, the T#number thing is not a string, but a convention from the IEC 61131-3 standard to represent a constant TIME variable.
Reply 1 0
dleecefft
Hi Thiago,

Thanks for the pointers on the time conversion function,  it worked out mostly like I intended but I have a couple more questions if and when someone on the forum has time to point me in the right direction. 
Is there a way to prepopulate default values for the holding register variables since the modbus map is zeroed out on restart.   Without data set the PLC is essentially a loop with nothing to do so the program fails to stay running long enough for someone to put in usable values.  I resolved this by adding a switch on the Raspberry Pi so I can set the timing values then enable the switch.  ideally I would like to have it default to some safe state on startup or keep the last settings. 

The second question was more of clarifying something about the reset option for coils.  Two of the three coils in the program are open on startup, and a reset seems to put them back into the open state,  the initial coil starts as normally closed and I needed a delay off timer to get that coil deenergized. As I mentioned this is my first toe dip in the ladder logic pool so there is likely a much simpler way to do this, any direction on tutorials is welcome.

clearsky-logic-diag-snippet.png 
 
 Thanks again for a great product,  despite the learning curve I can really see how useful this is and can only imagine the work that went into it.

Doug Leece


Reply 0 0
Reply