⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tiny_plc.txt

📁 单片PLC,AT2581实现梯形图功能,可作为参考
💻 TXT
📖 第 1 页 / 共 4 页
字号:
TinyPLC documentation

---------------------------------------------------------------------------

My thanks to my employer, Athena Controls (www.athenacontrols.com) for
permission to make this work open source.

---------------------------------------------------------------------------

TinyPLC started life as a project for work.  We have a new multi-zone
embedded control board, and one goal is to allow user programmability for
the "main loop".

So, we looked at PLCs and "logic programming" as a model for programmability.

And, early in 2006, I was told that we wanted a working demonstration for
a trade show.  I had one month to put it together.

So, I tried my best, writing a PLC editor/compiler to be run on a PC and a
PLC "kernel" for our embedded board, based on an Atmel ATmega 1281 or 2561
processor.

Of course, after the trade show, the PLC was basically shelved, with
"logic programming" becoming our preferred method of user programability.

After the work I had put into this, however, I didn't want to just throw
it away.  And since I am working on the now open-source DeSmet C compiler,
which for "some reason" :) I just happened to use for the PLC editor/compiler
(after all, I needed to have something working FAST!), I though it would
be a good showcase for the capabilities of the DeSmet compiler.

Thanks to the generosity of my employer (www.athenacontrols.com), I was
given permission to make this work open source.


---------------------------------------------------------------------------

Section I:   PLC editor/compiler documentation

Section II:  TinyPLC kernel documentation

Section III: Technical notes and suggested improvements


---------------------------------------------------------------------------

Section I:   PLC editor/compiler documentation

The PLC editor/compiler is PLC.EXE, consiting of the source files
   PLC.C
   PLC2.C
   PLC.H
   PLCSHARE.H
   CHARSET.H
   BIGCHAR.H
compiled and lined with DeSmet C, version 2.51 (aka PCC version 1.2D).
   C88 PLC
   C88 PLC2
   BIND PLC PLC2

PLC is a graphical editor that uses a mouse for most operations.  Graphics
are implemented via VESA BIOS extenions (should be standard), graphics
mode 0x0105 (1024 x 768 x 256 color).  The program will inform you if
this mode is not availble (Under Windows, make sure you are running in
"full-screen" DOS mode.  If you see a title bar, you are in a window.  Press
Alt-Enter to switch to full-screen mode.)  The mouse is implemented via the
"standard" Interrupt 33h calls (see Ralf Brown's interrupt list for more
information).

There are 4 command line parameters that may be used with PLC:
   -B<baudrate>      Set baudrate to <baudrate>  The default is 9600.
   -Q                Set quickexit.  Do not ask to save modified
                     ladder on exit, useful for debugging PLC.EXE
                     Default is quickexit = FALSE.
   -E                Target TinyPLC kernel is big-endian.  The default
                     is little-endian.
   1 or 2 or 3 or 4  COMM port to use.  The default is 1.

PLC stands for Programmable Logic Controller, a class of device used to
implement machine control systems.  While there are several different
"flavors" of PLC programming, PLC.EXE implements "ladder logic", which is
a modern implementation of early control systems, which consisted of relays
and like devices strung on wires in parallel.  When the diagrams of these
circuits are viewd on paper, the parallel wires connecting the power and
ground busses resembles a ladder.

Each rung of the ladder starts with a value of TRUE (line is energized),
which affects and is affected by the elements placed on the rung.

There are a number of "objects" and "operands" that can be placed on a
rung to implement the desired control system.  Objects are memory mapped
into TinyPLC's 256 32-bit storage locations:

   INPUTS:     There are 32 inputs, X0 .. X31.

   OUTPUTS:    There are 32 outputs, Y0 .. Y31.

   ANALOGS:    There are 32 analog inputs, A0 .. A31.

   VARIABLES:  There are 32 variables, V0 .. V31.  Each variable can hold a
               32-bit number.  V31 is special, and contains the status flags
               from arithmetic and logical 
               operations.
                     V31 & 1 = Carry status
                     V31 & 2 = Overflow status
                     V31 & 4 = Zero status
                     V31 & 8 = Negative status
                     V31 & 16 = Stack overflow/underflow error
                     V31 & 32 = Divide by 0 error

   TIMERS:     There are 16 timers, T0 ..  T15.  Each timer is 32-bits (0 .. 
               4,294,967,295) with 1ms resolution.
               Note: each timer uses 2 32-bit storage locations.

   COUNTERS:   There are 32 counters, C0 .. C31.  Each counter is 32-bits
               (0 .. 4,294,967,295).

   ONESHOTS:  There are 32 oneshot registers, R0 .. R31
              NOTE: when a ladder program is initalized, the previous state
                    of the inputs to oneshots is assumed to be FALSE.  As a
                    result, a oneshot can be used at the start of a rung to
                    execute initalization logic.

This accounts for 224 of the availble 256 storage locations.  The other
32 are reserved, and may be used for other types of storage, or may be
used to expand already existing data types.

It should be noted that, while the logic may allow (for example) 32 inputs,
the hardware may not.  The number of each type of object may be adjusted to
match the hardware limits, and the unused storage locations put back into
the available pool.

A logic ladder consists of 10 elements per rung (limited by screen resolution)
and up to 32 rungs (this may be changed by a single line change in the source
code).  Note that OR branches may add considerably to the complexity, with
up to 64 total rungs / branches (this may be changed by a single line change
in the source code).

The ladder symbols are:

   Inputs:
      --[ ]--  Normally Open input (output follows input)

      --[/]--  Normally Closed input (output is invert of input)

      Inputs may reference INPUTS, OUTPUTS, ANALOGS, VARIABLES, TIMERS,
      COUNTERS, and ONESHOTS.  A non-zero is considered TRUE, a zero is
      FALSE.

   Outputs:
      --( )--  Normally Open output (is set to line truth value)

      --(/)--  Normally Closed output (output is invert of line truth value)

      -(LAT)-  Latching output (output is TRUE if line is TRUE, else output
               does not change)

      -(UNL)-  Unlatching output (output is FALSE if line is TRUE, else
               output does not change)

      Outputs may be OUTPUTS (Y0 .. Y31) or VARIABLES (V0 .. V31).  A
      non-zero is considered TRUE, a zero is FALSE.

   Math operations:
      -(ADD)-  If line is TRUE, add two operands.  i.e. V0 = V1 + V2

      -(SUB)-  If line is TRUE, subtrace two operands.  i.e. V0 = V1 ? V2

      -(MUL)-  If line is TRUE, multiply two operands.  i.e. V0 = V1 * V2

      -(DIV)-  If line is TRUE, divide two operands.  i.e. V0 = V1 / V2

      -(MOD)-  If line is TRUE, take modulo of two operands.
               i.e. V0 = V1 % V2

      -(NEG)-  If line is TRUE, negate a variable.

      -(MOV)-  If line is TRUE, move value to variable.

      For ADD, SUB, MUL, DIV, and MOD, the node takes two operands (which may
      be of any type discussed above or ONE of the operands may be a CONSTANT
      in the range of 0 to 255), and the destination must be a VARIABLE.

      For NEG, the associated operand can only be a VARIABLE.

      For MOV, the destination must be a VARIABLE, while the value may be any
      type discussed above or a CONSTANT in the range of -2147483648 to
      2147483647.

   Logical Operations:
      -(AND)-  If line is TRUE, do a bitwise AND of two operands.
               i.e. V0 = V1 & V2

      -(OR)--  If line is TRUE, do a bitwise OR of two operands.
               i.e. V0 = V1 | V2

      -(XOR)-  If line is TRUE, do a bitwise XOR of two operands.
                i.e. V0 = V1 ^ V2

      -(NOT)-  If line is TRUE, do a logical NOT of the operand.

      For AND, OR, or XOR, the node takes two operands (which may be of any
      type discussed above or ONE of the operands may be a CONSTANT in the
      range of 0 to 255), and the destination must be a VARIABLE.

      For NOT, the associated operand can be a VARIABLE or an OUTPUT.

   Compare Operations:
      -[EQ]--  Compare two operands, set line TRUE if they are equal
               else FALSE

      -[NE]--  Compare two operands, set line TRUE if they are not equal
               else FALSE

      -[GT]--  Compare two operands, set line TRUE if OP1 > OP2 else FALSE

      -[GE]--  Compare two operands, set line TRUE if OP1 >= OP2 else FALSE

      -[LT]--  Compare two operands, set line TRUE if OP1 < OP2 else FALSE

      -[LE]--  Compare two operands, set line TRUE if OP1 <= OP2 else FALSE

      The two operands may be any of type discussed above or ONE of the
      operands may be a CONSTANT in the range of 0 to 255.

   Counter Operations:
      -[CTT]-  Count FALSE to TRUE transitions of the line, set output to
               TRUE when the preset limit is reached.

      -[CTF]-  Count TRUE to FALSE transitions of the line, set output to
               TRUE when the preset limit is reached.

      -[RST]-  If line is TRUE, reset a timer or a counter.

      There is a COUNTER associated with CTT or CTF.  Re-using a COUNTER
      in another node is a bad idea.  The preset limit is a CONSTANT in the
      range of 0 to 65535.

      The operand of RST must be a COUNTER or a TIMER.

   Timer Operations:
      -[TMT]-  Measure time that line is TRUE.  If this is more than a
               preset limit, set output to TRUE.  The timer is reset when
               the line is FALSE.

      -[TMF]-  Measure time that line is FALSE.  If this is more than a
               preset limit, set output to TRUE.  The timer is reset when
               the line is TRUE.

      -[RTT]-  Measure cumulative time that line is TRUE.  If this is more

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -