| General > General Technical Chat |
| Embedded software development. Best practices. |
| << < (3/6) > >> |
| nctnico:
--- Quote from: Neomys Sapiens on August 15, 2021, 10:52:23 pm ---Limiting interrupt processing to the ABSOLUTE MINIMUM NECESSARY is how PLCs achieve their deterministic reaction times and high-integrity program scheduling. Read regular inputs - process cyclical task - write regular outputs. For anything aquired during interrupt processing, you will have to analyse diligently at which point of the program's processing you should introduce this data. Because it would have a detrimental if not even damage-prone effect in most RT applications if you are half through with a calculation and logic processing and then perform the remaining part with a measurement value which does not belong to the same state of the real-world process than your binary inputs. --- End quote --- No. PLCs don't work that way. PLCs have a fixed (configurable) cycle time in which they process all inputs and calculate new output values. And it is possible to run several of these cycles sequentially as if they are parallel processes on more advanced PLCs. But this is all done at a higher (OS) level and the PLC's CPU idles when it is done processing. However, if your PLC program takes too long then the cycle time won't be met. In the end there is no magic bullet to add extra processing power. |
| PaulAm:
Be aware of what your target hardware is and code appropriately. As an example, say your target doesn't support floating point hardware. Even one line of C involving a floating point operation will cause the floating point emulation libraries to be loaded into the object. If you have hardware with very limited stack or code space, that could be a disaster. FSAs are very useful in many situations. However, hand managing FSA tables can be a nightmare and even worse for maintenance. The best way I've found to deal with FSAs over a 40 year career is an FSA generator called Libero written by Pieter Hintjens back around 2000. Pieter was an absolute genius. The code is available on github (https://imatix-legacy.github.io/libero) and will compile with out too much effort. The FSA is described using a dialog and the tool will generate the appropriate tables, stubs, etc. Modifications become fairly trivial since you work at a high level in the dialog and then fill in the short action stub routines. I can't say the examples are all that great, but it's worth a couple days effort to master. The really interesting thing about Libero is that it is not language specific. It uses templates to generate the target code and it will happily turn the FSA into anything. There are templates for Perl, shell, PHP, C, C++ , PC assembly and yes, even Cobol, among others. It's really a universal tool if you can get your head wrapped around it. |
| emece67:
. |
| Neomys Sapiens:
Some useful resources (several are in German): Real-Time Systems Development, A practical Guide to; Sylvia Goldsmith, Prentice Hall, 1993, ISBN 0-13-718503-0 Entwurf komplexer Echtzeitsysteme - State of the Art; Hüsener, BI, 1994, ISBN 3-411-16441-7 Software Engineering Handbook; Jessica Keyes, Auerbach, 2003, ISBN 0-203-97278-3 Handbook of Real-Time and Embedded Systems; Insup Lee et.al, Chapman&Hall/CRC, 2008, ISBN 1-58488-678-1 Design and Analysis of Reliable and Fault-Tolerant Computer Systems; Mostafa Abd-El-Barr, Imperial College Press, 2007, ISBN 1-86094-668-2 Programmable controllers: theory and implementation, L.A. Bryan & E.A. Bryan, Industrial Text and Video, 1997, ISBN 0-944107-32-X Control System Fundamentals (The Control Handbook - 2nd ed.); William S. Levine (Ed.), CRC Press, 2011, ISBN 978-1-4200-7363-8 Computing Handbook - Computer Science and Software Engineering; Allen B. Tucker (Ed.) Chapman&Hall/CRC, 2014, eISBN 978-1-4398-9853-6 Embedded Systems Handbook, Richard Zurawski (Ed.), CRC Press, 2006, ISBN tbd High Performance Embedded Computing Handbook - A Systems Perspective; D.R. Martinez, R.A. Bond, M.M. Vai (Eds.), CRC Press, 2008, ISBN 978-0-8493-7197-4 Numerical Methods for Real-Time and Embedded Systems Programming; Don Morgan, M&T Books, 1992, ISBN 1-55851-232-2 Embedded Systems Building Blocks - Complete and Ready-to-Use Modules in C; Jean J. Labrosse, R&D Books, 2000, ISBN 0-87939-604-1 Anwendungsorientierte Mikroprozessoren, Mikro-controller und Digitale Signalprozessoren; H. Baehring, Springer, 2010, ISBN 978-3-642-12291-0 Practical Aspects of Embedded System Design using Microcontrollers; Balakrishnan Selvan et.al, Springer, 2008, e-ISBN 978-1-4020-8393-8 Software-Implemented Hardware Fault Tolerance; O. Goloubeva et.al, Springer. 2006, ISBN 0-387-32937-4 Embedded Systems - Hardware, Design, and Implementation; Krzysztof Iniewski, Wiley, 2013, ISBN 978-1-118-35215-1 Real-Time Systems Development; Rob Williams, Butterworth-Heinemann, 2006, ISBN 978-0-7506-6471-4 Embedded Systems Design; Steve Heath; Newnes, 2003, ISBN 0-7506-5546-1 Embedded Systems and Computer Architecture, Graham Wilson, Newnes, 2002, ISBN 0-7506-5064-8 Mission-critical and safety-critical systems handbook : design and development for embedded applications; K. Fowler (Ed.), Newnes, tbd, ISBN 978-0-7506-8567-2 Embedded Systems (World Class Designs); Jack Ganssle et.al, Newnes, tbd, ISBN tbd Embedded Software Know-It-All; Labrosse et.al, Newnes, 2008, ISBN 978-0-7506-8583-2 Embedded Hardware Know-It-All; Jack Ganssle et.al, Newnes, 2008, ISBN 978-0-7506-8584-9 |
| Remark:
--- Quote from: emece67 on August 16, 2021, 04:05:36 pm ---Both approaches * keep ISR code at the bare minimum (ideally just trueing flags) and do all tasks in the super-loop * do all your processing on ISRs, keep super-loop task at minimum (ideally NOP)are time-proven approaches. So, what's up with them? Well, I think that both are better suited to different problems. I find myself using 2 when DSP is the main task of the system (also when bit banging), but 1 when it is control. IMHO not any of them substitutes the other, they are complementary. There is also another approach: use a tick to move all the system (this includes polling peripherals at such tick events). I do not use this approach much, though. As now I do more control than DSP, I now use much 1 than 2. Sometimes in bare metal scenarios, some other times using and RTOS. In both cases using FSMs. --- Quote from: PaulAm on August 16, 2021, 02:48:51 pm ---Be aware of what your target hardware is and code appropriately. --- End quote --- This is it! No matter what you code, you must understand what exactly means each line you write. Moving data to and fro and converting data between different formats can be time hogs, so you better avoid them and plan your application keep data movement and format conversions to a minimum. Sometimes such movements and conversions are hidden by the language, so be aware. C/C++? Well, after 30+ years doing all embedded in C and assembly, I'm now switching to C++ (I've used C++ out of embedded also for years, but my C++ experience is definitely smaller than in C). If I can decide, I will never use C again. No bloat at all, code is more readable, same speed, better interfaces, no more need to use that clunky feature named "macros". Sure, it can be done in C and it has been done in C forever, but I prefer C++ now. Regards. --- End quote --- And you probably apply OOP programming when you use the C++ language? |
| Navigation |
| Message Index |
| Next page |
| Previous page |