modbus and dmx512 using flowcode - circuit cellar · sponsored content if you purchase a product or...

4
SPONSORED CONTENT If you purchase a product or service via Flowcode.co.uk/circuitcellar, Circuit Cellar will receive an affiliate commission. Circuit Cellar only promotes those products or services that it feels will deliver value to you. Flowcode is a programming tool for microcontrollers. It uses simple flowchart icons which can be built up to create simple through to complex programs. Flowcharts can be organized into macros and macros can be packaged up into components allowing for a very flexible and modular approach to programming. Each packaged component features a full simulation allowing you to test your design in software before going near any hardware. It will also let you interact with hardware via various means, so you can control the real-world electronics from your PC. DMX 512 DMX512 may be familiar to DJs, stage lighting technicians and model railway enthusiasts, where it has a number of common applications. Communication is one-way, so it is used to send data from the master to the slave—no data can be sent back the other way. Also, DMX512 only allows 8-bit bytes to be transferred Modbus and DMX512 Using Flowcode By Ben Rowland, Embedded Engineer This article will investigate some of the more complex communications components, Modbus and DMX. Both of these components basically let you do the same thing, which is to use one device (Master) to control one or more remote devices (Slaves). Matrix TSL’s Flowcode software allows you to quickly and easily develop complex electronic and electromechanical systems. Engineers use Flowcode to develop systems for control and measurement based on microcontrollers, on rugged industrial interfaces or on Windows compatible personal computers. Flowcode 7 feaures a stylish and modern new UI that gives users an easy-to-use, advanced graphical programming IDE for their microcontroller project requirements. Download a Free Trial and/or Buy Flowcode 7 flowcode.co.uk/circuitcellar/

Upload: others

Post on 26-Sep-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Modbus and DMX512 Using Flowcode - Circuit Cellar · SPONSORED CONTENT If you purchase a product or service via Flowcode.co.ukcircuitcellar, Circuit Cellar will receive an affiliate

SPONSORED CONTENT If you purchase a product or service via Flowcode.co.uk/circuitcellar, Circuit Cellar will receive an affiliate commission. Circuit Cellar only promotes those products or services that it feels will deliver value to you.

Flowcode is a programming tool for microcontrollers. It uses simple flowchart icons which can be built up to create simple through to complex programs. Flowcharts can be organized into macros and macros can be packaged up into components allowing for a very flexible and modular approach to programming. Each packaged component features a full simulation allowing you to test your design in software before going near any hardware. It will also let you interact with hardware via various

means, so you can control the real-world electronics from your PC.

DMX 512DMX512 may be familiar to DJs, stage

lighting technicians and model railway enthusiasts, where it has a number of common applications. Communication is one-way, so it is used to send data from the master to the slave—no data can be sent back the other way. Also, DMX512 only allows 8-bit bytes to be transferred

Modbus and DMX512 Using Flowcode

By Ben Rowland, Embedded EngineerThis article will investigate some of the more complex communications

components, Modbus and DMX. Both of these components basically let you do the same thing, which is to use one device (Master) to control one or more remote devices (Slaves).

Matrix TSL’s Flowcode software allows you to quickly and easily develop complex electronic and electromechanical systems. Engineers use Flowcode to develop systems for control and

measurement based on microcontrollers, on rugged industrial interfaces or on Windows compatible personal computers. Flowcode 7 feaures a stylish and modern new UI that gives users an easy-to-use, advanced graphical programming IDE for their microcontroller project requirements.

Download a Free Trial and/or Buy Flowcode 7

flowcode.co.uk/circuitcellar/

Page 2: Modbus and DMX512 Using Flowcode - Circuit Cellar · SPONSORED CONTENT If you purchase a product or service via Flowcode.co.ukcircuitcellar, Circuit Cellar will receive an affiliate

SPONSORED CONTENT

so single bits of data have to be packed together inside a byte, or multiple bytes must be used to transfer values larger than 255.

Each DMX slave device can either have a unique address or can use different sections of the same message. For example, the master sends a DMX data chain of 24 bytes using the address byte 0x20. Two slave devices have the address 0x20, the first slave uses data channels 0-11 and the second slave uses data channels 12-23 (Figure 1).

The DMX512 example programs allow the master to control two slave devices. The master uses two full 8-bit ports to read the value of slide switches. The switches connected to PORTB are sent to slave node 1 and the switches connected to PORTD are sent to slave node 2 (Figure 2).

MODBUSModbus is used heavily in industry, from

the control of motors and actuators to sampling sensors and returning results. For example, a robot arm in a factory may have a Modbus slave device controlling the various moving parts of the arm and collecting data from sensors (e.g., ultrasonic proximity sensors or tactile press switches.

Modbus has four types of data that can be transferred between the master and slave:

• Digital States (Coils) – Master <-> Slave – 1-bit values

• Digital Inputs – Master <- Slave – 1-bit values

• Analog Values (Register) – Master <-> Slave – 16-bit values

• Analog Inputs – Master <- Slave – 16-bit values

Figure 1 - DMX512 Slave channels set using Flowcode

Figure 2 - E-blocks DMX512 1 Master and 2 Slaves

Page 3: Modbus and DMX512 Using Flowcode - Circuit Cellar · SPONSORED CONTENT If you purchase a product or service via Flowcode.co.ukcircuitcellar, Circuit Cellar will receive an affiliate

SPONSORED CONTENT If you purchase a product or service via Flowcode.co.uk/circuitcellar, Circuit Cellar will receive an affiliate commission. Circuit Cellar only promotes those products or services that it feels will deliver value to you.

The slave device stores the various values so the number of unique addresses is set in the Modbus slave component properties (Figure 3). Each Modbus slave device has its own address which can be specified as a single byte (255 available devices) or as two bytes (65535 available devices). Address 0 is reserved for broadcast to all type messages.

The Modbus example programs allow the master to read sensor values back from two slave nodes. The master reads the analog input register for slave addresses 1 and 2. The slaves constantly sample their sensor and update the value in the correct register ready for

the master to collect. This time the Modbus devices are connected together using RS-485 to allow the data direction to be controlled and allow bi-directional communications (Figure 4).

FLOWCODE INJECTORSThe Flowcode injector components

enable the connection of communications components to actual external devices inside the Flowcode simulation. In the examples the vNet injector is used, which allows two or more instances of Flowcode simulation to communicate together. If the COM port injector was used instead, the simulation could talk to real-world

Figure 4 - E-blocks Modbus 1 Master and 2 Slaves

Figure 3 - Specifying Modbus device addresses using Flowcode

Page 4: Modbus and DMX512 Using Flowcode - Circuit Cellar · SPONSORED CONTENT If you purchase a product or service via Flowcode.co.ukcircuitcellar, Circuit Cellar will receive an affiliate

SPONSORED CONTENT

hardware via a PC COM port. To set up the vNet component to communicate, you need to first check that the network interface is the same for both components: a correct setting should display your computer’s IP address, which will be used to route the communications. The TCP channel should be unique to the Flowcode instance and can range from 0-7. The Master component outputs data on port 4001 and listens for incoming data on port 4000. The Slave components outputs data on port 4000 and listens to port 4001.

MULTIPLE SLAVESWhen dealing with a single slave device,

you can simply connect the transmit pin of the Master to the receive pin of the Slave and vice versa. If you need the distance between microcontrollers to be significant (more than a meter or two), then you could use a driver chip such as a MAX2323 to convert the TTL signals up to RS-232 compatible voltages.

When using multiple slaves, the connections become a bit more difficult as you need a way to connect all the slave transmit pins to the master receive pin, without conflicting with one another. One way is to use a driver chip such as a MAX3078 to convert the signals to RS-

485 compatible voltages. If the device is bi-directional as is the case with Modbus, then an extra microcontroller pin is required to control the data direction of the MAX3078 IC. The Modbus component has an RS-485 mode which will do all the manipulation of the data direction pin for you.

CONCLUSIONConnecting systems together using

communications busses is often seen as a hard undertaking which can lead many engineers to struggle. Flowcode not only simplifies the process of connecting systems together, but also allows devices to be created using existing standards. Adopting an existing communications standard means your product can be compatible with a wide range of off the shelf products as well as a great number of end users who may be already familiar with the bus.

Ben Rowland is a graduate of the University of Huddersfield in the UK, where he earned a Master’s degree in Embedded Systems & Cybernetics before going on to work in the Flowcode development team at Matrix TSL where he has worked for more than 10 years.

Flowcode is an IDE for electronic and electromechanical system development. Pro engineers and academics can use Flowcode to develop systems for control and measurement based on microcontrollers or on rugged industrial interfaces using Windows-compatible personal computers.

Visit www.flowcode.co.uk/circuitcellar to learn about Flowcode 7. You can access a free version, or you can purchase advanced features and professional Flowcode licenses through the modular licensing system. If you make a purchase through that page, Circuit Cellar will receive a commission.

Download a Free Trial and/or Buy Flowcode 7

flowcode.co.uk/circuitcellar/

FREE