Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
1 1999613
  • Project overview
    • Project overview
    • Details
    • Activity
  • Issues 11
    • Issues 11
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Package Registry
  • Analytics
    • Analytics
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Create a new issue
  • Jobs
  • Issue Boards
Collapse sidebar
  • Klaus Overstreet
  • 1999613
  • Issues
  • #8

Closed
Open
Created Sep 28, 2025 by Klaus Overstreet@klausoverstreeMaintainer

LDmicro: Ladder Logic for PIC and AVR


Quick abstract: I wrote a compiler that starts with a ladder diagram and generates native PIC16 or AVR code. This program is free software program; supply code and executables are available for obtain. PLCs are sometimes programmed in ladder logic. It is because PLCs originally replaced relay control methods, and forty years later, we still have not fairly let go. A PLC, energy efficient heating like several microprocessor, executes a list of instructions in sequence. Ladder logic instruments 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 drawn. Some of the relay contacts might be tied to input indicators from the true world; among the coils may be tied to outputs. That manner you may make your simulated circuit work together with different units, and actually control issues. That is the purpose. Actually it's extra common than that, because you'll be able to incorporate timers and counters and arithmetic operations that you just could not (simply) perform with simply relays.


The circuit idea is still useful although, Alpha Heater official site partly just because it is intuitive, but additionally because it abstracts the concurrency issues. This is an easy piece of combinational logic. There are three input terms, Xa, Alpha Heater official site Xb, and Xc. There is one output time period, Alpha Heater official site Yout. Xa and (Xb or (not Xc)). This makes sense in the event you consider Xa and Xb as normally open relay contacts, Xc as normally closed relay contacts, and Yout as a relay coil. This is for Alpha Heater blog a easy thermostat. There are two analog inputs; considered one of them is for the setpoint, in order that it might, for instance, be related to a pot that the person turns to pick out the desired temperature. The other supplies the temperature measurement; it might be a semiconductor temperature sensor, or Alpha Heater official site a platinum RTD with suitable interfacing circuitry. There's a digital output, Yheater. Which may control a heating component, by means of an appropriate switch (a TRIAC, or a relay, or a solid-state relay, or whatever).


We shut the loop with a simple hysteretic (bang-bang) controller. We have now selected plus or minus 20 ADC items of hysteresis. 20), we turn the alpha heater reviews off. I chose to add a couple of small frills. First, there may be an enable input: the Alpha Heater official site is forced off when Xenable is low. This compares in opposition to a threshold slightly colder than (setpoint - 20), in order that the sunshine does not flicker with the traditional cycling of the thermostat. This can be a trivial instance, but it needs to be clear that the language is sort of expressive. Ladder logic will not be a basic-purpose programming language, but it is Turing-complete, accepted in trade, and, for Alpha Heater official site a limited class of (largely management-oriented) problems, surprisingly convenient. Modern sub-3.00 USD microcontrollers in all probability have about the computing power of a PLC circa 1975. They subsequently provide more than enough MIPS to run fairly complicated ladder logic with a cycle time of a few milliseconds. I feel PLCs usually have some type of runtime that's type of like an interpreter or a digital machine, but if we're doing easy logic on a processor with out a lot memory then a compiler could be a greater concept.


So I wrote a compiler. You begin with an empty rung. You may add contacts (inputs) and coils (outputs) and extra complicated structures to construct up your program. Timers (TON, TOF, RTO) are supported. The max/min durations depend on the cycle time of the `PLC,' which is configurable; timers can rely from milliseconds to tens of minutes. There are counters and arithmetic operations (plus, minus, times, div). Circuit components may be added in sequence or in parallel with present parts. An I/O listing is built from the ladder logic drawn. You may have inner relays (Rfoo), Alpha Heater official site for which reminiscence is automatically allotted, or inputs (Xfoo) and Alpha Heater portable outputs (Yfoo), to which you need to assign a pin on the microcontroller. The selection of pins available relies on the microcontroller. I've tried to support the most well-liked PICs and AVRs (see below). Then you may take a look at this system by simulating it in real time.

Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking