Course Code: MDP 454, Course Name:, Second Semester 2014 PC-based controller for Mechatronics System
Mechanical System PC Controller Controller in the Mechatronics System Configuration Actuators Power Amplification Sensors Signal Conditioning
Controller PC Computer based Controllers The controller is the PC (Personal Computer). Here attention is paid to: Programming Language Interface Pc Board CAN BUS GPIB Serial/parallel
Programming Languages Higher level Programming languages, Matlab Labview
Parallel Port (LPT) A parallel port is a type of interface found on computers for connecting peripherals. In computing, a parallel port is a parallel communication physical interface, it is also known as a printer port. It was an industry standard for many years in the late 1990s. Today, the parallel port interface is seeing decreasing use because of the rise of Universal Serial Bus (USB) and FireWire devices, along with network printing using Ethernet.
Parallel Port (LPT) Most PC-compatible systems in late1990s had one to three ports, with communication interfaces defined like this: Logical parallel port 1: I/O port 0x3BC, IRQ 7 (LPT1) Logical parallel port 2: I/O port 0x378, IRQ 7 (LPT2) Logical parallel port 3: I/O port 0x278, IRQ 5 (LPT3) PORT NO Interrupt # Starting I/O Ending I/O #1 IRQ 7 0x3BC 0x3BF #2 IRQ 7 0x378 0x37F #3 IRQ 5 0x278 0x27F
Parallel Port (LPT) The parallel printer ports (LPT) had an 8-bit data bus and four pins for control output (Strobe, Linefeed, Initialize, and Select In), and five more for control input (ACK, Busy, Select, Error, and Paper Out). Its data transfer speed is at 12,000 kbps.
Parallel Port (LPT) Pin No (DB25) Signal name Direction Register - bit Inverted 1 Strobe In/Out Control-0 Yes 2 Data0 Out Data-0 No 3 Data1 Out Data-1 No 4 Data2 Out Data-2 No 5 Data3 Out Data-3 No 6 Data4 Out Data-4 No 7 Data5 Out Data-5 No 8 Data6 Out Data-6 No 9 Data7 Out Data-7 No 10 Ack In Status-6 No 11 Busy In Status-7 Yes 12 Paper-Out In Status-5 No 13 Select In Status-4 No 14 Linefeed In/Out Control-1 Yes 15 Error In Status-3 No 16 Reset In/Out Control-2 No 17 Select-Printer In/Out Control-3 Yes 18-25 Ground - - -
Parallel Port (LPT) Example: Write a C++ code to control the status of 8 LEDs through the LPT port, where the user enters the desired value of LEDs, and accordingly they light up or not.
Parallel Port (LPT) Example: (Solution) Almost all programming languages allow programmers to access parallel port using some library functions. VC++ provides two functions to access IO mapped peripherals, '_inp' for reading and '_outp' for writing. These functions are declared in "conio.h".
Parallel Port (LPT) Example: (Solution) The schematic for the circuit to be used to test the Parallel port for digital output to control the LEDs is shown next. Where, each digital pin is used as output to control the status of each corresponding LED, if pin value is (1) its corresponding LED would light up, and vise versa.
Parallel Port (LPT) Example: (Solution) Now to write the code: Start VC++ IDE, Select 'New' from File menu. Then select Win32 Console Application from Projects tab. Enter the project name as partest1 for example, then click OK button.
Parallel Port (LPT) Example: (Solution) Select a simple Application and click Finish. Now open a new example1.cpp from file view and start writing the code given next. First, declare the libraries to be used in your code, remember that conio.h is the library that includes functions for LPT interfacing. #include "stdafx.h" #include "conio.h" #include "stdio.h" #include "string.h" #include "stdlib.h"
Parallel Port (LPT) Example: (Solution) Error handling, in case the user input less arguments int main(int argc, char* argv[]){ short data; if(argc<1){ printf("usage\n\n"); printf("partest1.exe,,\n\n\n"); return 0; } Main Function declared and starts here _outp(atoi(argv[2]),atoi(argv[3])); printf("data written to parallel port is "); printf("%s\n\n\n\n\n",argv[3]); } return 0; } Output the value entered to the desired LPT port and display message.
Parallel Port (LPT) Example: (Solution) Then (Build) the project, and to test the program, start typing the following in the console. Note: Make sure you connect the hardware correctly, and that you know which parallel port you are using, assuming here that LPT2 is used (at address 0x378). Open DOS command window (cmd). Move to the projects directory, assuming it is "C:\" for example, then type: and press enter. partest1 888 255
Parallel Port (LPT) Example: (Solution) If everything is correct, LED1 to LED8 in the hardware will glow. Otherwise re-check your connections and the success of your program build. Here (partest1) is name of the executable file of the program we developed, and we write it to start running the code. Also 888 which is (0x378) but in decimal numbering system is the address of the parallel port data register. Finally 255 which is (0x11111111) but in decimal numbering system, to indicate that the value to be written to the parallel port data register is to set all the pins to (1), or to turn all the LEDs on.
Data Acquisition Cards (DAQ) Data acquisition is the process of measuring an electrical or physical phenomenon such as voltage, current, temperature, pressure, or sound. PC-based data acquisition uses a combination of modular hardware, application software, and a computer to take measurements. While each data acquisition (DAQ) system is defined by its application requirements, every system shares a common goal of acquiring, analyzing, and presenting information. Data acquisition systems incorporate signals, sensors, actuators, signal conditioning, DAQ devices, and application software.
Data Acquisition Cards (DAQ) Example: NI USB-6008 The National Instruments USB-6008 provides basic data acquisition functionality Analog Inputs: 8 SE/4 DI 10 ks/s 12 bits Analog Outputs: 2 150 S/s 12 bits Digital I/O: 12 DIO Counter/Timers: 1 32 bits 5 MHz Measurement Type: Voltage
Data Acquisition Cards (DAQ) Example: NI USB-6251 BNC The National Instruments USB-6251 BNC is a USB high-performance M Series multifunction data acquisition Analog Inputs: 8 SE/8 DI 1.25 MS/s 16 bits Analog Outputs: 2 2.86 MS/s 16 bits Digital I/O: 24 DIO 1 MHz Counter/Timers: 2 32 bits 80 MHz Measurement Type: Quadrature encoder, Voltage
DAQ Analog [Reference Single Ended (RSE)]
DAQ Analog [Differential Mode (DI)] Differential Mode Two channels used for each signal ACH 0 is paired with ACH 8, ACH 1 is paired with ACH 9, etc. Rejects common-mode voltage and common-mode noise Measurement System
DAQ Analog [Differential Mode (DI)]
DAQ Programming Labview Matlab
DAQ Digitization Issues The big issue with digital conversion: a continuous value is made discrete In amplitude (Y axis issues) Resolution Saturation In time (X axis issues) Aliasing Leakage Frequency resolution
Digital DAQ SIGNAL RESOLUTION ISSUES (Y axis issues)
DAQ Digitization Issues Analog-Digital conversion: -quantization: -A continuous value is compared with a series of fixed, discrete intervals (states) -encoding: -The interval mean value is converted into a digital, usually binary, chain of elements
Digital DAQ Binary representation: Data type length = N bit Binary encoding = O / 1 Having only two states possible per element allows for very robust handling and transmission systems since the difference between states can be high and electronics is simple and cheap.
Digital DAQ DIGITAL RESOLUTION Having N bit data length 2 N different states 3 bit 2 3 =8 different states(1 byte = 8 bit) 8 bit 2 8 =256 states 10 bit 2 10 =1024 states 12 bit 2 12 =4096 states 14 bit 2 14 =16384 states 16 bit 2 16 =65536 states
output Digital DAQ AD converter transfer function is not linear: output = 2 N states input = continuous value input
Digital DAQ Resolution = minimum variation of the input quantity that can be detected by the AD converter. It is equal to the value of the least significant bit (the smallest one) LSB= least significant bit 1 LSB = FS / 2 N
Digital DAQ Resolution depends on both the full scale input of DAQ converter and bit length of data field Ex: FS=10 V N=3 bit LSB=1.25 V FS=10 V N=8 bit LSB=39 mv FS=10 V N=12 bit LSB=2.44mV resolution FS max 2 n FS min
DAQ Resolution Example 3-bit resolution can represent 8 voltage levels 16-bit resolution can represent 65,536 voltage levels Amplitude (volts) 10.00 8.75 7.50 6.25 5.00 3.75 2.50 1.25 0 0 16-Bit Versus 3-Bit Resolution (5kHz Sine Wave) 111 110 101 100 011 010 001 000 50 100 150 200 Time (ms) 16-bit resolution 3-bit resolution
DAQ Resolution Example Signal 3 bit 5 bit
Digital DAQ SIGNAL SAMPLING FREQUENCY ISSUES (X axis issues)
Digital DAQ SAMPLING: Conversion of a time continuous value into a chain of values V t V (t i, V i ) i=1,... N t
Digital DAQ Both V amplitude and it s time coordinates are discrete values depending on ADC capabilities and configuration SAMPLING TIME t C = t i - t i-1 SAMPLING FREQUENCY f C = 1 / t C V t i-1 t i t i+1 t
Digital DAQ Witch sampling frequency can be used to represent a signal without altering it? V t V t both OK, but somehow different
Digital DAQ If sampling frequency is too low a problem with frequency representation can occur: called aliasing V t Sampling signal is no longer recognizable, and its frequency seems lower than the original one.
Digital DAQ The issue of aliasing is related to the ratio between sampling frequency f S and signal frequency f A f S < 2 f A aliasing occurs f S > 2 f A f S = 2 f A f S < 2 f A
Digital DAQ Nyquist-Shannon theorem: if a continuous signal with a top limited bandwith contains only components with frequency up to f Amax therefore a coherent representation could be achieved bu a sampling frequency f S > 2 f Amax
Digital DAQ f S = 1 / t S f A = 1 / T A being f S > 2f A t S < T A / 2 We require at least two samples for each half period...
Nyquist Example Aliased Signal 100Hz Sine Wave Sampled at 100Hz Adequately Sampled for Frequency Only (Same # of cycles) 100Hz Sine Wave Sampled at 200Hz 100Hz Sine Wave Sampled at 1kHz Adequately Sampled for Frequency and Shape
DAQ Hardware 1. Signal 2. Terminal Block 3. Cable 4. DAQ Device 5. Computer 43
Analog to Digital Conversion (ADC) There are different methods in use that represent analog to digital conversion, such as: 1. The successive approximation ADC 2. Dual Slope Ramp ADC (long conversion time) 3. Parallel or flash A/D converter (Short conversion time).
ADC Successive Approximation The successive approximation ADC represents one of the (long conversion time) conversions. The Successive Approximation ADC employs a feedback system to perform the conversion. Essentially, a comparator is used to compare the input voltage, V x, to a feedback voltage, V F, that comes from a DAC. The comparator output signal drives a logic network that steps the digital output (and hence DAC input) until the comparator indicates the two signals are the same within the resolution of the converter.
Successive Approximation (ADC) ADC Successive Approximation
ADC Successive Approximation Illustration of 4-bit SAC with 1 volt step size
ADC Successive Approximation The logic circuitry is such that it successively sets and tests each bit, starting with the most significant bit of the word. We start with all bits zero. Thus, the first operation will be to set b 1 = 1, and test V F = V R 2-1 against V x through the comparator. If V x is greater, then b1 will be 1, b 2 is set to 1, and a test is made of V x versus V F = V R (2-1 + 2-2 ), and so on. If V x is less than V R 2-1, then b 1 is reset to zero, b 2 is set to 1, and a test is made of V x versus V R 2-2. This process is repeated to the least significant bit of the word. The conversion time of successive approximation-type ADCs is on the order of 1 to 5 μs per bit.
ADC Successive Approximation (Example): Find the successive approximation ADC output for a 4 - bit converter to a 3.217V input if the reference is 5 V.
Parallel or flash ADC
RAMP ADC
RAMP ADC The output of the DAC is applied to the other terminal of the comparator. Since the output of the DAC is increasing with the counter, it will trigger the comparator at some point when its voltage exceeds the analog input. The transition of the comparator stops the binary counter, which at that point holds the digital value corresponding to the analog voltage.
Digital to Analog Conversion (DAC) When data is in binary form, the 0's and 1's may be of several forms such as the TTL form where the logic zero may be a value up to 0.8 volts and the 1 may be a voltage from 2 to 5 volts. The data can be converted to clean digital form using gates which are designed to be on or off depending on the value of the incoming signal. Data in clean binary digital form can be converted to an analog form by using a summing amplifier. For example, a simple 4-bit D/A converter can be made with a four-input summing amplifier. Two Basic Approaches Weighted Summing Amplifier R-2R Network Approach
Weighted Sum DAC M-bit D/A converter
Weighted Sum DAC
R-2R Ladder DAC
DAQ Example Prepare a LabVIEW code to produce and read an analog voltage using a DAQ (NI USB-6008): The Voltage output to be produced is to be output on pin (AO0). The Input Voltage to be read from pin (AI0) For the sake of simplicity, read from the input pin, the value produced from the output pin, to confirm that the produced value is the desired.
DAQ Example (Solution) The hardware to be used is NI USB-6008 DAQ. Connect the DAQ to the PC, and make sure its driver is installed, and running with no problems. Connect the pins to be used in this example to their target destinations (as shown below).
DAQ Example (Solution) Open the LabVIEW software and develop the following control front panel to be used for controlling our example. The panel shows a dial for the Analog Output to be produced, and a gauge to reflect the Analog Input sensed by the DAQ.
DAQ Example (Solution) In the Block Diagram, the Following code will be implemented:
Thank You For Your Attention! Questions?