Friday, September 18, 2020

PLC formatted string over UART ladder diagram instruction

Overview

RS-232 And UART

PLC to host PC communication typically requires the RS-232 communication port. RS-232 could transfer data at long wire connection. However its logic level not directly compatible with microcontroller TTL logic level. It needs a RS-232 driver to communication and converts between those two distinct logic levels. MAX232 is the most commonly used chip. 

PLC formatted string over UART ladder diagram instruction
RS-232 to UART convert putted on a microcontroller board using MAX232.

In modern communication USB port could replace the RS-232 with a USB to serial converter chip - CH340 or FT-232 etc. These chips however provide a full features of the standard RS-232, except the RS-232 logic level.



A Spark Fun FT-232 USB to serial converter board 

A USB to serial convert chip usually require its OS driver developed by its manufacture. This kind of chip is smaller in side and easier to prototype.

Formatted String Over UART Instruction

Referring to UART, some important parameters are the baud rate, number of stop bit and parity. In LDMicro the baud rate is set in the MCU parameters - PLC Configuration.



PLC formatted string over UART ladder diagram instruction
MCU Parameters to set the UART Baud Rate - bps

The formatted string over UART instruction is just like the C program printf function. It contains string and data.

Formatted string over UART instruction

This instruction must contain a variable, for example the variable "var".

Property of this instruction

Put any string and data to send over UART. The \3 denotes the number of digits of the var variable. If var is a negative value we can put \-3 etc. The \r\n is the newline and carriage return.



For a full explanation please see the user manual of the IDE.

Ladder Diagram Example

In this example I create a counter whose content increase by 1 for every one second. Its content will send over the UART using this instruction.

PLC formatted string over UART ladder diagram instruction
Ladder Diagram Example

I show only the screen screen shot of the program simulation on this IDE.

PLC formatted string over UART ladder diagram instruction
Ladder Diagram Program Simulation

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



No comments:

Post a Comment

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)