How to use a PLC to read momentary discrete inputs via modbus - Page 1
Forum section: electronics / projects

author: 5U4GB
author_rank: Super Contributor
timestamp: June 10, 2025, 11:22:28 am
content: I'm working with a PLC with a 30-second scan cycle which checks a bunch of modbus discrete inputs (1x0000 / function code 0x02). Problem is that while these have a nice wide pulse feeding the input, it's just that, a pulse, which rarely coincides with the 30-second scan cycle.What's the standard way of dealing with this? The obvious one is to use a bunch of 555s as pulse stretchers to take it out to 60s or so and cover at least two scan cycles (this is fine, the input check is merely "did something happen since the last scan"), but that's going to require a bunch of extra circuitry and wiring. Is there some recommended technique for reading modbus discrete inputs whose timing doesn't correspond to the modbus read timing?

author: mikerj
author_rank: Super Contributor
timestamp: June 10, 2025, 01:30:05 pm
content: Which specific Modbus IO devices are you using? Some have a latched input register to overcome exactly this problem.

author: 5U4GB
author_rank: Super Contributor
timestamp: June 10, 2025, 01:55:40 pm
content: ATM purely for testing purposes a Waveshare modbus I/O device because I've got one lying around, the final device(s) will be TBD which is why I'm using the Waveshare with its convenient LED indicators everywhere for testing. The Waveshare AFAIK isn't latched because the docs talk about various control modes where the state of the input (high, low, pulse) controls what the output does, and there's no option to clear the inputs if they were latched. Unfortunately there's no option to latch an output based on an input pulse or I'd have used that, so essentially use the contents of an output holding register to find out what the corresponding input did.More generally though, I don't have a lot of control over what the I/O devices are so I'm expecting to run into at least some that are unlatched.

author: LaserSteve
author_rank: Super Contributor
timestamp: June 10, 2025, 03:07:48 pm
content: My employer, a PCB Board and Manufacturing House, builds Modbus and other PLC peripherals under contract for several PLC companies. May I suggest that you check the Logic Ladder program in the PLC as it's programmer that set the 30 second clock. The most you should have to stretch that pulse is 100-200 mS. A better beginner's arrangement would be for you to set a flipflop for your input signal to the PLC and let a PLC output unset it after scanning the inputs. This will need to be designed for startup reset conditions etc. PLC are designed for extreme reliability and safety, so your circuit should avoid things like timers and "hoping" that a coil scan (PLC memory locations are still known as COILS from the relay based PLC days") intercepts your status signal. Also remember to properly protect, current limit, and buffer / isolate your signal to the PLC.I do the problem solving, UL Compliance, support to our customer, and test design for our legacy PLC product line as the engineers long ago retired. We have them on call for any issues that arrise.. I really don't get into the ladder logic side of things, but what your describing seems just plain wrong based on the PLCs I have for testing. They are fast, and look for state changes, even though they are late 1990s and early 2000s designs.As PLCs generally control safety of life things, you should get professional advice from a consultant on how to meet industry standards and not just rely on forum advice for your design, especially if it's going into serial production and is not a "one-off". The required testing is immense for serial production and there are well defined industry and regulatory protocols to be followed.From what I have learned, low-cost PLCs are often a bad investment. I'm well aware the PLC Industry is a pay to play, closed garden, rough world where information is tightly held. I'm also aware of the yearly fees for software licenses etc. I know it's tough to enter this world without training and help from an experienced person.As one of the products we make is a plug-in module for adding RS232/RS485/RS422 to various PLCs, you may have other routes for data I/O to choose from.Steve

author: H.O
author_rank: Frequent Contributor
timestamp: June 10, 2025, 03:32:56 pm
content: Yeah, latching the input in the I/O-slave would be good but what the heck, 30s cycle-time!? 30ms is a long time these days....Is the program blocking while polling the slaves, one (or more) slaves not present (or not responding) and the MODBUS timeout set WAY high, possibly?

author: 5U4GB
author_rank: Super Contributor
timestamp: June 11, 2025, 08:21:17 am
content: It's not, strictly speaking, a standard PLC but an in-house developed PLC-ish device of which the developer(s) might read this forum so I'm being a bit vague :-). I certainly wouldn't go near any real-world use of this stuff because it's controlling some serious electrical gear, this is more a trial/proof-of-concept before it's done properly by people qualified to do so. In theory I could make it their problem to solve, but I'd like to at least explore possible solutions rather than push the task off to others, so forum advice is definitely appreciated, and will hopefully be useful to others dealing with similar problems.In particular the inputs are, as far as I can tell, used to trigger animations on a dashboard which is why it's not overly critical whether they're handled in anywhere near real time or not (and they're appropriately conditioned, isolated etc, the hardware side is fine). The outputs, which I definitely won't be touching, are another matter...

author: mikerj
author_rank: Super Contributor
timestamp: June 12, 2025, 11:36:27 am
content: Absent of the IO devices having latched input registers I don't think there is any kind of coding trick you can use to fix this. You need to sample at least twice as often as the active pulse period, and ideally a bit higher, so it's either down to increasing the scan rate or performing pulse stretching (or maybe latching) in the analog domain.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: June 15, 2025, 07:01:58 pm
content: Is there a reason for the scan cycle being so extremely slow? Best I know the normal approach is to have a scan time that is less then 100ms. 500ms would already be quite slow.Does that remote I/O have any intelligence on it's own? Can it remember / latch a switch state? If it also has outputs, you could add a bistable relay. A user button sets it, and the PLC clears it after reading.

author: 5U4GB
author_rank: Super Contributor
timestamp: June 16, 2025, 12:13:54 pm
content: Seethis post, it's not a PLC in the usual sense but some custom controller board with PLC-like functionality.In the meantime I've found a solution but it's unfortunately not general-purpose so probably not that useful for most people facing the same problem: There's two inputs that go to counters and can be configured to clear on read and currently seem to be unused for other stuff, so they can be used to detect whether there's been an input pulse since the last read.

author: sales@dnaengineering.in
author_rank: Newbie
timestamp: June 17, 2025, 11:03:27 am
content: Please mention the part no of the device