Monday, September 28, 2020

PLC if-not-equal ladder diagram instruction

In the previous post we have show about an equal comparison instruction. In LDMicro ladder diagram PLC instruction set there are up to six comparison instructions. These are very easy to understand to most experienced programmers. We will not list them all due to the repetitions. 

A list of PLC comparison ladder diagram instructions

For now and final of these instructions, I will show only the example of the If-Not-Equal ladder diagram instruction. This instruction make a logical comparison of its operands whenever its input is true. If the logical operation those two operands is not equal it will output true.

A very simple example shows how to use this instruction with the UART. The PLC keep track of reading the the character from UART terminal. If the received character is letter 'A' then the output coil is off, otherwise it's true.



PLC if-not-equal ladder diagram instruction
If not equal ladder diagram instruction example


The circuit diagram show only the PIC-based PLC with its basic connections and the host PC UART terminal.

PLC if-not-equal ladder diagram instruction
Schematic diagram



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


Sunday, September 27, 2020

PLC piecewise linear table instruction to convert A/D value into PWM duty cycle

In the previous post, I have show to use piecewise linear table to convert between ADC value to analog voltage value. The advantage of this instruction is that the programmer could map between two value without putting any math equation into the PLC ladder diagram program.

Here, I use this instruction to map the A/D converter digital value into the PWM duty cycle that it will adjust the speed of a DC motor. I create a piecewise linear table with three points on the graph A(x0,y0) B(x1,y1) and C(x2,y2).

PLC piecewise linear instruction to convert A/D value into PWM duty cycle
A piecewise linear table that return a duty cycle value in term of the ADC0.

The main ladder diagram program keeps track of three main tasks:
  1. Reading the A/D converter value and converts it to the PWM duty cycle value via a piecewise linear table.
  2. Sending the current PWM duty cycle to the host PC via UART terminal
  3. Adjusting the motor speed via its PWM duty cycle.


PLC piecewise linear instruction to convert A/D value into PWM duty cycle
The Ladder Diagram Program

I selected PIC16F876 due a the ease of use.

PLC piecewise linear instruction to convert A/D value into PWM duty cycle
Schematic Diagram

Click here to download this ladder diagram example.



Saturday, September 26, 2020

PLC one-shot low level (OSL) ladder diagram instruction

A one-shot low level (OSL) instruction is a normally output true instruction. Whenever its input is false then it output false for a PLC scan cycle.

The one shot low level instruction symbol

For more details let see its timing diagram.
The OSL timing diagram

This instruction is useful in the case that the user needs to trigger the action on the falling to low level of the input signal.

In the following example, we create a sample monitoring of this instruction. Whenever the user switch the input contact to the ground, the contact makes a input false signal to the OSL. This OSL again trigger a low level pulse of one PLC scan cycle of 10 mS.



PLC one-shot low level (OSL) ladder diagram instruction
The OSL ladder diagram example

The output coil Y0 is normally output true in the overall PLC program. The output coil Y1 outputs true when there's nothing happen.

PLC one-shot low level (OSL) ladder diagram instruction
Circuit Diagram



Click here to download the zip file of this working example.



Friday, September 25, 2020

PLC circular shift ladder diagram instruction

A shift instruction commonly found in the high level programming language such as C. Here in the PLC ladder diagram they include a circular shift instruction that support a carry bit. 

Circular shift left and right

The shift operation works in two directions - right and left. After the shift operation the data just change its position but all bits will not lost their value.

The operation of these two instructions

When the input to these instruction is true it start its circular shift operations with any specific position. The position is set in the operand2 of instruction property.

The circular shift left ROL instruction property

The circular shift right ROR instruction property

For a simple example I use these two instruction to chase the LEDs.



PLC circular shift ladder diagram instruction
Ladder diagram example

PIC16F876 uses most of its I/O pins to output the LED chasing.



PLC circular shift ladder diagram instruction
Schematic Diagram

Click here to see the folder of this working ladder diagram example.



PLC UART example to adjust the PWM duty cycle

Revising the UART and PWM ladder diagram instructions as a topic, Today I use these two main instructions to adjust the PWM output.

The UART terminal of the host PC receives the character command from the user to increase/decrease the duty cycle. I use letter 'P' to increase the duty cycle and letter 'N' to decrease the duty cycle.

There some others remanding instruction that I don't want to show any detail here due to the previous post's explanation.

PLC UART example to adjust the PWM duty cycle
Ladder diagram example


The initial set up assigns the duty cycle to 0 - there's no output power. A UART terminal prompt the user once in how to adjust the duty cycle.

Once the character command is prompted the PWM duty cycle is adjust within the step of 10% in duty cycle.

PLC UART example to adjust the PWM duty cycle
The schematic diagram

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

PLC one shot rising ladder diagram instruction

In the PLC ladder diagram a one shot instruction creates a one shot signal output. For the one shot rising OSF instruction, it output a high pulse for one PLC cycle time - for example 10 mS, whenever its input true. This output pulse only create one's until the system is reset.
The one shot rising instruction symbol

This instruction is an auxiliary to other instruction in the same rung. It's place in front of other instructions to make them run only once when the program started.



Let take a look at a simple ladder diagram example. 

PLC one shot rising ladder diagram instruction
OSF ladder diagram example program

An OSF activate the turn off delay T0F that create a high delay time for 10 second before it's fall. So the output coil Y0 turned on for only 10 second in the PLC program.



PLC one shot rising ladder diagram instruction
The ladder diagram programming example of the OSF

Click here to download the zip file of this working example.


PLC toggle type coil ladder diagram instruction

In the PLC ladder diagram, a coil is classified into many types as shown in the picture below.

Many options of coil types selection.

As we can see in the picture below a coil could be an internal relay, an output pin on MCU or a Modbus. There are five different types of coil. Here we select the T-trigger (T) type. The letter T means 'toggle'.

A T-trigger coil changes (toggles) its output logic state whenever it's input change from low to high.

Let look at very simple example, I use an input contact to change the logic state of the output coil.

PLC toggle type coil ladder diagram instruction
Toggle type coil ladder diagram example

When the contact XC2 changes from false to true, the output coil changes its logic state.



We can make a circuit simulation in Proteus to verify the result.

PLC toggle type coil ladder diagram instruction
Ladder diagram program example

This program could run on an 8-pin PIC16F629 for convenience. My YouTube video show about a testing program on my DIY PLC board I made a few years ago.



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

Thursday, September 24, 2020

PLC equal comparison ladder diagram instruction

Just like other programming language, math comparison instruction is always existed. In ladder diagram these kinds of instruction built in symbols rather than a text.

A list of ladder diagram instruction symbols

We have six comparison instructions list above,
  1. if equal
  2. if not equal
  3. if greater than
  4. if less than
  5. if greater than or equal
  6. if less than or equal
When the input to the instruction is true, it make a comparison between two operands as set in its property. This instruction will output true whenever the result of the comparison returns true.

For a simple example to test this instruction, I use the if equal ladder diagram instruction to compare between the preset characters and the received characters from UART. If the comparison is true the program will turn on/off the output coil.



PLC equal comparison ladder diagram instruction
Ladder diagram example

In this example we use internal set and reset output coils to control an external output coil.



PLC equal comparison ladder diagram instruction
Schematic diagram

Click here to download the zip file of this working example.



PLC turn-on delay Tdon ladder diagram instruction

This instruction is a type of PLC delay timer. The timer on delay Tdon instruction keeps track of its input high time but it's not store the timing value like the retentive timer.
Tdon instruction symbol

If the input high time into this instruction is greater than the preset delay time, it will output true. And it will change to false at the moment the input falls to low.

PLC turn-on delay Tdon ladder diagram instruction
Tdon timing diagram. The input delay time of one second is set in the
instruction property.

The delay time may be preset in its property.

PLC turn-on delay Tdon ladder diagram instruction
Tdon instruction property. The picture above I set the delay time to 5000 mS or five seconds.

A very simple and easy ladder diagram example show a single rung of the program that made of an input contact, a Tdon instruction and an output coil.



PLC turn-on delay Tdon ladder diagram instruction
Ladder diagram example program

It's not necessary to draw and simulate the ladder diagram in any EDA software. But I wish you can make it as leisure. 



PLC turn-on delay Tdon ladder diagram instruction
Schematic Diagram

Click here to download the zip file of this working example.


PLC turn-off delay Tdoff ladder diagram instruction

Referring to the timer delay related instructions in the PLC ladder diagram instructions, we are now discussing about another timer delay called turn-off delay (Tdoff). 

Turn-off delay instruction symbol

When ever the input to this instruction changes from false to true, it will output true for a specific delay time. The input high time must greater or equal to the PLC cycle time.

PLC turn-off delay Tdoff ladder diagram instruction
Timing diagram for Turn-off delay instruction

Let see a very simple example. I use an input contact to turn on an output coil for 10 seconds.



PLC turn-off delay Tdoff ladder diagram instruction
Turn-off delay ladder diagram instruction example

We configure the Tdoff instruction as below.

The delay time is set to 10000 mS or 10 second.

It's convenience to add a one-shot rising to the rung to prevent the rung become true while the input contact X0 is in a long press duration.

The remanding open-circuit rungs are just an example of cutting the rungs. 



For a serious PLC programmer they always need to test the program in both hardware and software. However, we already know that the overall program is completedly work. So It's not necessary to test this program in another software simulation and in the hardware.

PLC turn-off delay Tdoff ladder diagram instruction
Schematic diagram

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


PLC piecewise linear table and 7-segments instruction

With the piecewise linear table again, I use this instruction to create a map of characters from 0 to F presenting a hexadecimal values.

The host PC UART terminal send the ASCII character within a range of 0 to 15 to the PLC. These value will be converted by the PLC piecewise linear table instruction before it's sent to the 7-Segment display.

PLC piecewise linear table and 7-segments instruction
Piecewise linear table instruction setting

The ladder diagram program made up of a few rungs as listed below.

PLC piecewise linear table and 7-segments instruction
Ladder diagram example

The PLC hardware made up of a few components, a 7-segment display, clock and reset circuit. We assume that the user use a USB-serial converter to make a communication between the PLC and the host PC.


PLC piecewise linear table and 7-segments instruction
Schematic diagram

I made a photo of sample of the running program of PLC.



A sample of running program. The UART send a list of character ended with letter 'A'.

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


Application of Piecewise Linear and ADC Instruction with LM35 thermometer

In this example we want to demonstrate some working instructions that we have learn before,
  1. cyclic on/off timer
  2. contact and coil
  3. read A/D converter
  4. piecewise linear table
  5. if greater than instruction
  6. formatted string over UART
Using these instruction we can make a typical application of a temperature controlled system.

In this example, the PLC reads an analog temperature converted by LM35 analog temperature sensor. A buzzer will alarm whenever the temperature exceed 40 degree Celsius. Temperature data sent over the UART terminal to the host PC.

A commercial sample of LM35 from an online market place.


Application of Piecewise Linear and ADC Instruction with LM35 thermometer
Ladder diagram example

Cyclic on/off timer T0 activate the internal output coil Ready for every one second. This coil command the A/D converter read instruction ADC0. It also command the PLC to sent data over the UART terminal to the host PC.



Piecewise linear table create the temperature data table corresponding to the analog voltage value converted by LM35 analog temperature sensor.

Application of Piecewise Linear and ADC Instruction with LM35 thermometer
The temp is a function of ADC0. This table created by three points.
It return a temperature data between 0 and 150 degree Celsius.

A comparison instruction if greater than compare the analog temperature with 40 degree Celsius, a preset value made by the programmer. If the temperature exceed 40 degree Celsius it will output true turning the alarm buzzer.



Application of Piecewise Linear and ADC Instruction with LM35 thermometer
Schematic diagram

An alarm buzzer could be any type - a simple active 5V buzzer or a active 12 V buzzer. Selecting the right buffer driver depends on the user. There are a lot of driver available in the online market place. I don't want to specify them here.

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


Wednesday, September 23, 2020

PLC piecewise linear table instruction and SSD example

So far we have learned about,
  • Piecewise linear table
  • shift register
  • UART 
  • Counter 
  • And one shot 
Now we combine, these instruction to make a simple example. In this example the user send the ASCII characters over the UART terminal to the PLC.

PLC piecewise linear table instruction and SSD example
Ladder diagram example

A circular counter activates the four digits multiplexed displays. The display port is PORTC. Each digit becomes active for 2 mS.

A set of UART instructions send and receive the characters between the host PC and the PLC. 



A five stages shift register, receives the character sent from UART before it sends to the multiplexed display.

PLC piecewise linear table instruction and SSD example
Schematic Diagram

The picture below is a sample of program simulation.



PLC piecewise linear table instruction and SSD example
A sample of program

Click here to download the ladder diagram example.


PLC GOTO and LABEL ladder diagram instruction

The GOTO instruction command the PLC program to jump to a specific rung. Rung may have a LABEL or may not.

When the input goes to this rung is true, it causes the program to rung N or any rung with the label.

For example GOTO(N),

  1. When N==0, the program jumps to the beginning to the PLC cycle. It clear the watch dog timer, then it continuous to rung 1.
  2. When N==0, the program jumps to the address 0. It's a soft reset of the PLC program.
  3. When N is any label, the program jumps the the rung with that label.
For more information, click here to see the original post from GitHub.

For an introductory example, I use the GOTO instruction to jump to rung 4 of PLC ladder diagram.

PLC GOTO and LABEL ladder diagram instruction
GOTO LABEL ladder diagram example

In the ladder diagram example above, 

  • At rung 1, the program is commanded to skip the two remanding rungs 2 and 3. 
  • It jumps to rung 4 and stay there until the next reset.
This ladder program could be considered as non-sense. However, we can make a circuit just of leisure.



PLC GOTO and LABEL ladder diagram instruction
Ladder Diagram Example



The result of this program shown below.

PLC GOTO and LABEL ladder diagram instruction
Ladder diagram program simulation result

Since rung 2 and 3 are skipped, these rungs are not active. The program jumps to rung 4, activating the output coil that connect to RC2 of PIC16F876A.


Click here to download the zip file of this example.

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)