Is there a way to create an interrupt from hardware input from a X20 DI?
My application needs to measure the duty cycle of a 20Hz PWM input.
My background is SIEMENS. To achieve this task with SIEMENS PLC, I will use a high feature DI and create two hardware interrupts on the DI channel that receives the PWM. The interrupt service program will get the interrupt type as rising edge or falling edge and with any way of calculating the time, I can get the period and duty cycle easily.
When I’m looking at doing the same thing with X20, the current idea is run TC#1 as fast as possible (1ms I suppose). But this seems to be a very inefficient way.
I also had a brief look at the reACTION modules, they seems to be high speed counters.
since the Automation Runtime and the whole hardware ecosystem is based on a deterministic runtime behavior, there’s no functionality like “user defined IRQ / ISR” (because this could disturb the realtime operation, for example if the ISR is takes too long to execute).
So the way to solve it is exactly like you described: the digital input state is read and can be used for calculations cyclically - since the X2X bus and the Automation Runtime is deterministic, you have already out-of-the-box a reliable timebase for those calculations.
The minimum possible cycle time and x2x io cycle depends on the PLC you’re using (so even below 1ms is possible, but not with every type of PLC). How fast you really need to read the IO and calculate the frequency and duty cycle depends on your accuracy needs.
Like you mentioned, the’re also IO modules available that can do the measurement job (partly) on the module itself, for example reACTION modules or with digital signal processing modules like the X20DS1319 using it’s edge detection features and the nettime timestamp (that’s a very precise timestamp when for example a edge was detected inside the module) - the named module is only an example, the’re also other X20DS (DS means “digital signal processing” in that context) or X20DC (DC means “digital counter” in that context) modules maybe fitting to your needs.
Using reACTION or X20DS modules are normally used for much faster signals (kHz). To be honest, for me personally it sounds “a bit oversized” using such modules with a 20Hz signal But as I said, I’m not aware of the accuracy you need for this signal, and this resolution needed is the key factor for defining the right hardware module and how to process it.