kingmatrix
Does the editor support interrupts, select the interrupt option, compile error.
The arduino has hardware interrupts.
Reply 0 0
thiagoralves
The editor does not support interrupts yet. Arduino boards have hardware interrupts, but each platform implements it differently. We need to find a consistent way to have interrupts among all supported platforms.
Reply 0 0
r2k-in-the-vortex
That's not how plcs in general work. You have the cyclic tasks and that's it. Encoder readers, servo drives, these are external devices separate from a plc.
Reply 0 0
r2k-in-the-vortex
Huh, really, how does that work? I tried to google some but didn't find anything, do you have a link where I could read more from? Are they true interrupts or just cyclic checks that conditionally trigger some code?
Reply 0 0
thiagoralves
There are some PLCs that support interrupts, that’s true. You just need to be extra careful with the timing, because if you spend too much time in the interrupt routine you will mess up your main plc cycle.

OpenPLC Editor in fact supports interrupts. This is a feature inherited from Beremiz. The problem is that the OpenPLC Runtime does not support interrupts yet. I’ll take a look into this to see if there is an easy way to implement it in the runtime.
Reply 0 0
openplc80
That's not how plcs in general work. You have the cyclic tasks and that's it. Encoder readers, servo drives, these are external devices separate from a plc.


I do not agree. They have cyclic, events (interrupt driven tasks), specific blocks for reading incremental encoders or for fast counters, and output blocks for PWM or pulse generation for motor control.

Only higher end PLCs do not concentrate on those capabilities, They propose to use dedicated blocks for a more or less proprietary bus and proprietary hardware, for reading encoders and for motor control.

But in this case the price rise a lot. OpenPLC is not in this area and should stay compatible with simple hardware (incremental encoders, PWM, pulse generation, and common and simple buses like Modbus).


With that, it is possible to make great things.
Reply 0 0
openplc80
There are some PLCs that support interrupts, that’s true. You just need to be extra careful with the timing, because if you spend too much time in the interrupt routine you will mess up your main plc cycle.

OpenPLC Editor in fact supports interrupts. This is a feature inherited from Beremiz. The problem is that the OpenPLC Runtime does not support interrupts yet. I’ll take a look into this to see if there is an easy way to implement it in the runtime.


I've read that it is possible as well to run a task from a software interrupt, called from a global variable set to true. Is it working inside OpenPLC ?
Reply 0 0
thiagoralves
The runtime does not implement any type of interrupt, software or hardware. In any case, you can fake out a software interrupt just by calling a function block when a variable is true in your program. This is limiting as the period in which the input is updated is tied to your scan cycle time. I understand that having the possibility of calling routines through hardware interrupts is important and I plan to bring it into the runtime in the future.
Reply 0 0
openplc80
The runtime does not implement any type of interrupt, software or hardware. In any case, you can fake out a software interrupt just by calling a function block when a variable is true in your program. This is limiting as the period in which the input is updated is tied to your scan cycle time. I understand that having the possibility of calling routines through hardware interrupts is important and I plan to bring it into the runtime in the future.


Very nice.
In the last project i did with OpenPLC, i did use two programs to compensate for the lack of interrupts. The main program was running at 20 ms period, and the second one, with only a frequency meter bloc inside, was running at 5 ms period, to allow for a higher capture frequency. Then i did use a global variable to exchange the mesured frequency with the main program.

This is a workaround to get a better responsiveness but it is far from the efficiency of an interrupt task (named Events on some PLCs).

I remember i did use an Event task on a Twido PLC to capture the index pulse from an incremental encoder, to get higher precision at axis initialisation.

I did work a couple times with low level code on the AVR platform, using interrupt is not complicated because interrupt management on the AVR or AVR Mega is very basic.

On some AVR controllers, there are a few more hardware interrupt sources available, not only a pin going high or low. This need to be checked in the documentation of each controller. A good tool to check this is Codevision AVR, because it gives a clear view of what is available for each controller at the hardware level, and what code is needed to get it working, without spending a lot of time in the data-sheets.

I think that Microchip Studio has a comparable code generator tool, but Codevision seems simpler, and is now bundled with Microchip Studio.




Reply 0 0
thiagoralves
Yes, implementing interrupts on AVR is easy. The thing is that OpenPLC runtime runs on AVR 8-bit, arm (various models), espressif esp cores, risc V, etc…. Managing interrupts in all those different platforms is the problem
Reply 0 0
openplc80
Would it be simpler (and doable) to use an intermediate realtime OS as an isolation layer between low level hardware and the runtime ?
Reply 0 0
openplc80
Yes implementing all platforms would be difficult or time consuming because each one has slightly different implementation. Even AVR has one special thing, 16 bits words can be corrupted during interrupt calls and must be managed with a special code checking for corruption.

Implementing a single platform, like 8 bits Mega AVR, would be probably a good start. Anyway without EEPROM (for settings memory) and I/O blocks support (fast counters, PWM and pulse output), OpenPLC is actually limited to small or medium projects and does not fully profit from 32 bits processors.

More, Mega AVR has a clear documentation that does not need a lot of time to read.
Reply 0 0
Reply