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.
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.
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.
Ladder Diagram Example
I show only the screen screen shot of the program simulation on this IDE.
No comments:
Post a Comment