1131 runtime on FreeRTOS with PIC
Posted by Mihai
on March 11, 2010
I’d like to check if FreeRTOS suits to my demand to run it in a microcontroller such as PIC18, or dsPIC from Microchip in order to hide their hw details for a new application: a microPLC that is able to support a 61131 runtime for PLC automation projects.
For those that don’t know, in principle, a 1131 runtime is a forever loop that first reads the INPUTs of an I/O list (values being sampled beforehand based on interrupts), then process these inputs variable in a simple logic (AND/OR, .... sometimes more complex math like translating engineering units degree->radians, etc) with a dataflow imposed by various timers (TON, TOFF, ...), and writes the OUTPUTs back to the hardware.
Basically, looking at FreeRTOS design, I think that this 1131 runtime is a high-priority task together with an idle task for power-saving (sleep moments). In addition we also have the data acquisition component (that is interrupt driven). So, I don’t have lots of tasks, nor a complex priority scheme.
I personally don’t know if it’s useful to have a RTOS (and its overhead) on small microcontrollers such as PICs, for the application I described above with 1131 runtime. I wonder because one of the biggest problem in implementing 1131 runtime is supporting of various timers (hopefully using HW timers as available by specific PIC) and FreeRTOS doesn’t support hw specific timers, nor allow custom timers (I’ve read this post: http://sourceforge.net/projects/freertos/forums/forum/382005/topic/3585958). In our 1131 runtime, we need timers to enable/disable various branches of the dataflow (e.g. code if/then/else, switch) within this task, not necessarily enabling other tasks.
I don’t know if you have met such application which requires a 1131 runtime, but if you do, please share the good/bad experience.
RE: 1131 runtime on FreeRTOS with PIC
Posted by Richard
on March 11, 2010
In my experience PLCs generally sample inputs at a fixed frequency, whereas RTOS based designed benefit most from event driven architectures (where lots of time can be saved because the need to poll is completely removed).
There is no reason why you could not implement this in an RTOS, especially if you have multiple communication interfaces that need services (as is common in PLCs) which is another area you are likely to see benefits. If the overall CPU load was relatively low, and power consumption was not an issue, then I'm sure you could just as easily do it bare back.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.