PLC C programming

Hi all

In case I need to implement a PLC with arduino UNO how do I do the routine that will sample all inputs fast enough and will control all outputs .

The problem is that some outputs are delays dependent, so it makes the programming issue harder.

Thanks in advance

Elico

By writing the code that will read the inputs at the appropriate rate and modify the outputs based on their values. Then uploading the sketch to the Arduino board.

If you're going to be really vague, I will be too.

i had once ask this question on the forum. but really after a while i learn that it is quite easy to make the transition. tell me how your program work and i will try to help you

how do I do the routine that will sample all inputs fast enough and will control all outputs

It's not clear, for analog inputs or digital. If digital, there is a way to read / write 8 pins simultaneously using avr-gcc.

Here's a template

while(1) {
    read_some_stuff();
    perform_calculations_on_the_stuff();
    maybe_wait_awhile();
    write_some_stuff();
}

Honestly that's about as good as I can do with such a vague question.

Computing is a precise vocation, be precise.

Would you ask a builder how to build a house and say "I know there's a hammer involved and materials come in and get modified and I heard something about it taking quite some time"


Rob

Scattered showers my arse -- Noah, 2348BC.

[+1]

:), I can't claim to be the author though, I think I read it somewhere a while back.


Rob

The problem is that some outputs are delays dependent, so it makes the programming issue harder.

No, it doesn't. The time to turn an output on, relative to an event, may not be exactly when the event occurs. So, make note of when the event occurred, and, periodically, see if it is time to perform the action.

The time to turn the output off may be relative to when the output was turned on. If so, see above, and change on to off.

Finally was understood !
make note of when the event occurred” can you explain please ?

Eliahu

"make note of when the event occurred" can you explain please ?

If you need to bake a cake, and it needs to bake for 25 minutes, how do you determine when to take it out? You make note of when you put it in the oven. You need to do the same thing, here. The difference is that the watch/clock here is the millis() function.

Many thanks and well done Elico

Are you trying to build a PLC simulator or trying to build a system which could equally controlled by a PLC or a microcontroller such as the arduino?

If it is worthwhile, please visit site http://www.arduoplc.blogspot.it
and select your preferred language.
Find in alpha version a simulator / compiler for Arduino PLC.

Regards.

Giuseppe G.