Sunday, July 3, 2011

OMRON



Using FinsGateway To Set Non Zero Network Number For A CLK Network
Document reference : COMM0010, version 1 Simply getting on-line to a PLC via Controller Link (CLK) is quite straightforward, as to specify the local network you simply spec
Last Modified - 2008-12-08 - Similar Articles

Profibus Configuration For Trajexia
Introduction Profibus communication between CJI-PRM21 and TJI-PRT This pdf document and lin
Last Modified - 2009-04-30 - Similar Articles

Step by Step Downloading a Protocol Macro
Introduction Screenshots guiding the User through the download of a protocol macro onto a Serial Co
Last Modified - 2008-12-08 - Similar Articles

Getting Started Using The K3SC Serial Converter With Multiple PLCs
Introduction This helpsheet is aimed at providing a worked example for connecting a PC using CX-Progra
Last Modified - 2009-04-16 - Similar Articles

Sample Programs for Host Link Commands
Introduction This tutorial gives an introduction to Host Link and a sample program to demonstrate the protocol. The sample program has been written to be used in conjunctio
Last Modified - 2009-04-30 - Similar Articles

Connecting E5_N Series to CPM2C-CIF21
Introduction This note describes a simple way of connecting Omron CPM2C-CIF21 communication unit to E5_N temperature controllers to read PV and Status and write the Setpo
Last Modified - 2009-04-28 - Similar Articles

How Do I Make A Program To Transfer A 2.5-digit BCD Data Stored In The DM Area To Display It On A Static-Input Digital Display (CIO 2.00 To CIO 2.09)?
We will assume that CIO 2.10 to CIO 2.15 are allocated to other output bits. The main point of this program is how to process the combination with the other output bits.
Last Modified - 2009-04-29 - Similar Articles

How Do I Create Programming To Use A DATA SEARCH (SRCH) Instruction To Find A Certain Product Code From Within The Production Instruction Master Table And Extract The Related Production Instruction Data?
Introduction There are many applications that use the product code as a search key to extract the related production instruction data. The following explains how to use t
Last Modified - 2009-04-28 - Similar Articles

How Should I Handle Programs That Have BCD Subtraction Operations That Result In A Negative Number?
Introduction When the result of a BCD arithmetic operation is a negative number, the operation result will be output as the 10’s complement (see Additional Informatio
Last Modified - 2008-11-06 - Similar Articles

What Outputs Turn OFF With In Interlocked Program Sections Interlock Instruction (IL/ILC) And What Ones Don't?
Introduction The Interlock Instructions can be used to turn OFF all the sequence outputs from a specific program block, as might be necessary to process an emergency stop f
Last Modified - 2008-11-06 - Similar Articles

NS Serial Connection With PLCs
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore use it only to become familiar with the product, and
Last Modified - 2008-11-12 - Similar Articles

NT20S - Conversion from NT-DOS to NT Win
Introduction This tutorial is intended as a supplement to the original manuals for the products. Use it therefore as a means to get to know the product and not as an
Last Modified - 2008-11-13 - Similar Articles

Getting Started With NT2S-SF123B-E
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use this as a means to get to know the product,&nbs
Last Modified - 2008-11-13 - Similar Articles

E5ZN As SAP In NS-Panel
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use it as a means to familiarise yourself with
Last Modified - 2008-11-13 - Similar Articles

NS Screen Shift From PLC
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use it as a means to get to familiarise yourself wi
Last Modified - 2008-11-13 - Similar Articles

Connecting a PC To NS Via CS/CJ PLC
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use this as a means to familiarise yourself wi
Last Modified - 2010-03-11 - Similar Articles

Connecting a PC To CS/CJ PLC Via NS
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use this to familiarise yourself&nbs
Last Modified - 2010-03-11 - Similar Articles

Getting Started With F7/E7
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use this as a means to familiarise yourself wi
Last Modified - 2008-11-26 - Similar Articles

Getting Started With RV/PV
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use this as a means to familiarise yourself wi
Last Modified - 2009-06-11 - Similar Articles

3G3MV As PID - An Example
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use it familiarise yourself with the product, and n
Last Modified - 2008-11-19 - Similar Articles

Modbus Serial Gateway
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use it as a means to familiarise yourself with
Last Modified - 2008-11-26 - Similar Articles

PLC 'Serial Gateway' To The Inverter
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use it to familiarise yourself with the product and
Last Modified - 2009-04-02 - Similar Articles

Modbus PLC-MV/JV/PV
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use it to familiarise yourself with the product but not as a guide
Last Modified - 2009-03-19 - Similar Articles

Programming With Westermo TD-22
Introduction This tutorial is intended as a supplement to the original manuals for the products. Therefore, use it to familiarise yourself with the products and not
Last Modified - 2008-11-21 - Similar Articles

Programming With Westermo TD-32
Introduction This tutorial is intended as a supplement to the original user manuals. Therefore, us it to familiarise yourself with the project and not as a complete guide to
Last Modified - 2008-11-21 - Similar Articles

Programming With Westermo TD-32B
Introduction This tutorial is intended as a supplement to the product user manuals. Therefore, use it to familiarise yourself with the product but not as a guide to complete
Last Modified - 2008-11-21 - Similar Articles

Setting Up Wavecom GSM Modem
Introduction This tutorial is intended as a supplement to the User manuals. Therefore, only use it to familiarise yourself with the product and not as a complete gu
Last Modified - 2008-11-24 - Similar Articles

Setting Up The Westermo GD-01 GSM Modem
Introduction This tutorial is intended as a supplement to the User manuals. Therefore, use it to familiarise yourself with the product and not a a complete guide to installat
Last Modified - 2009-08-26 - Similar Articles

CX-Integrator
Introduction This tutorial is intended as a supplement to the orginal product manuals. Therefore, use it to familiarise yourself with the product and not as a guide to t
Last Modified - 2008-11-25 - Similar Articles

Communication Efficiency
Introduction This tutorial is intended as a supplement to the original product manuals. Therefore, only use it to familiarise yourself with the product and not as a guide to
Last Modified - 2008-11-25 - Similar Articles

CX-Server Lite
Introduction This information is intended only as a supplement to the original product user manuals. Therefore, use it to familiarise yourself with the product and not as a g
Last Modified - 2008-11-27 - Similar Articles

ZFV - Colour
Introduction This tutorial is meant as a supplement to the original product manuals. Therefore, use it to familiarise yourself with the product and not as a guide to complete
Last Modified - 2008-11-27 - Similar Articles

NS HMI Create Your Own Recipe
Introduction Omron has improved the Recipe functions of NS in V6.60 to give you the freedom to develop your own Recipe screen, but at the same time use the standard function
Last Modified - 2011-05-12 - Similar Articles

Creating An I/O Table On A CJ1 PLC
Introduction Assemble all the I/O modules and power supply module to the CPU. Initia
Last Modified - 2008-12-03 - Similar Articles

Setting Communications Between A CJ1 PLC And An NS Screen
Introduction 1 Connect the communication cable between your computer and the CJ PLC. (Check that dipswitch 5 i
Last Modified - 2008-12-03 - Similar Articles

Connecting A PLC To A PC For Programming Using CX-One
Introduction Before Powering PLC 1A Initially, make sure all modules are clipped together sec
Last Modified - 2008-12-03 - Similar Articles

Recall Parameter Selection In CX-Thermo?
Introduction This tutorial is aimed at giving an overview of the re-use of parameters used in the previous CX-Thermo session. It refers to CX-Thermo v2.0 or higher.
Last Modified - 2008-12-04 - Similar Articles

Connection To CX-Thermo Via USB Port
Introduction This tutorial is intended as an overivew of connecting CelciuXº to the PC and configure via CX-Thermo. Components used:
Last Modified - 2008-12-04 - Similar Articles

Connection To OPC Clients Using CX Server OPC
Introduction This tutorial is intended to provide an overview of connecting CelciuXº to the PC and connecting to an OPC client. Componen
Last Modified - 2008-12-04 - Similar Articles

Connection From CX-Supervisor v2.0
Introduction This tutorial is intended to give you an overview of connecting CelciuXº to the PC using CX-Supervisor in order to monitor values.
Last Modified - 2008-12-04 - Similar Articles

Connection Of CelciuXº With Profibus Gateway
Introduction This tutorial is intended as an overivew of connecting CelciuXº to Profibus Gateway and Profibus Master. Components used
Last Modified - 2008-12-04 - Similar Articles

CP1L Connection
Introduction This tutorial is intended to give an overview of connecting CelciuXº to CP1L (serial CompowayF) Components used:
Last Modified - 2008-12-05 - Similar Articles

Direct NS Connection Using Smart Active Parts
Introduction This tutorial is intended to give an overview of connecting CelciuXº to NS and using Smart Active Parts with the HMI. Compone
Last Modified - 2008-12-05 - Similar Articles

Setting Up Data Logging On CX-Supervisor
Introduction This tutorial is intended to provide an overview of setting up CX-Supervisor to log data to, Data Log Viewer Microsoft Excel Microsoft Access It will cover
Last Modified - 2008-12-05 - Similar Articles

Direct NT3S Connection Using Modbus
Introduction This tutorial is intended as an overview of direct NT3S Connection using Modbus. Components used: • EJ1N-TC__-
Last Modified - 2008-12-05 - Similar Articles

Connection Of CelciuXº To Siemens S7-300
Introduction This tutorial is intended as an overview of programless connecting of CelciuXº to the Siemens S7-300 PLC. Components used:
Last Modified - 2008-12-05 - Similar Articles

CX-Supervisor and MODBUS TCP
1. Introduction CX-Modbus TCP is an ActiveX intended to work with CX-Supervisor to enable communication with Modbus TCP server. Installation The Modbus TCP Control
Last Modified - 2010-01-28 - Similar Articles

Function Block For Using Integrated Serial Port With SYSMAC Way on CJ1 and CS1 PLCs
Introduction Function Block for SYSMAC WAY communication. The Function Block (FB) attached exploits the Hostlink communication protocol. The master PLC can
Last Modified - 2009-05-15 - Similar Articles

Function Block For Configuring the CAN Open Network
The purpose of this Function Block (FB) is to simplify the immediate configuration of the CJ1W-CORT21 card for communication devices with CAN-Open. The Function Bloc
Last Modified - 2009-05-18 - Similar Articles

How To Configure Communication To SYSMAC Board in CX-Supervisor
Introduction At present, CX-Server (v1.0 / 1.1) can not find drivers for SYSMAC Board. However, this can be worked around by defining the SCS in FINSGateway. In this case, Ne
Last Modified - 2009-06-04 - Similar Articles

How To Use Controller Link Board With CX-Supervisor
Introduction This tutorial is about the Controller-Link board for SCSs with the 3G8F5-CLK21-E card for PCs. In this example, there is no data link, but the SCS oper
Last Modified - 2009-06-08 - Similar Articles

Connecting To PLC With VPN Using CISCO PIX 501
Introduction This tutorial uses the example of the setting up of CISCO VPN Client Software in order to contact the outside world from your office to devic
Last Modified - 2009-12-01 - Similar Articles

Database Connection To SQL Database - CX-Supervisor
Introduction Installation The following programs / drivers must be installed: 1. The SQL server mysql-3.23.51-win. 2. The ODBC driver for mysql MyODBC 3.51.03.exe. This i
Last Modified - 2009-06-18 - Similar Articles

How To Connect PC To NS And PLC via bluetooth
Introduction This tutorial is designed to cover the connection from a PC to NS and PLC via bluetooth. The Promi SD202-OA adapts the serial ports of the PLC and NS to a
Last Modified - 2009-08-26 - Similar Articles

Transfer Compact Flash memory card
Introduction This tutorial is designed to explain the transfer process of compact flash memory cards for CS1/CJ1 PLCs. Saving configuration files / program on the
Last Modified - 2010-02-15 - Similar Articles

Connecting Modbus RTU master cards SCU
Introduction This tutorial is intended to explain the connection of Modbus RTU masters cards SCU. The CJ/CS1W-SCU21/41 * cards are capable of gateway-mode
Last Modified - 2009-08-26 - Similar Articles

PC-Modem-PLC connection
Introduction This tutorial is designed to cover the configuration and connection between PC and PLC using modems. I. Wiring Attention!: Be careful to identify the PLC and
Last Modified - 2009-08-26 - Similar Articles

Quick Start Guide For Configuring DeviceNet Master
Introduction Starting your first Remote IO application with SmartSlice over DeviceNet may seem difficult with a lot of manuals to read, but this
Last Modified - 2009-08-19 - Similar Articles

How To Make CX-Supervisor Log Out A User Automatically
Introduction Sometimes its useful to be able to get CX-Supervisor to log out a user automatically, for example after the PC has not been used for a period of time. This artic
Last Modified - 2009-08-21 - Similar Articles

How To Connect NS to PLC Via Dedicated Line
Introduction This tutorial is designed to cover the NS to PLC connection via a dedicated line using a Gener modem. I. Setting modems 1. AT & F Recall fa
Last Modified - 2009-08-26 - Similar Articles

Methods Of Program Protection
Introduction This tutorial is designed to introduce the methods of protection for programmes available for PLCs in CX-Programmer. I. Protection program password 1.
Last Modified - 2009-08-26 - Similar Articles

Login/Configuration of CS/CJ ETN21
Introduction This tutorial is intended to explain the login and configuration of CS/CJ ETN21. I. Connection with Internet Explorer 1. Connect to the default addres
Last Modified - 2009-08-26 - Similar Articles

FINS Network Routing
Introduction This tutorial is intended to explain the principles behind FINS Network routing. I. Principle The FINS network address consists of 3 fields: Net: num
Last Modified - 2009-08-26 - Similar Articles

Sending Mail With ETN21 Card
Introduction This tutorial is intended to explain how to send mail with the ETN21 card. * Note: The CJ1M-CPUxx-ETN (integrated) does not have the functionality and mail socke
Last Modified - 2009-08-26 - Similar Articles

Serial Communication On CP1L & CP1H
Introduction This tutorial is intended to explain serial communication with CP1L & CP1H. The optional cards CP1W-CIF01 (RS232C) and CP1W-CIF11 (RS422A/485
Last Modified - 2009-08-26 - Similar Articles

Passing An Array Of Data To A Function Block
Objective This article describes how to pass an array of data (in this case a number of Integers) to a Function Block for processing. It assumes the use of a CJ1/CS1 (V4
Last Modified - 2009-09-07 - Similar Articles

How To Save The Windows Event Log
Introduction Microsoft Windows provides an Event Log where all applications may store warnings and errors found during execution. When debugging a system fault, it can
Last Modified - 2009-09-25 - Similar Articles

How To Reduce CX-Supervisor Runtime (SR2) File Size
Introduction When creating a CX-Supervisor Runtime application all the pages, objects and project settings are compiled into one file (SR2). Pages with lots of
Last Modified - 2009-10-14 - Similar Articles

How To Read And Write To Excel Cells From CX-Supervisor
Introduction Plant data can easily be collected by CX-Supervisor, but extra data analysis often requires data to be exported or imported from a spreadsheet like Microsoft Exc
Last Modified - 2010-02-25 - Similar Articles

How To Send Out An Explicit Message To Read The DeviceNet Powersupply Voltage
DeviceNet supports so called explicit messaging. The purpose is to read or write a single attribute value from a DeviceNet device. In this particular case we read the DeviceN
Last Modified - 2009-12-02 - Similar Articles

How To Convert Siemens And Mitsubishi PLC programs to Omron
The Ladder Program Converter tool has been incorporated into CX-One Lite v4 and CX-One Full v4.0. This tool is used to convert the instructions of Mitsubishi and Siemens
Last Modified - 2010-01-19 - Similar Articles

Profibus Connection To A MX2-inverter With Gateway PRT1-SCU11
Introduction The OMRON gateway between Profibus and serial connections does not work only with temperature controllers, but since version 2 also with inverters. With the inve
Last Modified - 2009-12-18 - Similar Articles

How To Switch From SMS, To A Communications Protocol, When Using A GSM Modem For Both SMS And Remote Connection
Introduction When using a GSM modem with an Omron PLC, the serial port can be configured to to allow AT commands to be sent to the GSM modem (‘No Protocol’ mode)
Last Modified - 2010-01-07 - Similar Articles

How To Configure 1 NS(NT Link) On A PLC Link Network
Introduction Sometimes there is a desire for a complete automation system with PLCs, HMI and inverter's, but in a small format for example, usin
Last Modified - 2010-07-27 - Similar Articles

Remote Programming of CS1 Board PLC
System Diagram: Hardware and Software for this example: Dyalox PC (PC 1) - Windows XP Embedded version 2002, Service Pack 2 - FinsGateway Version 2003 Embedded - Fins
Last Modified - 2010-05-12 - Similar Articles

How Do I Log To A Database with CX-Supervisor And View In The New Data Log Viewer?
Introduction The new Data Log Viewer (V2) shipped with CX-Supervisor v3 has the ability to view data logs stored as an Access database format (mdb extension) and CX-Superviso
Last Modified - 2010-05-19 - Similar Articles

Using Excel To Manage CX-Supervisor Points
Introduction CX-Supervisor allows you to copy and paste from the point editor into Excel and back again. This can be useful if you want to duplicate lots of points and for ex
Last Modified - 2010-06-17 - Similar Articles

How To Convert CX-Designer Projects Version 8.2 To 8.1
Here is a description on how to convert the system version of projects from Version 8.2 to Version 8.1 with the CX-Designer. This is helpful if you want to use your CX-De
Last Modified - 2010-10-14 - Similar Articles

How To Connect NQ HMI To Omron PLC Using Hostlink Protocol
Introduction This article describes the initial connection between a NQ HMI and a PLC using Hostlink protocol. For the example below a NQ3-TQ000B and a CP1L PLC will b
Last Modified - 2011-06-14 - Similar Articles

How To Transfer Your Program To Or From The CP1L, CP1H Without A Computer
Introduction You can upload and download programs to a CP1 PLC using a PC but sometimes this is not ideal, for example: You want to transfer a program direct
Last Modified - 2010-08-05 - Similar Articles

How To Connect 3G3AX-MX2-ECT To TwinCAT
Introduction This article explains how to connect the 3G3AX-MX2-ECT drive with EtherCAT directly to a PC with TwinCAT installed. Following the instructions will allow yo
Last Modified - 2010-12-02 - Similar Articles

How To Connect R88D-KNxxx-ECT To TwinCAT
Introduction This article explains how to connect the R88D-KN drive with EtherCAT directly to a PC with TwinCAT installed. Following the instructions will allow you
Last Modified - 2010-12-02 - Similar Articles

How To Manage Enhanced Write Filter Function Within XP Embedded
What is Enhanced Write Filter (EWF)? Enhanced Write Filter (EWF) is a component in XP Embedded which prevents write operations to another medium such as a DOM or Compact Flas
Last Modified - 2010-09-22 - Similar Articles

How To Keep Trying To Open A Device That Fails To Connect - CX-Supervisor
When a device is first opened (either during start up, or from a script command), CX-Supervisor starts a heartbeat to monitor the status of the connection. Therefore, if
Last Modified - 2010-09-03 - Similar Articles

How Do I Create A Secure Audit Trail Of Points, Alarms And Events In CX-Supervisor?
Introduction In some applications, especially those destined for the pharmaceutical industry, it is important to keep a log of important events and changes that have occurred
Last Modified - 2010-12-10 - Similar Articles

How Do I Link A CX-Supervisor User To Windows Security Credentials?
Introduction CX-Supervisor has always offered the ability for users to log in and have differing levels of security access to an application. In some cases especially in the
Last Modified - 2010-12-15 - Similar Articles

PROFINET Quick Start Guide
Objectives This quick start guide is to allow a new user to PROFINET to attach PROFINET I/O to an Omron PLC and configure it to work. Introduction PROFINET products support
Last Modified - 2011-01-06 - Similar Articles

How To Link Two Or More CX-Supervisor Runtimes Using FinsGateway
Introduction In large applications it can sometimes be necessary to link multiple PCs each running a CX-Supervisor runtime application. This has previously been achieved usin
Last Modified - 2011-02-02 - Similar Articles

How To Replace The Battery On CS1 PLC
Introduction This article is a quick reference for replacing the CS1W-BAT01 backup battery on CS1, CS1-V1 and CS1-H series PLCs where the existing battery has become fully di
Last Modified - 2011-02-08 - Similar Articles

Sunday, June 26, 2011

VB6 sending signal RS232

1. Use computers to control the real world

1.1 Introduction

The diagram on the right is a simplified model for computer control. It starts with the user interface. Users give instructions and read information from the control target through the user interface. The software in the computer will process the instructions and send it to the control/interface board through a communication port. The control/interface board will interpret and execute the instructions according to a pre-written protocol.

The interface board uses a micro controller to interpret and execute the instructions from computer. To make the micro controller understand the instructions, it needs to be loaded with a software. The software is called "firmware" to differentiate it from the software in the computer. The micro controller can read status of an input and give feedback to the computer. It can also switch an output to high (normally 5 volt) or low (0 volt).

However, an interface board cannot drive an electric device directly since the output from the micro controller can only take very small amount of current (normally less than 20 mA). So we need to use a relay or a driving board between the interface board and an electric device. A driving board normally consists of integrated circuits (IC) that can take larger current and can be switched by the micro controller outputs. The RSVB1500 adapter board is an example of such driving board. A relay is an electric switch. When a small current is applied, it can switch on a much larger current. You can find more information in the section 1.4 of this tutorial. Sometimes the interface board and the driving board are integrated into one board (the RSVB1600 board and RSVB1700 controller belong to this type).

1.2 User interface, software and computer communication

I here put the 3 topics under one section since they are very closely related to each other. A user interface is a part of software that is used to get information from user and to display the information it received. The software needs to be written using a programming language. There are many programming languages available for writing a software, such as assembly language, C language, Java, Basic, and Visual Basic. Among these languages, C language is the most powerful and is the major language for making complicated application software. As it is not easy to command, the language is normally for professional software engineers. Visual Basic (here after we will refer it as VB) is a powerful and very user friendly language from Microsoft. It is easy to remember the commands and easy to build user interface. VB is an excellent tool for those who want to develop automation solution but do not have training on programming. The RSVBcon software is made using VB. It services as a good example about the capability of VB. The software written using a programming language need to be translated to a format that can be executed by a computer. We call this process "compile". The tool used for the translation is called "compiler". Each language need its specific compiler.

The software sited in a computer talks to a interface board through a communication port. It can be a RS232 port, a parallel port, a LAN port, or a USB port. RS232 port was mainly used for modem connection. It is also convenient for interfacing with small instruments. Parallel port is mainly used for controlling a printer. LAN port is useful for networking such as internet connection. USB port is just getting more and more popular nowadays because of its hot "plug/play" feature. It is very easy for a device user. However for a USB interface developer, it demands very profound knowledge in computer operation system.

For a VB based software, the most convenient communication approach is using a RS232 port. This is because RS232 is very simple to setup (only need two wires for communication) and VB can send commands and receive feedback through a RS232 port directly. Even if a PC does not have a RS232 port, a USB port can be easily converted using a USB/RS232 converter. The price of a converter ranges from 20 to 40 dollars. You can find more details about how to use VB to send out commands through a RS232 port in section 2.

1.3 Control/interface board and microcontroller

1.3.1 Microcontroller

A microcontroller is an integrated circuit (IC) that includes data processor, program storage, data storage, and input/output. It needs to be programmed before it can be used. The developer first write a software (firmware) using a specific language. Then the firmware is compiled to a format usable by the microcontroller. The compiled software is then loaded to the microcontroller. This step is called programming and the tool for loading firmware is called programmer. The firmware in the microcontroller interprets the commands from computer and tells the microcontroller what to do. It will also report its status to computer. To come out a right firmware, the developer needs to know detailed structure of a microcontroller and the communication protocol between the computer and the microcontroller. This is normally the biggest barrier for a person to develop an automation solution without a background in computer control. The RSVB1000 board saves a developer the efforts in dealing with these issues.

1.3.2 Input and output of a microcontroller

Input is like the ears or eyes and the output is like mouth or hands. An output drives a device to do something and an input checks the status and gives feedback to controllers. In a control, it is not sufficient just to be able to tell a device what to do. It is necessary to monitor the status of the devices so that we know if a device has done what it is supposed to do and decide next action according to its status. The first type control is called "open loop" control and the second type is called "closed loop" control.

Input and output can be of analog type or digital type according to the signals they process or generate. An analog signal has continuous value (such as voltage and current) while a digital signal consists of "0" and "1" or their combinations.

To allow a computer to process an analog signal, the signal needs to be converted to digital type first. The RSVB1000 board has two 10-bit analog-to-digital converters for handling analog signals. Here the term "10-bit" is a description of resolution for the A/D converter. The maximum value for a 10-bit variable is 1023. The digital range 0-1023 is used to cover 0-5 volt analog input. One digital unit will be equivalent to 5 mV. If the analog signal changes less than 5 mV, the A/D converter will not be able to detect the difference. An A/D converter can be used with analog type sensors to achieve closed loop control, such as use a temperature sensor to control a heater.

A digital input monitors the two status: logic low (0) and logic high (1). The two status are associated with voltage change (normally 0 volt is for logic low and 5 volt is for logic high). The RSVB1000 has 7 digital input for monitoring the high and the low status. We also call them TTL compatible input (TTL=transistor-transistor logic). Some digital input can have extra data processing function. For example, it may count how many times the status has changed. The counter in the RSVB1000 and RSVB1600 boards belong to this type. A counter can be used with a motor encoder for position control and speed control.

1.3.3 Function of interface board

An interface board consists of a microcontroller and other functions to allow a microcontroller to work properly. Among the functions are power supply, external clock, input/output connectors, signal conditioning components, and circuit for communicating with computer. The RSVB1000 interface board is made ready for receiving commands from a RS232 ports. For example, when a string "H6" is send out from a VB software, the interface will pass the information to its microcontroller. The firmware in the microcontroller interprets it as "switch output 6 to 5 volt" and makes the microcontroller do it accordingly. If this command is executed, the LED for output 6 will light up. If you use a multimeter to measure, the voltage of of the pin for output 6 will be around 5 volt.

1.4 Drive electric devices

An electric device can be a light bulb, a valve, or a motor. Each device has a working range in voltage and current. If the voltage applied to a device is above the upper limit of a device, the device may get damaged. On the other hand, if a device draw more current than the output current of a driving board or a power supply, the system may shut down or even get permanent damage.

1.4.1 Use a microcontroller output to drive a device

Suppose we want to control a valve with a 12 volt working voltage and 700 mA current. An output on a microcontroller can only draw less than 20 mA current and can only provide 5 volt. So it cannot drive the valve directly.

One approach is using a relay. A relay is like a switch that allows you to use a smaller power to switch a bigger power. The diagram on the right shows how a relay works. When a small trigger voltage is applied to a relay, a larger power can be switched on (for the valve, the power supply should have a 12 volt output voltage and above 700 mA output current). When the trigger voltage is removed, the power supply for the device is also cut off. Some relays can be triggered directly by a microcontroller output (such as some solid state relays).

Another approach is using transistor based integrated circuits. This kind of ICs can be directly triggered by a microcontroller output. The RSVB1500 adapter board and the RSVB1600 control board use this type of ICs. Sixteen of their outputs can have up to 500 mA output current and up to 24 volt output voltage. Sometimes we can use a microcontroller output to switch a transistor based IC and let an output of the transistor IC to switch a relay for much higher current.

1.4.2 Match supplied voltage with the working voltage of a device

Sometimes the output voltage of a power supply is too large for a device. A voltage regulator may be used to lower a portion of the output to the desired voltage. There are many low cost voltage regulators available in the market (such as LM317, L7805, L7812). Their connection is quite simple. Another approach is connecting a resistor in series with the device so that the resistor will consume the extra power. Although this approach is very easy to do, the resistor simply convert the power to heat and gets it wasted. So this is normally used when the total current is very small.

A more advanced approach is using the pulse width modulation technique (PWM). In a PWM regulated output, a continuous supply is divided into many small pulses. During each pulse period, the output is set to high for some time and set to low for the rest of the period. The number of pulses per second is called PWM frequency. The ratio of time that an output is maintained high to the total time of a pulse is called duty cycle. A PWM output can be used to switch a power supply on and off quickly. It will lower the current flowing through a device without interrupting its operation. For example, we may use a 24 volt power supply to drive a 12 volt heating element by setting the PWM duty cycle at 50%. PWM output can also be used to control the speed of DC motors. The RSVB1000 board has two PWM outputs. They are used in RSVB1500 board for manipulating wattage for output 1-8. Detailed information about how to use PWM to control motor speed and to adjust output voltage is available in the user manuals of the boards.

1.4.3 Match the working current of a device with the output current of a supply

For voltage, we need to make sure the supplied voltage not be higher than the working voltage of a device. In term of current, it is the other way round. We must make sure supplied current capacity (output current) is higher than the working current (or rated current) of a device.

The working current of a device depends on two factors: supplied voltage and the resistance of the device. For most cases, the current can be estimated using Ohm's law. Let us use the relay in section 1.4.1 as an example. If the coil has a resistance of 100 Ohm and its working voltage is 5 volt, we can estimate the current flowing through the coil will be 50 mA. If we use a microcontroller output to drive the relay coil directly, the current flowing through the output will be too high (one output can only allow 20 mA). The microcontroller will either shut down or get damaged. We may try to add a resistor in between to regulate the current. If the resistor is too large, it may reduce the power below the working range and the coil may not be powerful enough to do a switch. Other options include selecting a relay with smaller working current (such as a solid state relay) and using a transistor type IC in between.

For a DC motor, we cannot simply use Ohm's law to estimate the working current. This is because a running DC motor can generate an opposite current to suppress the current flow. The faster it runs, the lower the net current flowing through the motor. The current flowing through a free running motor is normally 10-20% of the value estimated using Ohm's law. When a DC motor is slowed down due to increased load, its current will increase to make it move faster. If the motor is stopped due to blockage or overloading, the current will surge by 5 to 10 times. If the power is not cutoff quickly, the system can get damaged. In some DC motor systems that require high reliability, current detection circuit is built in.

1.4.4 Good practice in handling electric devices

  • Always check the specification of a device before connecting it to the system. Most datasheet can be easily obtained from internet.
  • Discharge your body before touching an electronic board as many electronic components are sensitive to static charge. This can be easily done by touching a water tap using a hand.
  • Make sure the power is switched off before adding or removing a component.
  • When switching on an electronic board, look at the power light indicator. If it does not light up or the light is not steady, switch it off immediately. Either the power supply is not right or a device is connected incorrectly.

Back to top

2. Visual Basic programming for control

2.1 Introduction

VB is a very easy yet very powerful application development tool under the Microsoft Windows family. As you may already know, it is possible to get your first program running in less than an hour. There are three editions of VB, they are the learning edition, the professional edition, and the enterprise edition. To develop software for control, a professional edition is necessary. The tutorial here is based on professional edition of VB6.

When we start up VB, a dialog panel will appear, asking us to select a project type (see figure 2.1). For control software development, we will mainly use the "Standard.exe" project under the "New" menu bar. When you click on the icon representing "Standard.exe", the VB development environment will show up (see figure 2.2). Double click on an icon in the tool box, that icon will appear in the "Form1" frame and the relevant properties will be displayed in the property panel. Each icon represents an object, such as a button, a text box, or a timer.

Figure 2.1 VB project selection panel

Figure 2.2 VB development environment

In a VB program, all the actions must be triggered by letting something happen to an object. For example if we want a text box to change content, something must happen to an object. This event can be a mouse click at a button, a timer is enabled, or a check box is checked. This is one of the major difference between VB and other traditional programming language.

2.2 Setup programming environment

VB has a special function for RS232 communication called MScomm. It is not included in the standard tool box. It needs to be added before making a control software. To do this, first go to menu bar "Project" and select "Components" in the drop down list. Then check "Microsoft Comm Control 6.0" (see figure 2.3) and click on the "Apply" button. A telephone icon will appear in the tool box. Double click at the icon, it will appear in the form and its properties will appear in the properties panel (see figure 2.4). One important property is CommPort value. It is the number of the RS232 port (COM port) used for communicating with the interface board. The default value is 1. If your computer has more than one COM port or you use a USB converted port, the number could be different. If this setting is not correct, the PC will not be able to communicate with the interface board. A convenient way to find out the correct port number is to use the RSVBtest software shipped with the RSVB1000 and RSVB1600 boards. It can automatically detect the port number. Another important property is the communication speed in RS232 setting. It must be the same as the setting in the interface board. The default value in the VB is 9600 (bit per second). The RSVB1000 and RSVB1600 boards use a faster communication speed (38400). You need to make the change in VB accordingly. For other MScomm properties, we can leave them as the default setting.

Figure 2.3 Add MScomm to the tool box

Figure 2.4 Set right properties for RS232 communication

2.3 A simple programming example

After setting up the development environment, we can start building a program to communicate with a RSVB1000 or a RSVB1600 board. The first thing is to build a user interface. Double click at the button icon, the text box icon, and the MScomm icon. The form will be like the one in figure 2.4. Then set the RS232 setting and the CommPort to the correct value. Double click at the form will bring out the programming panel for writing code.

Figure 2.5 is the programming panel with a simple program. It is divided into 3 sections (subs). Each sub tells what to do under an event. The first sub tells what to do at the beginning when the form is displayed (remember what we said before: something must happen to an object to trigger actions). It will do two things. One is to open the selected RS232 port. It needs to be opened before we can send out commands. The 2nd thing is to make the text box blank. The 2nd sub tells what to do when you quit a program. When the form is closed, the RS232 port is closed also. The 3rd sub tells what to do when the "command1" button is clicked. It will do 3 things. First it will send command "H6" to the interface board. The phrase "chr(13)" is equivalent to pressing the "enter" key. When the interface board receives "H6", it will set output 6 to 5 volt (high status). The 2nd thing is to send out command "A1" to the interface board. When the interface board receives this command, it will send out the value of analog input An1 to the computer. The 3rd thing is to wait until the data from RSVB1000 reaches the computer and put the data to the text box. To understand this part, we need to go a bid deeper about RS232 communication in VB.

When we add a MScomm object to form1, the computer will automatically allocate two special memory zones for receiving and sending out data. It is called inputbuffer and outputbuffer. When VB sends out "H6", the computer cannot send all of it at one go. This is because RS232 communication is of serial type. It can only send one bit at a time. Command "H6" has two characters and it is equivalent to 16 bits (In ASCII code, each character is represented by a 8-bits value). The RS232 protocol will add 2 more bits for each character. One is the starting bit and the other stop bit so that the interface board will know when a complete character has been transferred . So some bits has to wait in the output buffer before being sent out. When the interface board send data back to PC, it first divides the analog value into bits and then add the starting bits and the stop bits. Then the bits are send out one by one. When the bits arrive at the computer, they will gather in the inputbuffer to form a complete character or number. If the communication speed is set at 38400 bits per second, the time for transferring one character is around 0.25 mili second. This may appear very fast to you but it is much slower than the execution speed of the program. If we read the inputbuffer immediately after sending out "A1", the data we get will be blank as the command is still in its way to the interface board.

The paragraph from "Dim dummy" to "loop until ..." is a delay program. It checks the number of bits in inputbuffer continuously. When its data reach one byte, the data is removed and put to the text box. A command line like "A=B" in VB is not exactly like "A equals B". Its meaning in a program is "put value of B to A". A and B are two places for holding data or two variables. After the program executing "Text1.text = Val(MSComm1.input)", the content in inputbuffer will be displayed in text1 box and the inputbuffer will be empty and ready for next coming data.

Figure 2.5 Code writing panel and a simple program

Figure 2.6 Run the program

To try out this program, first connect a RSVB1000 board or a RSVB1600 board to a RS232 port and apply power to the board. Then go to Menu bar "Run" and select "Start with full compile (see figure 2.6). The program is compiled and ready to run. When you click at the "Command1" button, the LED representing output 6 in the board should light up and text1 box should show some number. If you see these indeed, then you have successfully build an application software that can tell a device what to do and can monitor its status.

Back to Top

2.4 A more advanced example

In the above example, we need to click at the button to see something happen. You may wonder how we can let things happen automatically. You may also notice in the above example we need to remove the data from inputbuffer before next data can go in, otherwise different type of data can mix up. In next example, we will show how to achieve automation and how to read more inputs at one go.

First we will build an interface as shown in figure 2.7. The ten text boxes belong to one array (Text1). Each of them has its own name (text1(0) to text1(9)). We can make an object array by copying the object and paste it several times. Later you will see that using array can simplify programming considerably. The 10 text boxes will be used to display all the input data from RSVB1000 board. It includes 2 analog input, one counter input, and 7 TTL compatible input. Above each text box is a label indicating the meaning of the data in the text box. We can change the word on a label by changing the "Caption" property through the property panel. The two timers will be used for automation. The interval is set as 100 (milli second) for timer1and 20 for timer2. In the previous example, we set the properties through the property panel In this example, we will show how to set the properties through the code.

Figure 2.7 Interface in design status

Figure 2.8 Interface in running status

Below is the complete code for this example. When the "Start" button is clicked, timer1 is enabled. When timer1 is enabled, it will start counting. When the counting is equivalent to 100 ms, it will generate an event (make something happen) and start 2nd round of counting. If it is not disabled, timer1 will repeatedly generate events every 100 ms. These events can be used to achieve automation.
Code Explanation
Dim RSVBinput As String This section is for defining variables that can be used by all the subs in the program. RSVBinput will be used to read the input from the RSVB1000 board.
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 100
Timer2.Enabled = False
Timer2.Interval = 20

MSComm1.Settings = "38400,n,8,1"
MSComm1.CommPort = 1
MSComm1.PortOpen = True

Dim i As Integer
For i = 0 To 9
Text1(i).Text = ""
Next i

End Sub

This sub tells what to do when the software is just launched (form loaded). Here the properties are set for the timers and the RS232 communication port. In the previous example, we set the properties through the property panel. You may use either approach.

Here the CommPort is set as 1. It varies with the real port number in the PC. You may use the RSVBtest software to find the accurate port number.

Command "Timer1.Enabled = False" will disable the timer. Without doing this, the timer will start running when the program is launched.

These four line commands clear the 10 text boxes. If the box is not named under one array, we will have to use 10 command lines to clear the box one by one.

Private Sub Form_Unload(Cancel As Integer)
MSComm1.Output = "L20" + Chr(13)
MSComm1.PortOpen = False
End Sub
This section tells what to do when you quite the program. First it will set all output to low. Then it will close the communication port

Private Sub Command1_Click()

Timer1.Enabled = True
MSComm1.Output = "P250" + Chr(13)
MSComm1.Output = "M250" + Chr(13)
End Sub

Command1 is the name of the "Start" button. When the button was added to the form, the word on it is the same as its name. Later we changed it to "Start" by modifying its caption property. When this button is clicked, timer1 starts generating events repeatedly. The other two command lines are for setting the duty cycle of PWM1 and PWM2 output. The RSVB1500 driving board use the PWM output to regulate current for output 1-8.
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
When the "Stop" button is clicked, it will stop the process by disabling timer1.
Private Sub Command3_Click()
Timer1.Enabled = False
MSComm1.Output = "L20" + Chr(13)
MSComm1.PortOpen = False
End
End Sub
When the "Exit" button is clicked, the running process will stop, all the output in the RSVB1000 board will be switched off, the RS232 port will be closed, and finally the program will be closed.
Private Sub Timer1_Timer()

MSComm1.Output = "I8" + Chr(13)
Timer2.Enabled = True

If Val(Text1(0)) >= 35 Then
MSComm1.Output = "H18" + Chr(13)
ElseIf Val(Text1(0)) < 30 Then
MSComm1.Output = "L18" + Chr(13)
End If

If Val(Text1(5)) = 0 Then
MSComm1.Output = "X1" + Chr(13) + "I2" + Chr(13) + "S400" + Chr(13)
End If

End Sub
When timer1 counting reaches its set value (100 ms) an event called "Timer1_timer" will occur. This event will trigger following actions: 1) send out command "I8" to ask RSVB1000 or RSVB1600 to send out all its input data; 2) enable timer2 for reading the input data; 3) control output 18 using the analog signal An1; 4) let a stepper motor move 400 steps at step/2 ms in direction 1 when input In1 is 0. As the event "timer1_timer" occurs repeatedly, the program will trigger the actions again and again. Action 3 may be used to control a heater or a cooling fan according to feedback of a temperature sensor. Action 4 may be used to do position control. When In1 in RSVB1000 is connected to ground, In1 will be 0. Then the stepper motor connected to outputs 1- 4 will move 400 steps.

Private Sub Timer2_Timer()

RSVBinput = MSComm1.Input
Dim head As Integer
Dim tail As Integer
head = InStr(RSVBinput, "A")
tail = InStr(RSVBinput, "B")
If head > 0 Then
Text1(0).Text = Mid$(RSVBinput, head + 1, tail - head - 1)
End If

head = InStr(RSVBinput, "B")
tail = InStr(RSVBinput, "C")
If head > 0 Then
Text1(1).Text = Mid$(RSVBinput, head + 1, tail - head - 1)
End If

head = InStr(RSVBinput, "C")
tail = InStr(RSVBinput, "D")
If head > 0 Then
Text1(2).Text = Mid$(RSVBinput, head + 1, tail - head - 1)
End If

head = InStr(RSVBinput, "D")
If head > 0 Then
Text1(3).Text = Mid$(RSVBinput, head + 1, 1)
Text1(4).Text = Mid$(RSVBinput, head + 2, 1)
Text1(5).Text = Mid$(RSVBinput, head + 3, 1)
Text1(6).Text = Mid$(RSVBinput, head + 4, 1)
Text1(7).Text = Mid$(RSVBinput, head + 5, 1)

Text1(8).Text = Mid$(RSVBinput, head + 6, 1)
Text1(9).Text = Mid$(RSVBinput, head + 7, 1)
End If

Timer2.Enabled = False


End Sub

When timer1 enables timer2, timer2 will count for 20 ms and then generate event "timer2_timer". The 20 ms interval will allow the command "I8" to reach RSVB1000 board and all the input data to reach the computer. The timer2_timer event will trigger 3 actions: 1) remove the input data in the inputbuffer and give them to variable RSVBinput; 2) separate the mixed data and put then to individual text box; 3) disable itself. Since timer1 will enable timer2 every 100 ms, timer2 will run repeatedly as well.

The major part of this section is for sorting out the input data. When the RSVB1000 send out the data, they are put together in the inputbuffer. To help identify which is which, RSVB1000 insert some letters in between. The whole data string is like "A25B119C0D1111111". Its sequence is as A-An1-B-An2-C-Cn1-D-In1 to In7. The process for sorting out the information is called "parsing". In VB this can be done using two functions. One is "InStr" and the other "Mid$". (Perhaps your head start aching now. Do not give up. After here the rest will be easy).

InStr can be used to check if a word or a letter exists in a text string. Command line head = InStr(RSVBinput, "A") checks if RSVBinput has letter "A" and its position in the string. The value of variable head is the position of the letter in the string. If head=0, the letter does not exist in the string.

MId$ function can be used to get a segment of content from a text string. Command line Text1(0).Text = Mid$(RSVBinput, head + 1, tail - head - 1) will take the content starting from next to letter A and end before letter B in RSVBinput and put the content to text1(0) box as An1 value.

After getting An1, the program goes to next until all the input data have been sorted out. You may notice for In1 to In7 only head is used for the parsing. This is because these TTL inputs have fixed length (one letter each). We can calculate their position once we locate the position of letter D. For other inputs, the length can change, we have to use a head and a tail to get the complete piece of information. As timer1 triggers timer2 repeatedly, the data in the 10 text box will be updated every 100 ms (0.1 second).

The parsing part may look a bid complicated. It is OK if you do not understand it fully. You can copy this part to your future program for getting the input data. The parsing approach is more reliable than the approach used in the previous example for getting the input data. When you run this program, the interface screen will be like the one in figure 2.8. You may notice the icons for timer and MScomm are not there.

Back to To Top

3. Control stepper motors

3.1 Introduction


Stepper motors are excellent for position control. Unlike DC motors, their speed is not affected by the loading as long as it is not beyond its loading capacity. They are so reliable that an open loop control is sufficient for most situations. Stepper motors can be classified as unipolar and bipolar types. The figures below show the major difference of the two.

Both types have two groups of coils. A unipolar motor has two extra wires connected to the middle of each coil. You can tell the type of a stepper motor according to its number of wires. A bipolar motor normally has only 4 wires while a unipolar motor normally has 6 wires. Some unipolar motors have 5 wires when the two middle wires are jointed as one. Occasionally you may see a unipolar motor with 8 wires in which each coil is divided into two coils.

Figure 3.1 Unipolar stepper motor

Figure 3.2 Bipolar stepper motor

3.2 Drivers of stepper motors

Stepper motors are driven using electric pulses. A motor moves only one step with one pulse. To make a stepper motor run continuously, we need to provide electric pulses repeatedly. For each pulse, the current flow for each coil needs to change following a certain sequence pattern. Below are two sequence examples for moving stepper motors:

a1 a2 b1 b2 The sequence on the left can be used to drive a unipolar stepper motor. In the first pulse, the current flows from V+ to a1. In pulse 2 the current flows from V+ to a2, etc.. In pulse 5, the sequence will start from line 1 again. a1 a2 b1 b2 The sequence on the left is for a bipolar stepper motor. First current flow from a2 to a1 and b2 to b1, then the current in coil b will change direction. Next current in coil a will change direction. In step 4, current in coil a will change direction again.
on off off off - + - +
off on off off - + + -
off off on off + - + -
off off off on + - - +

If the sequence is executed in an opposite direction (from bottom to top), the motor will move in the other direction. When a bipolar motor is running, both coils are powered for each pulses, while in case of unipolar motor, only one coil is powered for each pulse. It is why a bipolar stepper motor is more powerful than a unipolar steper motor.

In the sequence for a unipolar stepper motor, current always flow from V+ to one of the 4 coil ends. We only need to control 4 switches for diverting the current to the right ends of a coil. In the sequence for a bipolar motor, current will change direction in each step. It makes the control for a bipolar motor a bid more complicated. Normally a H-bridge circuit is needed for current direction change.

Since control of a stepper motor is not straight forward, a driving circuit is needed between a micro controller and a stepper motor. The driving circuit looks after the sequence of current flow and provides suitable current output for the motor. Normally the pulse generation is done by the microcontroller.

3.3 Control stepper motors using RSVB1000 + RSVB1500 boards or a RSVB1600 board

3.3.1 Working principle

The RSVB1000 interface board has two build-in drivers for driving two bipolar stepper motors simultaneously. The drivers look after both pulse generation and sequence pattern. The relevant commands for VB are very simple. Below are two examples:

MSComm1.Output = "X1" + Chr(13) + "I2" + Chr(13) + "S400" + Chr(13) (move motor X 400 steps at interval 2 ms/step)

MSComm1.Output = "Y2" + Chr(13) + "I5" + Chr(13) + "S0" + Chr(13) (move motor Y till In2 =1 at interval 5 ms/step)

The command has 3 parts separated by chr(13). The first part tells which motor to run and the moving direction. "X" is for motor connected to outputs 1-4 and "Y" is for motor connected to outputs 5-8. The digit after the letter (1 or 2) tells the moving direction. As the real direction depends on the wire connection, you need to test with a specific motor to decide which is clockwise and which is counter clockwise. The second part tells the interval between steps (in ms). The third part tells the number of steps. If it is 0, the motor will move until it reaches its home position. For motor X the home position is indicated by status of input In1 and for motor Y In2 is used as indicator. If we want a motor to move to a certain position, first we need to drive it to its home position and then let it move necessary steps from there. The RSVB3000 experiment station has a sensor for detecting the home position and ready wiring allowing you to practice the position control.

A RSVB1600 board can be used to drive stepper motors directly. As the output of RSVB1000 cannot provide sufficient current for a motor, a RSVB1500 board need to be used to provide larger current. A RSVB1600 board is equivalent to a combination of a RSVB1000 and a RSVB1500 board. In the rest of this tutorial, a RSVB1000 and a RSVB1500 are used. The information can be easily applied to a RSVB1600 board.

3.3.2 Hardware connections

When a RSVB1500 board is attached to a RVB1000 board, it is ready for driving two stepper motors. Figure 3.3 shows how to make the connection. Outputs 1-4 is for motor X and output 5-8 is for motor Y. Although the build-in driver is for bipolar stepper motors, it can also use unipolar stepper motors. You can follow the same way as connecting bipolar stepper motors and simply leave the V+ wires unconnected.

It can be a challenging task to figure out which wire is a1 and which is b2 as different manufacturers may follow different style. We do not have to differentiate between a1 and a2 or between b1 and b2. It is sufficient to find out which two wires belong to the same coil. In case of unipolar stepper motor, we also need to identify the V+ wire. This can be easily done by measuring resistance between the wires. If the resistance between two wires is in mega Ohm range, they belong to different coils. The resistance between the two ends in a coil is normally less than 200 Ohms. The resistance between V+ and one of the two ends in the same coil should be half of the resistance. For example if the resistance between a1 and a2 is 100 Ohms, the resistance between V+ and a1 should be 50 Ohms.

When connecting a stepper motor to outputs 1-4, make sure outputs 1 and 2 are used by the wires from the same coil. In case of outputs 5-8, make sure outputs 5 and 6 are used by the wires from the same coil. It is OK if you swap the two wires in the same coil.

Figure 3.3 Connection diagram for using RSVB1500 to drive stepper motors

After connecting the stepper motor to a RSVB1500 board, we need to consider the power supply. The supplied voltage for a RSVB1000 can be 8-24 volts. As shown in figure 3.3, a short wire can be used to connect the power from RSVB1000 to RSVB1500 board. Since each of outputs 1-8 can only have up to 500 mA output current, the working current of the stepper motor should be smaller than this value. Ideally the working voltage of the stepper motor should be the same or slightly lower than the supplied voltage. If the working voltage of the stepper motor is lower than the supplied voltage, we can use PWM1 and PWM2 to make an adjustment. Outputs 1-4 is regulated by PWM2 and output 5-8 is regulated by PWM1. If the supplied voltage is 24 volts and the stepper motor can only take 12 volts, we can set the duty cycle of relevant PWM to 215 (refer to section 1.4 and user manuals for more information about PWM technique).

3.3.3 Position control

To drive a stepper motor to a certain position, we need a reference point. This reference point is called its home position. We can drive the motor to its home position and then move necessary steps from there. A sensor is needed to tell if the home position has been reached. Figure 3.4 shows an optic sensor and its working principle. A 5 volt power is applied to the LED and its light switches on the transistor. Input In1 in RSVB1000 is connected to ground when the transistor is on. The status of In1 is 0 (same as ground). When light from the LED is blocked, In1 is cut from the ground. Its status becomes 1 (5 volt).

Figure 3.4 optic sensor

In RSVB3000 experiment station, an optic sensor is used for detecting the home position of the stepper motor. Such sensor is widely used for position control.

Back to To Top


4. Control DC motors

4.1 Introduction

It is very easy to make a DC motor turn. It can be done by simply connecting one of the wire to the positive end of a power supply and the other wire to the negative end of the power supply. It is also easy to make a DC motor change direction. Simply swapping the connection of the two wires will achieve this. The task becomes more challenging if we want to make the direction change occur automatically, to make a DC motor move at a steady speed when its load is changing, or to make a DC motor move to a certain position. A DC motor tends to move faster when its load is low. When the load is increased, the DC motor will slow down and the current flowing through the coil will increase. When we want a DC motor to stop, it will keep moving for some time, making it difficult for position control. The control becomes more complicated than controlling stepper motors. However, DC motors have their advantages over stepper motors in that the hardware connection is simpler, move is smoother, and their loading capacity is larger then stepper motors of similar wattage or size. When the load becomes too heavy, a stepper motor will simply give up (step slipping). But a DC motor will slow down and increase the current to keep the load moving. A geared DC motor is very good for moving heavy loads. The RSVB3000 experiment station is installed with a geared DC motor.

4.2 Control direction of DC motors

To change moving direction of a DC motor without manually swapping wire connection, a H-bridge circuit is needed. The RSVB1500 board has such circuits. Two outputs are needed to enable direction control. Either of these four output pairs can be used for direction control: 1 and 2, 3 and 4, 5 and 6, and 7 and 8. Let us use output 5 and 6 as an example. When output 5 is set to high and output 6 is set to low, current will flow from output 5 to DC motor and then to the ground through output 6. When output 5 is set low and output 6 is set high, the current flow direction and the motor moving direction will change. When both outputs 5 and 6 are set high, motor will be stopped with a braking effect. We can also stop a motor by setting the two outputs to low but it will take longer time since there is no braking effect.

In VB, we only need following two commands to change the direction of a DC motor:

MSComm1.Output = "H5" + Chr(13)+ "L6" + Chr(13)

MSComm1.Output = "L5" + Chr(13)+ "H6" + Chr(13)

4.3 Control speed of DC motors

PWM technique can be used to control the speed of a DC motor. Here we use an example to show how it can be done. The example needs RSVB1000 interface board, RSVB1500 driving board, and the RSVB3000 experiment station. The geared DC motor on RSVB3000 experiment station is connected to output 5 and 6 on RSVB1500 board. The encoder for the DC motor on the experiment station is connected to counter1 on the RSVB1000 board for speed feedback. This encoder consists of an optic sensor (see figure 3.4) and a disk with 60 slits. The disk is mounted on the shaft of the motor. When a slit passes the optic sensor, counter 1 status changes from high to low and the counter will increase by one. We can find out the speed according to the counter value within a period. Below is the Software interface and the code.

The form has 2 text boxes and 4 command buttons. Command1 and command2 are for start and stop. Command3 and command4 are for changing the set speed value. Two timers are used for automation. The interval is 1000 for timer1 and 10 for timer2. The MSComm1 setting is the same as in section 2.3. The properties are set with the property panel.

Figure 4.1 Interface in design stage

Figure 4.2 Interface in running stage

Code Explanation
Option Explicit
Dim setspeed As Integer
Dim realspeed As Integer
Dim pwmvalue As Integer
Define variables.
Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
Text1.Text = "30"
Text2.Text = "0"
MSComm1.PortOpen = True
End Sub
This section tells what to do when the software is launched.

It stops timer, clear text box, and set text1 box value as 30.

Open the communication port

Private Sub Form_Unload(Cancel As Integer)
MSComm1.Output = "L20" + Chr(13)
MSComm1.PortOpen = False
End Sub
This section tells what to do when closing the software.

Switch off all the outputs and close the communication port.

Private Sub Command1_Click()
pwmvalue = 200
MSComm1.Output = "P" + Str(pwmvalue) + Chr(13)
Timer1.Enabled = True
MSComm1.Output = "H5" + Chr(13)
End Sub
When the start button is clicked, it will set the value for pwm1, switch on pwm1, start timer1 and switch on output 5. The DC motor will start running when both pwm1 and output 5 are switched on. Here variable pwmvalue is used to tell the pwm setting. Str(pwmvalue) tells VB to send the pwmvalue as string. The effect is equivalent to "P" +"200" + Chr(13)
Private Sub Command2_Click()
MSComm1.Output = "P0" + Chr(13)
Timer1.Enabled = False
Text2.Text = "0"
End Sub
When stop button is clicked, pwm1 is set to 0 (motor will sop), timer1 is stopped, and the real speed display is set to 0.
Private Sub Command3_Click()
If Val(Text1) < 60 Then
setspeed = setspeed + 1
Text1.Text = setspeed
End If
End Sub
When the "+" button is clicked, the value in text1 (set speed) increase by 1. The maximum set speed is limited to 50 count/sec

The DC motor can go up to 60 rpm or one round per second. The encoder disk has 60 slits. The max achievable speed for this motor is 60 count/sec.

Private Sub Command4_Click()
If Val(Text1) > 15 Then
setspeed = setspeed - 1
Text1.Text = setspeed
End If
End Sub
When the "-" button is clicked, the value in text1 (set speed) decrease by 1. The minimum set speed is limited to 15 count/sec

By lowering the pwm duty cycle, the DC motor can go as slow as 5 count/sec but the control is not very stable. So here it is limited to 15 count/sec

Private Sub Timer1_Timer()
MSComm1.Output = "C1" + Chr(13)
Timer2.Enabled = True
End Sub
Start the automatic control process. It will send out command "C1" to get the counter1 value and start timer2 for more controls

This event repeats every second as timer1's interval is 1000 ms.

Private Sub Timer2_Timer()
MSComm1.Output = "C0" + Chr(13)
realspeed = Val(MSComm1.Input)
Text2.Text = realspeed
setspeed = Val(Text1)
pwmvalue = pwmvalue + (setspeed - realspeed) * 2.2

If pwmvalue < 150 Then
pwmvalue = 150
ElseIf pwmvalue > 255 Then
pwmvalue = 255
End If

MSComm1.Output = "P" + Str(pwmvalue) + Chr(13)

Timer2.Enabled = False
End Sub
This event occurs 10 ms after the timer1 event. It gives sufficient time for counter2 data to reach the input buffer. First command "C0" is send to RSVB1000 to set counter1 to 0. Then the counter1 data is fetched from the inputbuffer and put to text2 box.

A new pwm value is calculated according to the difference between the set speed and the measured speed. Here "2.2" is the gain for the control. Its meaning is "to change the speed by 1 unit, the pwm value need to change by 2.2. This is obtained by experiment and will vary with motor and power supply. The real speed is measured when pwm is set at 255 and 155. The gain is 100 divided by the speed difference. This code can be used to get the real speed if the pwm calculation part is removed.

The section from "If" to "End if" is to limit fluctuation of control output (you may remove this section and try again). Finally a new pwm value is sent to RSVB1000 for speed adjustment.

When running this program, the DC motor will run first at 30 count/sec. By clicking at the "+" or the "-" button, the set speed will change. The real speed should make corresponding change to match the new setting. If you use a finger to slow down the motor, you can feel the increased push from the motor for maintaining the original speed.