LDmicro: Ladder Logic For PIC And AVR

De Transcription | Bibliothèque patrimoniale numérique Mines ParisTech
Révision datée du 25 novembre 2025 à 11:58 par KaraShumack6739 (discussion | contributions) (Page créée avec « <br>Quick abstract: I wrote a compiler that starts with a ladder diagram and generates native PIC16 or AVR code. This program is free software; supply code and executables... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Aller à : navigation, rechercher


Quick abstract: I wrote a compiler that starts with a ladder diagram and generates native PIC16 or AVR code. This program is free software; supply code and executables can be found for download. PLCs are sometimes programmed in ladder logic. This is because PLCs originally changed relay control methods, and forty years later, we still have not fairly let go. A PLC, like all microprocessor, executes a list of directions in sequence. Ladder logic tools summary this; you can program the PLC by wiring up relay contacts and coils on-display, and the PLC runtime will simulate the circuit that you've got drawn. A number of the relay contacts will be tied to enter alerts from the real world; among the coils can be tied to outputs. That method you can also make your simulated circuit work together with different gadgets, and actually control issues. That's the purpose. Actually it's extra general than that, because you may incorporate timers and counters and arithmetic operations that you could not (easily) perform with just relays.



The circuit idea remains to be helpful although, partly simply because it's intuitive, but also because it abstracts the concurrency issues. This is a simple piece of combinational logic. There are three input terms, Xa, Xb, and Xc. There is one output time period, Yout. Xa and (Xb or (not Xc)). This makes sense for those who consider Xa and Xb as usually open relay contacts, Xc as usually closed relay contacts, and Yout as a relay coil. That is for a easy thermostat. There are two analog inputs; one in every of them is for the setpoint, in order that it'd, for example, be linked to a pot that the user turns to select the specified temperature. The other supplies the temperature measurement; it could be a semiconductor temperature sensor, or a platinum RTD with suitable interfacing circuitry. There is a digital output, Yheater. That may control a heating element, through an acceptable swap (a TRIAC, or a relay, or a strong-state relay, or whatever).



We close the loop with a simple hysteretic (bang-bang) controller. We have selected plus or Alpha Heater online store minus 20 ADC models of hysteresis. 20), we turn the Alpha Heater online store off. I selected to add just a few small frills. First, there is an allow input: the heater is forced off when Xenable is low. This compares against a threshold barely colder than (setpoint - 20), so that the light doesn't flicker with the conventional cycling of the thermostat. It is a trivial example, but it needs to be clear that the language is quite expressive. Ladder logic will not be a normal-goal programming language, however it is Turing-full, accepted in industry, and, for a limited class of (largely management-oriented) problems, surprisingly handy. Modern sub-3.00 USD microcontrollers probably have concerning the computing energy of a PLC circa 1975. They due to this fact provide greater than enough MIPS to run fairly complex ladder logic with a cycle time of some milliseconds. I think PLCs usually have some form of runtime that's form of like an interpreter or a digital machine, but if we're doing simple logic on a processor with out a lot reminiscence then a compiler may be a better concept.



So I wrote a compiler. You begin with an empty rung. You'll be able to add contacts (inputs) and coils (outputs) and extra difficult buildings to construct up your program. Timers (TON, TOF, RTO) are supported. The max/min durations rely upon the cycle time of the `PLC,' which is configurable; timers can count from milliseconds to tens of minutes. There are counters and arithmetic operations (plus, minus, occasions, div). Circuit parts may be added in series or in parallel with existing components. An I/O record is built from the ladder logic drawn. You'll be able to have inner relays (Rfoo), for which reminiscence is routinely allocated, or inputs (Xfoo) and outputs (Yfoo), to which you must assign a pin on the microcontroller. The collection of pins obtainable relies on the microcontroller. I've tried to help the preferred PICs and AVRs (see below). Then you may check the program by simulating it in real time.