LDmicro: Ladder Logic For PIC And AVR

De Transcription | Bibliothèque patrimoniale numérique Mines ParisTech
Aller à : navigation, rechercher


Quick summary: I wrote a compiler that begins with a ladder diagram and generates native PIC16 or AVR code. This program is free software program; supply code and executables can be found for download. PLCs are sometimes programmed in ladder logic. This is because PLCs initially changed relay management programs, and forty years later, we nonetheless have not quite let go. A PLC, Alpha Heater official site like every microprocessor, executes an inventory of directions in sequence. Ladder logic instruments abstract this; you'll be able to program the PLC by wiring up relay contacts and coils on-display, and the PLC runtime will simulate the circuit that you have drawn. A few of the relay contacts will be tied to input alerts from the true world; some of the coils might be tied to outputs. That means you can also make your simulated circuit work together with different gadgets, and really management things. That is the point. Actually it's extra general than that, as a result of you'll be able to incorporate timers and counters and arithmetic operations that you simply could not (simply) perform with just relays.



The circuit idea continues to be helpful although, partly just because it is intuitive, but in addition because it abstracts the concurrency issues. This is a simple piece of combinational logic. There are three input phrases, Xa, Xb, and Xc. There may be one output term, Yout. Xa and (Xb or (not Xc)). This makes sense for those who think of Xa and Xb as normally open relay contacts, Xc as normally closed relay contacts, and Yout as a relay coil. That is for a simple thermostat. There are two analog inputs; one among them is for the setpoint, in order that it might, for example, be related to a pot that the user turns to pick the desired temperature. The other gives the temperature measurement; it might be a semiconductor temperature sensor, or a platinum RTD with suitable interfacing circuitry. There's a digital output, Yheater. That may management a heating component, by way of a suitable swap (a TRIAC, or a relay, or a solid-state relay, or no matter).



We close the loop with a easy hysteretic (bang-bang) controller. We've selected plus or minus 20 ADC models of hysteresis. 20), we turn the heater off. I chose to add a few small frills. First, there's an enable input: the Alpha Heater official site is forced off when Xenable is low. This compares towards a threshold slightly colder than (setpoint - 20), so that the sunshine doesn't flicker with the normal cycling of the thermostat. This can be a trivial instance, however it needs to be clear that the language is quite expressive. Ladder logic will not be a general-objective programming language, however it's Turing-full, accepted in industry, and, for a restricted class of (principally control-oriented) issues, surprisingly convenient. Modern sub-3.00 USD microcontrollers most likely have concerning the computing energy of a PLC circa 1975. They subsequently provide more than sufficient MIPS to run moderately complicated ladder logic with a cycle time of a few milliseconds. I feel PLCs often have some type of runtime that's sort of like an interpreter or a virtual machine, but when we're doing easy logic on a processor with out a lot memory then a compiler is likely to be a greater thought.



So I wrote a compiler. You start with an empty rung. You'll be able to add contacts (inputs) and coils (outputs) and more sophisticated constructions to build up your program. Timers (TON, TOF, RTO) are supported. The max/min durations depend upon the cycle time of the `PLC,' which is configurable; timers can depend from milliseconds to tens of minutes. There are counters and arithmetic operations (plus, minus, occasions, div). Circuit components could also be added in series or in parallel with current parts. An I/O checklist is constructed from the ladder logic drawn. You possibly can have internal relays (Rfoo), for which memory is mechanically allotted, or inputs (Xfoo) and outputs (Yfoo), to which you could assign a pin on the microcontroller. The number of pins out there depends upon the microcontroller. I've tried to help the preferred PICs and AVRs (see beneath). Then you'll be able to take a look at this system by simulating it in actual time.