Final Report - University of Victoria

advertisement
University of Victoria
Faculty of Engineering
Spring 2008
ELEC 499 Technical Report
Distributed Feedback Laser Controller
in partial fulfillment of the requirements of the
B.Eng. Degree
Name
Bryson Medlar
Justin Latimer
Lynn Yin
Rejoy Isaac
Student Number
0229518
0226363
0332710
0233349
Email address
bmedlar@uvic.ca
jlatimer@engr.uvic.ca
lynnyin@uvic.ca
risaac@engr.uvic.ca
Project Demonstration: March 27, 2008
Report Submission: April 4, 2008
ELEC499 – Distributed Laser Feedback Controller
Group 2
Faculty of Engineering
University of Victoria
P.O. Box 3500 STN CSC
Victoria, British Columbia
V8W 3P6 Canada
April 4, 2008
Attention: Dr. Thomas E. Darcie
Dear Dr. Darcie
Please accept the accompanying Elec499 Report entitled “Distributed Laser Feedback
Controller.” This report is the result of lab work and research experience at the University of
Victoria: Faculty of Electrical and Computer Engineering.
All group members are pleased with the success of our design project. The material was very
interesting and we learned a lot. The project encompassed many aspects of electrical engineering
that we have acquired over the last four years including fibre optics, communication, electronics,
microcontrollers and programming. The purpose of this document is to outline the technical
aspects of our design as well as providing complete documentation for future research
opportunities.
The ELW A117 laboratory was excellent. Thanks to Dr. Darcie for his patience and expertise, as
well as the individuals that work in the lab who were extremely helpful. Special thanks are given
to Samuel Liang for his aid in troubleshooting issues involving interfacing between devices.
Sincerely,
Group Number 2
4th Year Electrical Engineering Students
1
ELEC499 – Distributed Laser Feedback Controller
Group 2
Table of Contents
Table of Contents ................................................................................................................ 2
List of Table and Figures .................................................................................................... 3
1.0 Summary ....................................................................................................................... 4
2.0 Introduction ................................................................................................................... 5
3.0 Results and Discussion ................................................................................................. 6
3.1 Distributed Feedback Laser Module ......................................................................... 6
3.2 Laser Diode Mount ................................................................................................... 6
3.3 Thermoelectric Cooler Controller ............................................................................. 7
3.4 Constant Current Driver ............................................................................................ 8
3.5 Microcontroller ......................................................................................................... 8
3.6 Optical Spectrum Analyzer ....................................................................................... 8
3.7 Tunable Laser Source ............................................................................................... 9
3.8 Device Interfacing ..................................................................................................... 9
3.8.1 Hardware ............................................................................................................ 9
3.8.2 Wiring Schematic............................................................................................... 9
3.8.3 Software ........................................................................................................... 11
3.9 Applications ............................................................................................................ 11
3.9.1 Terahertz Signal Generation ............................................................................ 11
3.9.2 CARS Spectroscopy......................................................................................... 11
4.0 Conclusion .................................................................................................................. 13
5.0 Recommendations ....................................................................................................... 14
6.0 References ................................................................................................................... 15
6.1 Cited References ..................................................................................................... 15
Appendix A: Progress Report #1 ..................................................................................... 16
Appendix B: Progress Report #2 ..................................................................................... 17
Appendix C: C-Code........................................................................................................ 19
Appendix D: BASIC Code............................................................................................... 26
2
ELEC499 – Distributed Laser Feedback Controller
Group 2
List of Table and Figures
Table 1: Internal Wiring of Mount (Male Connector) ....................................................... 7
Table 2: Internal Wiring of Mount (Female Connector) ................................................... 7
Table 3: List of Hardware .................................................................................................. 9
Figure 1: Flow Diagram ..................................................................................................... 6
3
ELEC499 – Distributed Laser Feedback Controller
Group 2
1.0 Summary
A digital control system for fibre optic lasers will be designed. A laser is characterized
by its operational frequency, output power, and linewidth. Laser power is controlled by
the current, and the frequency linewidth of the spectrum is controlled by the temperature.
A constant linewidth and power is required for most purposes, but it is sometimes
necessary to modulate these parameters.
In our project, a distributed feedback laser module is used. Contained in this butterfly
package is a laser diode, along with a thermoelectric cooler, a thermistor, and a photo
diode. The TEC can be controlled by an external TEC controller. The TEC controller
reads the temperature from a thermistor in the laser module, and in turn adjusts the TEC
to keep the laser at a constant temperature. A second external controller is used to
maintain a constant desired laser power output. The laser diode constant current driver
monitors the laser’s power output with the laser module’s internal photo diode. The
current driver can then adjust the laser’s input current to maintain constant power.
Desired temperature and input current can be set on the TEC controller and current
driver, respectively. This is to be done by using our proposed controller. An application
of our DFLC was implemented to demonstrate its capabilities. A second tunable laser
source was coupled with the laser output from our laser module and inputted into an
optical spectrum analyzer. Using GPIB to establish communication between the OSA
and a PC, measurements of wavelength and signal power were obtained. After
interfacing the PC with a microcontroller, these values were used to maintain a constant
difference wavelength. Maintaining a constant difference wavelength between two
closely spaced laser signals has many research applications.
4
ELEC499 – Distributed Laser Feedback Controller
Group 2
2.0 Introduction
In many optical research applications – such as terahertz wave generation and CARS
spectroscopy – it is important to maintain a constant and precise separation in the
wavelength of two lasers. One way to achieve this is to have an uncontrolled reference
laser and a second laser with a control system that continually monitors the reference
beam and makes wavelength adjustments to the controlled beam in order to maintain this
constant separation. The Distributed Feedback (DFB) Laser Controller uses three
feedback loops to precisely match the wavelength and power of a laser to a reference
beam: a wavelength detection loop (utilizing an optical spectrum analyzer), a temperature
control loop (using a thermistor and a thermoelectric cooler), and an optical power
control loop (using a monitor photodiode and a constant current driver). The wavelength
detection of the two lasers is performed by the optical spectrum analyzer and this
measured information is then sent to a PC which calculates the wavelength difference and
sends commands to the microcontroller to increase, decrease, or leave unchanged the
desired setting of the temperature control loop. Controlling the optical output power is
done in much the same way, although this functionality is not used in the wavelength
difference controlling application. Although there are systems with similar functionality
on the market, the DFB Laser Controller was created for a fraction of the cost which
makes it highly feasible for many research applications.
5
ELEC499 – Distributed Laser Feedback Controller
Group 2
3.0 Results and Discussion
The following flow diagram outlines the communication and control connections used in
this project. Additional detailed connection information can be found in the Device
Interfacing section.
Figure 1: Flow Diagram
3.1 Distributed Feedback Laser Module
A Nortel LC155W – 20A WDM DFB Laser Module was used as the primary laser diode
source. This laser module is conveniently built into a 14-pin butterfly package which is
easily mounted in a laser diode mount. The laser module has nominal operating
wavelength of 1539.44nm. This corresponds to IEEE Channel #47 in fibre optic
communication applications. There is a thermo electric cooler (TEC), thermistor, laser
diode, and monitor photo diode included within the package. The thermoelectric cooler
is required to keep the laser diode at a precise temperature (see Thermoelectric Cooler
Controller (TECC)). A thermistor is used to indicate temperature. The value of
resistance is proportional to the temperature. The monitor photo diode is used to measure
the laser output power.
3.2 Laser Diode Mount
The DFB laser module is securely placed in a mount. An ILX Lightwave – LDM-4980
Series Laser Diode Mount was used in this project. The mount has several purposes. It
provides a way to fasten the 14-pin butterfly package laser diode. The mount allows easy
6
ELEC499 – Distributed Laser Feedback Controller
Group 2
connections to the laser module via 9-pin serial cable connectors (RS-232). It can easily
be re-wired to accommodate different laser diode packages. The internal mount
connections are shown below. The mount also acts as a large heat sink allowing the laser
diode to be kept at a relatively constant temperature thus resisting change caused by the
environment.
9-pin Serial
Connector
M1-1
M1-2
M1-3
M1-4
M1-7
M1-8
Wire Color
RED
RED
BLACK
BLACK
ORANGE
YELLOW
Butterfly
Pin #
6
6
7
7
1
2
Table 1: Internal Wiring of Mount (Male Connector)
9-pin Serial
Connector
M2-3
M2-4
M2-5
M2-6
M2-7
M2-8
M2-9
Wire Color
GREEN
BROWN
BROWN
BLUE
GREY
WHITE
WHITE
Butterfly
Pin #
GRD MT
3
3
5
4
11
11
Table 2: Internal Wiring of Mount (Female Connector)
3.3 Thermoelectric Cooler Controller
The butterfly laser package includes a thermo electric cooler (TEC) to maintain a
constant temperature. The TEC operates on the principle of a heat pump using the Peltier
Effect. It transfers heat from one side of the device to the other side against the
temperature gradient (from cold to hot), with consumption of power [2]. This TEC
requires control via a thermoelectric cooler controller (TECC) and uses a feedback loop
to monitor its status. The feedback loop uses a 10KΩ NTC type thermistor. A Thorlabs
TCM1000T - 3W TEC Controller was chosen for the purposes of this project. This unit
has max 3V 1A or 3W output power. Temperature is monitored and set using a scaled
voltage based on the thermistor resistance for a given temperature. The TECC required
some modification. A potentiometer providing control range from 5kohm to 25kohm
was removed and replaced with a digital potentiometer (Microchip - MCP42050). This
was done in order to automate the process of changing temperature. Also included on the
TECC board, is a Proportional Gain adjustment potentiometer and an Integral Gain
adjustment potentiometer. System response can be adjusted for various thermal loads
using these pots. TECC status is monitored via JP3-5 (monitor TSET), and JP3-6
7
ELEC499 – Distributed Laser Feedback Controller
Group 2
(monitor TACT). A relay including normally open and normally closed dry-type
contacts is also included on the TECC for monitoring purposes. This functionality was
not implemented in our controller design, but can be used as status indication and
incorporated into an external control circuit.
3.4 Constant Current Driver
A current driver is required to provide power to the laser module. A Thorlabs LD1225R – Laser Diode Constant Current Driver was chosen to operate the laser in
constant current mode up to a maximum of 250mA. The current driver has several
modes of operation to set working current including an onboard 12-turn trim
potentiometer, an external 0 to 5VDC input, or a combination of both. The driver was
implemented in external current control mode by placing a jumper between pins J2-1 and
J2-2. The driver uses a feedback loop including a photodiode to monitor its status. There
is an onboard amplifier that converts the photodiode current to a voltage that can be
measured to monitor the laser power. Prior to applying or removing the power source to
the driver, a disable pin must be shorted to ground. This precaution is taken to avoid
power supply transients that can potentially damage the current driver circuitry. The
disable pin also allows a user to stop laser output without having to remove supply
power.
3.5 Microcontroller
A Basic Stamp 2 (BS2) microcontroller was chosen for monitoring and control of the
TECC and Current Driver. Inputs were taken from JP3-4, JP3-5, and JP3-6 on the TECC
and from J1-10 and J1-9 on the current driver. These inputs were used strictly for
monitoring purposes. Since the BS2 is strictly a digital device, an ADC was required.
Two outputs from the BS2 were used for control of the TECC and current driver. A
digital to analog converter was required to input 0 to 5VDC into the current driver’s
external current control. The other output was used to vary the resistance of a digital
potentiometer which controls the desired temperature on the TECC.
Serial communication was established between the PC and BS2. This communication
was used to instruct the BS2 to increase or decrease the wavelength and/or laser power.
For additional information, see the Device Interfacing section.
3.6 Optical Spectrum Analyzer
An optical spectrum analyzer (Agilent – 86142B) was used to view the wavelength and
amplitude of the signal from the laser diode. Using GPIB to establish communication
between the OSA and a PC, measurements of wavelength and signal power were
obtained. Now that these values are in the PC, instructions to raise or lower
wavelength/amplitude can be sent from the PC to the BS2 and then the BS2 will output
the desired wavelength/amplitude.
8
ELEC499 – Distributed Laser Feedback Controller
Group 2
3.7 Tunable Laser Source
An Agilent – 8164A Tunable Laser Source was used as a second signal. The tunable
laser source and the laser diode signals were coupled and inputted into the optical
spectrum analyzer.
3.8 Device Interfacing
3.8.1 Hardware
The following list is inclusive of all hardware elements used in the distributed feedback
laser controller.
Agilent – 8164A Tunable Laser Source
Agilent – 86142B Optical Spectrum Analyzer
Basic Stamp 2 Microcontroller
ILX Lightwave – LDM-4980 Series Laser Diode Mount
Interface Computer
Maxim – MAX534 – 8-bit Quad DAC
Microchip - MCP42050 Digital Potentiometer
National Semiconductor – ADC0838 8-Channel MUX
Nortel – LC155W – 20A WDM DFB Laser Module
Thorlabs - LD1225R – Laser Diode Constant Current Driver
Thorlabs – TCM1000T – 3W TEC Controller
Table 3: List of Hardware
3.8.2 Wiring Schematic
See next page
9
ELEC499 – Distributed Laser Feedback Controller
Group 2
10
ELEC499 – Distributed Laser Feedback Controller
Group 2
3.8.3 Software
Two software applications were written to control the Basic Stamp 2 microcontroller and
to read wavelength measurements from the Optical Spectrum Analyzer over GPIB.
A C program was run on a workstation which communicates with the OSA over GPIB
interface. The program defines the desired difference in operating wavelengths of the two
lasers and measures the same (in nm) continually and sends appropriate instructions to
the microcontroller. The microcontroller receives instructions from the C program and
performs one of the three actions: increases the temperature, decreases the temperature or
remains idle.
The workstation is connected to the Optical Spectrum Analyzer and the
microcontroller over a GPIB (NI-488) and Serial interface respectively. The control
application written in the C programming language, uses libraries provided by National
Instruments to communicate over the GPIB interface. The program presets the Optical
Spectrum analyzer and adjusts the span and center wavelength on the OSA to cover the
adjustable wavelength range of the DFB laser. It then runs an infinite loop where it
calculates the wavelengths of the two lasers by measuring the wavelengths of the two
peaks on the OSA. The program sends different strings to the microcontroller over the
serial interface corresponding to the difference in the two measured wavelengths. If the
difference in the wavelengths is within a certain range (1 – 1.5nm), it sends the character
‘A’. If the difference is lesser than 1nm, it sends the character ‘B’. Otherwise, it sends the
character ‘C’. The source code is included in Appendices.
3.9 Applications
3.9.1 Terahertz Signal Generation
Terahertz waves are in the region of the electromagnetic spectrum between 300GHz and
3THz [1]. Terahertz radiation is generated through a technique called photo-mixing that
uses two lasers. The laser beams are superposed (mixed) and their output is focused onto
a photo-mixer device which generates the Terahertz radiation. It is technologically
significant because there are few sources capable of providing radiation in this waveband.
The advantages of this technique are that it is continuously tunable over the frequency
range from 300GHz to 3THz (10cm-1 to 100cm-1)(1mm to 0.1mm), and spectral
resolutions in the order of 1MHz can be achieved. Terahertz radiation has various
applications in medical imaging, security, spectroscopy, and communication.
3.9.2 CARS Spectroscopy
Raman Spectroscopy is a technique used to analyze the composition of a compound by
observing the Raman scattering effect when the sample is illuminated with a laser beam.
When light impinges upon a molecule, it is either excited from the ground state to a
virtual energy state or if the molecule was already in an elevated vibrational energy state,
it is brought back to the ground state. The former phenomenon is called Stokes Raman
11
ELEC499 – Distributed Laser Feedback Controller
Group 2
Scattering while the latter is called Anti Stokes Raman Scattering. One of the major
difficulty of Raman Spectroscopy is the weak Raman scattering.
Coherent Anti Stokes Raman spectroscopy (CARS) is another form of Raman
Spectroscopy where three laser beams (Pump beam, Stokes beam and Probe beam) are
used and a coherent optical signal is produced at the Anti Stokes frequency. This signal is
resonantly enhanced when the difference between the Pump and Stokes beams coincides
with the frequency of a Raman resonance.
12
ELEC499 – Distributed Laser Feedback Controller
Group 2
4.0 Conclusion
The ability to automatically maintain a constant and precise frequency separation
between two laser beams can be extremely useful in various research applications. This
project successfully demonstrates how the operating frequency and optical power of a
tunable laser can be automatically controlled by adjusting its temperature and drive
current. The Distributed Feedback Laser Controller can be implemented in future laser
research.
13
ELEC499 – Distributed Laser Feedback Controller
Group 2
5.0 Recommendations
A Basic Stamp 2 (BS2) microcontroller was implemented for the purposes of this laser
controller. The Basic Stamp 2 microcontroller cannot handle floating point data which
limits device functionality. For this reason, calculation of difference wavelength must be
conducted in the PC (C-code) and commands for raising and lowing frequency are sent to
the microcontroller. Another limitation of the BS2, is that the device can handle only
digital values. For this reason, analog to digital converters (ADC) and digital to analog
converters (DAC) were implemented for I/O purposes. The BS2 also has minimal
memory. It is recommended that a more advanced microcontroller be used to improve
performance.
The ADC and DAC used for input and output of the BS2 have 8-bit resolution. The
precision of the laser controller can therefore be improved by using components with
higher bit resolutions. Choosing a more advanced microcontroller with onboard ADC
and DAC’s would also prove a solution to this limitation.
The Optical Spectrum Analyzer is a very expensive piece of equipment. Removing this
device from the circuit and replacing with a more cost efficient item would yield better
practical purposes. The OSA can be replaced by a frequency locker to output the
operating frequency of the laser.
All command changes, such as the desired difference wavelength, must be made through
C and/or BS2 code. A graphical user interface can be implemented to aid in setting
desired wavelengths, difference frequencies, amplitudes, etc.
14
ELEC499 – Distributed Laser Feedback Controller
Group 2
6.0 References
6.1 Cited References
[1]
[2]
“Terahertz Radiation”, [online document] available at
http://en.wikipedia.org/wiki/Terahertz_radiation
“Thermoelectric Cooling”, [online document] available at
http://en.wikipedia.org/wiki/Thermoelectric_cooler
15
ELEC499 – Distributed Laser Feedback Controller
Group 2
Appendix A: Progress Report #1
Project Number:
Project Title:
Group Members:
2
Distributed Feedback Laser Controller
Name
Bryson Medlar
Justin Latimer
Lynn Yin
Rejoy Isaac
Faculty Supervisor:
Student Number
0229518
0226363
0332710
0233349
Email address
bmedlar@uvic.ca
jlatimer@engr.uvic.ca
lynnyin@uvic.ca
risaac@engr.uvic.ca
Ted Darcie
Project Summary:
A digital control system for infrared lasers will be designed. A laser is characterized by
its operational frequency, output power, and linewidth. Laser power is controlled by the
current, and the frequency linewidth of the spectrum is controlled by the temperature. A
constant linewidth and power is required for most purposes, but it is sometimes necessary
to modulate these parameters.
In our project, a distributed feedback (DFB) laser module is used. Contained in this
butterfly package is a laser diode, along with a thermoelectric cooler (TEC), a thermistor,
and a photo diode. The TEC can be controlled by an external TEC controller
(TCM1000T). The TEC controller reads the temperature from a thermistor in the laser
module, and in turn adjusts the TEC to keep the laser at a constant temperature. A
second external controller is used to maintain a constant desired laser power output. The
Laser Diode Constant Current Driver (LD1255R) monitors the laser’s power output with
the laser module’s internal photo diode. The current driver can then adjust the laser’s
input current to maintain constant power.
Desired temperature and input current can be set on the TEC controller and current
driver, respectively. This is to be done by using our proposed controller.
Assigned Tasks:
Laser Setup: Lynn and Rejoy
Controller: Justin and Bryson
Parts Required:
 LC155W – 20A WCM DFB Laser Module
 Laser Module Mount
TCM1000T - 3W TEC Controller
LD1255R – Laser Diode Constant Current Driver
DSPic Microcontroller
Parts have been ordered and should arrive in one to two weeks.
16
ELEC499 – Distributed Laser Feedback Controller
Group 2
Appendix B: Progress Report #2
Project Number:
2
Project Title:
Distributed Feedback Laser Controller
Faculty Supervisor: Ted Darcie
Group Members:
Name
Student Number
Email address
Bryson Medlar
0229518
bmedlar@uvic.ca
Justin Latimer
0226363
jlatimer@engr.uvic.ca
Lynn Yin
0332710
lynnyin@uvic.ca
Rejoy Isaac
0233349
risaac@engr.uvic.ca
Tasks Completed:
1. Operational testing of the laser diode: The operation of the laser diode was verified by
providing injection current to the laser diode in the butterfly laser package and the
intensity of the infra red light outputted through the fiber optic cable was measured using
an optical power meter.
2. Internal wiring of the laser module mount.
The LDM-4980 Laser diode mount is equipped with configurable pin headers which
allow the mount to be configured for any appropriate laser diode pin-out. Two 9-pin D
connectors in the mount are used for laser current control and laser internal temperature
control. The mount was configured for our laser diode by connecting the colour coded
wires from the 9-pin connector to the corresponding pin on the configurable header.
Connections to the laser module can now easily be made through the two 9-pin D
connectors.
3. TEC controller and Laser Current driver connections
Computer monitor cables with 9-pin connecters were used to provide the interface
between the mount and the TEC Controller and Laser Current driver. The 9-pin D-SUB
male connector on the mount was connected to the TEC controller while the 9-pin DSUB female connector was connected to the constant current driver. (The schematics of
the pin configurations and wiring will be provided in the final report.)
4. Operational testing of the constant current driver
The constant current driver operates within a voltage range of -8 to -12 V. Both internal
current control (using a 12-turn on board potentiometer) and external current control
(using 0 to 5V Analog Input voltage) were tested and used to supply input current
ranging from 0.55mA to about 100mA. The corresponding output power from the laser
was measured using an optical power meter and a maximum output power of around
2mW was measured. (The accurate power versus input current characteristic of the laser
will be provided in the final report)
5. Operational testing of the TEC controller
17
ELEC499 – Distributed Laser Feedback Controller
Group 2
The TEC controller is used to maintain a constant temperature on the device mounted to
the cooler based on feedback provided from a 10kΩ NTC type thermistor sensor. The
temperature control range is from 5kΩ to 25kΩ (approximately 40оC to 10оC).
The TEC controller was tested by setting the desired temperature using an onboard
potentiometer and measuring the actual temperature of the module from the value of the
resistance of the NTC thermistor. The resistance of the thermistor was determined by
measuring the voltage across the appropriate output pins and using the conversion factor
given (1.000V = 10.000kΩ).
Outstanding Tasks:
1. All Programming of DSPic Microcontroller
The controller will be responsible for setting the required temperature and input current
on the TEC controller and current driver respectively for a desired intensity (power
output) and operating frequency of the laser.
A possible addition to the control system could be to control the output of two laser
modules in order to maintain a precise difference in the operating frequencies of the two
lasers.
2. Testing of laser controller
Some hardware testing has been completed. The complete system including DSPic
Microcontroller has yet to be tested. Possible testing procedures may include:
verification of output frequency, verification of output line-width, graphical plots of
applied inputs and corresponding laser output, etc.
3. Poster Presentation, Website, and Final Report
**Hardware not yet acquired:
1. The microprocessor chip for damaged board has not yet arrived. (DSPic
Microcontroller)
2. D/A converter
3. A digital potentiometer is required to replace the potentiometer of the TEC in
order to implement the control system.
18
ELEC499 – Distributed Laser Feedback Controller
Group 2
Appendix C: C-Code
// Example.cpp : Defines the entry point for the console application.
//
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
"stdafx.h"
<windows.h>
<stdio.h>
<stdlib.h>
<malloc.h>
"ni488.h"
<conio.h>
<iostream>
<commctrl.h>
<strsafe.h>
"winbase.h"
<fstream>
using namespace std;
#define ARRAYSIZE
#define
#define
#define
#define
#define
#define
1024
BDINDEX
PRIMARY_ADDR_OF_SCOPE
NO_SECONDARY_ADDR
TIMEOUT
EOTMODE
EOSMODE
0
23
0
T10s
1
0
// Size of read buffer
//
//
//
//
//
//
Board Index
Primary address of device
Secondary address of device
Timeout value = 10 seconds
Enable the END message
Disable the EOS mode
int Dev;
float f1 = 0;
float f2 = 0;
float a1 = 0;
float a2 = 0;
int dummy;
char ValueStr[ARRAYSIZE + 1];
/******************************************/
//Serout variables
BOOL
m_bPortReady;
HANDLE
m_hCom;
DCB m_dcb;
COMMTIMEOUTS m_CommTimeouts;
BOOL
bWriteRC;
BOOL
bReadRC;
DWORD iBytesWritten;
DWORD iBytesRead=0;
char sBuffer[128];
LPCWSTR devP;
const WCHAR com5[5]={'C','O','M','4','\0'};
/******************************************/
19
ELEC499 – Distributed Laser Feedback Controller
char ErrorMnemonic[21][5] = {"EDVR",
"ESAC",
"EOIP",
"ESTB",
Group 2
"ECIC",
"EABO",
"ECAP",
"ESRQ",
"ENOL",
"ENEB",
"EFSO",
"", "",
"EADR", "EARG",
"EDMA", "",
"", "EBUS",
"", "ETAB"};
//void GPIBCleanup(int Dev, char* ErrorMsg);
void GPIBCleanup(int Dev, char* ErrorMsg)
{
printf("Error : %s\nibsta = 0x%x iberr = %d (%s)\n",
ErrorMsg, ibsta, iberr, ErrorMnemonic[iberr]);
if (Dev != -1)
{
printf("Cleanup: Taking device offline\n");
ibonl (Dev, 0);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
char up_message[1]={'C'};
char down_message[1]={'B'};
char ok_message[1] = {'A'};
int write_status;
int close_status;
DWORD num_bytes_written = 0;
devP = (LPCWSTR)com5;
/******************************************************/
//Serial communication stuff
m_hCom = CreateFile(devP,GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING,
0 |FILE_ATTRIBUTE_NORMAL|
//FILE_FLAG_OVERLAPPED |
FILE_FLAG_NO_BUFFERING,NULL);
if (m_hCom == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf("\tCreateFile failed with error%d.\n",GetLastError());
}
//set buffer sizes
m_bPortReady = SetupComm(m_hCom, 128, 128);
//setting up Data Communication block
m_bPortReady = GetCommState(m_hCom, &m_dcb);
m_dcb.BaudRate = 9600;
m_dcb.ByteSize = 8;
m_dcb.Parity = NOPARITY;
m_dcb.StopBits = ONESTOPBIT;
m_dcb.fAbortOnError = TRUE;
m_bPortReady = SetCommState(m_hCom, &m_dcb);
20
ELEC499 – Distributed Laser Feedback Controller
Group 2
//setting up Communication Timeouts
m_bPortReady = GetCommTimeouts (m_hCom, &m_CommTimeouts);
m_CommTimeouts.ReadIntervalTimeout = 50;
m_CommTimeouts.ReadTotalTimeoutConstant = 50;
m_CommTimeouts.ReadTotalTimeoutMultiplier = 10;
m_CommTimeouts.WriteTotalTimeoutConstant = 50;
m_CommTimeouts.WriteTotalTimeoutMultiplier = 10;
m_bPortReady = SetCommTimeouts (m_hCom, &m_CommTimeouts);
/*
*
=======================================================================
=
*
* INITIALIZATION SECTION
*
*
=======================================================================
=
*/
/*
* The application brings the OSA online using ibdev. A
* device handle, Dev, is returned and is used in all subsequent
* calls to the device.
*/
ofstream myfile;
myfile.open ("output_file.txt", ios::trunc);
myfile.close();
Dev = ibdev(BDINDEX, PRIMARY_ADDR_OF_SCOPE, NO_SECONDARY_ADDR,
TIMEOUT, EOTMODE, EOSMODE);
if (ibsta & ERR)
{
printf("Unable to open device\nibsta = 0x%x iberr = %d\n",
ibsta, iberr);
return 1;
}
/* Clear the internal or device functions of the device. If the
* error bit ERR is set in ibsta, call GPIBCleanup with an error
* message.
*/
ibwrt (Dev, "SYStem:preset\n", 15L);
ibclr (Dev);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to clear device");
return 1;
}
/*
21
ELEC499 – Distributed Laser Feedback Controller
Group 2
*
=======================================================================
=
*
* MAIN BODY SECTION
*
* In this application, the Main Body communicates with the instrument
* by writing a command to it and reading its response. T
*
*
=======================================================================
=
*/
/*
* The application issues the '*IDN?' command to the oscilloscope.
*/
ibwrt (Dev, "*IDN?\n", 6L);
printf("ibsta: %d\n", ibsta);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to set oscilloscope");
return 1;
}
/*
* The application reads the identification code in the form of an
* ASCII string from the oscilloscope into the ValueStr variable.
*/
ibrd (Dev, ValueStr, ARRAYSIZE);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to read data from oscilloscope");
return 1;
}
/*
* Assume that the returned string contains ASCII data. NULL
* terminate the string using the value in ibcntl which is the
* number of bytes read in. Use printf to display the string.
*/
ValueStr[ibcntl - 1] = '\0';
printf("Data read: %s\n", ValueStr);
/****************************************************************
***/
//set center frequency
ibwrt (Dev, "Sense:Wavelength:Center 1540nm\n", 32L);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to set oscilloscope");
return 1;
}
/****************************************************************
****/
//set span
ibwrt (Dev, "Sense:Wavelength:span 7nm\n", 28L);
22
ELEC499 – Distributed Laser Feedback Controller
Group 2
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to set oscilloscope");
return 1;
}
//set first marker
ibwrt (Dev, "CALCulate:MARK:state 1\n", 22L);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to set oscilloscope");
return 1;
}
for(;;)
{
//peak search
ibwrt (Dev, "calculate:Marker:MAXimum\n", 28L);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to set oscilloscope");
return 1;
}
//output the frequency of marker 1
ibwrt (Dev, "calculate:Mark1:X?\n", 20L);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to get marker1 frequency");
return 1;
}
ibrd (Dev, ValueStr, ARRAYSIZE);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to obtain frequency info");
return 1;
}
ValueStr[ibcntl - 1] = '\0';
//printf("Frequency1: %s\n", ValueStr);
f1 = atof (ValueStr);
printf("Frequency1: %7.3f nm\n", f1*1000000000);
myfile.open ("output_file.txt", ios::app);
myfile << "Frequency1: "<<f1*1000000000<<" nm\n";
myfile.close();
//output the amplitude of marker 1
ibwrt (Dev, "calculate:Mark1:Y?\n", 20L);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to get marker1 amplitude");
return 1;
}
ibrd (Dev, ValueStr, ARRAYSIZE);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to obtain amplitude info");
return 1;
23
ELEC499 – Distributed Laser Feedback Controller
Group 2
}
ValueStr[ibcntl - 1] = '\0';
a1 = atof (ValueStr);
printf("Amplitude1: %5.3f dBm\n", a1);
myfile.open ("output_file.txt", ios::app);
myfile << "Amplitude1: "<<a1<<" dB\n";
myfile.close();
//move the marker1 to the next highest peak
ibwrt (Dev, "calculate:Marker:MAXimum:next\n", 30L);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to find next highest peak");
return 1;
}
//output the frequency of marker 1
ibwrt (Dev, "calculate:Mark1:X?\n", 20L);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to obtain frequency 2 info");
return 1;
}
ibrd (Dev, ValueStr, ARRAYSIZE);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to read frequency 2 info");
return 1;
}
ValueStr[ibcntl - 1] = '\0';
f2 = atof (ValueStr);
printf("Frequency2: %7.3f nm\n", f2*1000000000);
myfile.open ("output_file.txt", ios::app);
myfile << "Frequency2: "<<f2*1000000000<<"
myfile.close();
nm\n";
//output the amplitude of marker 1
ibwrt (Dev, "calculate:Mark1:Y?\n", 20L);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to get marker1 amplitude");
return 1;
}
ibrd (Dev, ValueStr, ARRAYSIZE);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to obtain amplitude info");
return 1;
}
ValueStr[ibcntl - 1] = '\0';
a2 = atof (ValueStr);
printf("Amplitude2: %5.3f dBm\n", a2);
24
ELEC499 – Distributed Laser Feedback Controller
Group 2
myfile.open ("output_file.txt", ios::app);
myfile << "Amplitude2: "<<a2<<" dB\n";
myfile.close();
printf("Freq difference: %5.3f nm\n", (f2-f1)*1000000000);
printf("Amplitude difference: %5.3f dBm\n\n\n", (a2-a1));
myfile.open ("output_file.txt", ios::app);
myfile << "Freq difference: "<<(f2-f1)*1000000000<<" nm\n";
myfile << "Amplitude difference: "<<(a2-a1)<<" dBm\n\n\n";
myfile.close();
/***************************************/
if((f2-f1)*1000000000<=1.5 && (f2-f1)*1000000000>=1)
{
//we're ok
write_status=WriteFile(m_hCom, ok_message,
sizeof(ok_message), &num_bytes_written, NULL);
printf("wavelength is ok\n");
}
else
if ((f2-f1)*1000000000>1.5)
{
//increase wavelength
write_status=WriteFile(m_hCom, up_message,
sizeof(up_message), &num_bytes_written, NULL);
printf("Increase wavelength \n");
}
else if ((f2-f1)*1000000000<1)
{
//decrease wavelength
write_status=WriteFile(m_hCom, down_message,
sizeof(down_message), &num_bytes_written, NULL);
printf("Decrease wavelength\n");
}
}
close_status=CloseHandle(m_hCom );
/*
=======================================================================
=
*
* CLEANUP SECTION
*
*
=======================================================================
=
*/
/* The device is taken offline.
*/
ibonl(Dev, 0);
return 0;
}
25
ELEC499 – Distributed Laser Feedback Controller
Group 2
Appendix D: BASIC Code
' {$STAMP BS2}
' Program: Laser Control System
'
'variables and constants:
temp
VAR
Byte
current
VAR
Byte
text
VAR
Byte
'Temperature setting (DIGIPOT value)
'Current setting (DAC value)
'Laser wavelength
'DAC
DAC_CS
DAC_DI
DAC_CLK
DAC_addrA
CON
CON
CON
CON
13
15
14
%0011
'POT
POT_CS
POT_DI
POT_CLK
POT_addr
CON
CON
CON
CON
10
'POT Chip Select pin
12
'POT Data In pin (into POT)
11
'POT Clock pin
%11011101
'POT address
'DAC Chip Select pin
'DAC Data In pin (into DAC)
'DAC Clock pin
'DAC-A address
init:
HIGH POT_CS
'deactivate pot
HIGH DAC_CS
'deactivate DAC
temp = $32
'initialise temperature setting
current = $70
'initialise temperature setting
GOSUB POT_out
'send to TECC
GOSUB DAC_out
'send to TECC
PAUSE 5000
main:
SERIN 16, 16468, main, [STR text\2]
IF (text = 65) THEN doNothing
IF (text = 66) THEN temp_down
IF (text = 67) THEN temp_up
END
doNothing:
'DEBUG HEX temp, CR
GOTO main
temp_down:
'decrease TECC temperature setting
26
ELEC499 – Distributed Laser Feedback Controller
Group 2
IF temp = $6a THEN fix_temp_high
temp = temp + 2
'decrement temperature setting
PAUSE 150
GOSUB POT_out
'send to TECC
GOTO main
temp_up:
'increase TECC temperature setting
IF temp = $00 THEN fix_temp_low
temp = temp - 2
'increment temperature setting
PAUSE 150
GOSUB POT_out
'send to TECC
GOTO main
fix_temp_high:
'temp = $64
temp = $68
GOTO temp_down
fix_temp_low:
'temp = $05
temp = $02
GOTO temp_up
sub:
DAC_out:
'send digital value to DAC over serial
LOW DAC_CLK
'reset DAC clock
LOW DAC_CS
'activate DAC
SHIFTOUT DAC_DI,DAC_CLK,MSBFIRST,[DAC_addrA\4,current\8] 'send data
HIGH DAC_CS
RETURN
POT_out:
'send digital value to DIGIPOT over serial
LOW POT_CLK
'reset POT clock
LOW POT_CS
'activate POT
SHIFTOUT POT_DI,POT_CLK,MSBFIRST,[POT_addr\8,temp\8]
HIGH POT_CS
RETURN
END
27
Download