pia-468x60

pia-728x90

Tuesday, September 22, 2020

PLC A/D converter read ladder diagram instruction

In a digital control system, it usually require an analog input. The analog input, created by any external sensors - an analog temperature sensor, an NTC/PTC or an LDR. These devices create output an analog voltage corresponding to its measuring quantity.
Analog Output Sensors

To read the value from these sensor, the PLC need to command to its analog reading instruction. The A/D converter read instruction is a unique ladder diagram instruction that accomplish the analog input reading using only PLC cycle time.

A/D Converter Read Instruction Symbol

It's configured as follow.

A/D converter Read instruction property

Without any optional settings, the A/D uses a single-end reading mode. The references voltage is internally wired to GND and VDD of the target MCU - for example PIC16F876. For other MCU such as AVR, it's convenient to check the device datasheet and the user's manual of this ladder diagram IDE.

PIC16F876 comes with a 10-bit A/D converter module. It gives a 10-bit resolutions, creates a digital value of 1024 (0 to 1023).

An introductory example show how to use this instruction to read an analog input fed to RA0. The PLC convert the analog input value to digital value before it sends to the host PC via UART terminal. This task is accomplished using a rung of ladder diagram instructions. This rung is activated for every 400 mS, powered by a cyclic on/off timer instruction.



PLC A/D converter read ladder diagram instruction
A/D converter read ladder diagram example

The selected processor of this PLC is PIC16F876, clocks to maximum frequency at 20 MHz. The PLC UART baud rate is 9600 by default due a minimum system requirements.



PLC A/D converter read ladder diagram instruction
Schematic Diagram

Click here to download the zip file of this ladder diagram example.


PLC piece wise linear ladder diagram instruction

In algebra, a line is created by at least two point A(x0,y0) and B(x1,y1), with a line equation y = f(x).
For a typical PLC example, we refer to the ADC reading digital value vs the analog voltage.
PLC piece wise linear ladder diagram instruction
Piece wise linear application with ADC reading

The graph above shows a function of voltage vs its ADC reading. For example,

  • f(0) = 0
  • f(512) = 2.5 V
  • f(1023) = 5 V
Now let move back to LDMicro ladder diagram, the symbol of piece wise linear instruction shown below.
PWL ladder diagram instruction symbol

The property of the instruction allow us to set the name, number of points etc.

PLC piece wise linear ladder diagram instruction
PWL instruction property

For a simple example, I use this instruction to read the analog value fed to RA0 of the PLC and send it over the UART to the host PC.

PLC piece wise linear ladder diagram instruction
PWL ladder diagram example

PIC16F876 is selected as a CPU of this PLC, clocks at 20 MHz to get its maximum computing performance.

  • The PWL table created with only two points. It output a decimal analog voltage, volt.
  • An internal output coil Rstate active for every 600 mS by a timer tick created by a cyclic on/off T0. It activates the ADC instruction to read the analog input voltage fed to RA0 of the PLC MCU.
  • The UART instruction activated by the Rstate to send the analog voltage reading value to the host PC via UART.

PLC piece wise linear ladder diagram instruction
Simulation schematic diagram

Click here to download this ladder diagram example in zip file.


Monday, September 21, 2020

PLC look-up table instruction ladder diagram

A look-up table is commonly found in the low level programming language - assembly. Likewise, in the high level programming language such as C, it's called an array.

In the PLC ladder diagram instruction, a look-up table is combined in only one instruction.

Look-up table instruction

  • A dest (destination) is any variable to copy the content to.
  • LUT[i] is a table with its index i.
The look-up table must have a name, a specific size i with its index i-1. When the input to this instruction true, it sends an element with a specific index to the destination. The overall parameters list below.


Parameters of look-up table instruction

In a simple ladder diagram below, I use this instruction to store a set of ASCII character. It's five in size. The element content of initial index 0 is 65 denotes the ASCII character 'A' and vice versa.

PLC look-up table instruction ladder diagram
Look-up table ladder diagram example


Every one second the PLC send the letter from A to E to the host PC over UART repeatedly. 

PLC look-up table instruction ladder diagram
Schematic Diagram

Click here to download this ladder diagram programming example.



Labels