314 10 VOLTAGE AND TEMPERATURE MEASUREMENT
screen. In general, gotoxy() is used to set the position of the cursor, and therefore there is no need for a line feed or carriage return.
The measured value of the pulse period is a ‘representation’ of the square wave period. This value is obtained by using the member function MeasurePeriod() of the Vco object. We use the cprintf() function to call the MeasurePeriod() function. The cprintf() function prints the measured value divided by 1000 on the screen.
The member function GetLastOutput() of the DAC class is called to obtain the previous value output to the DAC. This value is then used within the switch statement block to ensure that the byte being sent to the DAC is kept within its operating range of 0 to 255 for each press of the up or down arrow key. The two cases corresponding to the up arrow and the down arrow have been implemented using the SendData() function of the DAC class. Depending whether the up or down arrow key has been pressed, the value sent to the DAC is either incremented or decremented by 8. During execution of the SendData() function, the data member LastOutput of the DAC class is updated to store the value just output.
Origin (1,1)
Positive y
Positive x
Figure 10-5 Screen coordinates in text mode.
Three code modules are required to generate an executable program for the code segment shown in Listing 10-6. These are the ParallelPort, VCO, and DAC modules. A project file (or make file) must be formed to compile all modules and link them together to form the executable file. The VCO module consists of the header file given in Listing 10-1 and the function file given in Listing 10-4. The ParallelPort class header file and its function file were formed in Section 9.4 and are repeated in Listing 10-7 and Listing 10-8, respectively.
10 VOLTAGE AND TEMPERATURE MEASUREMENT 315
Listing 10-7 Header file for the ParallelPort class - pport.h.
#ifndef PportH #define PportH
class ParallelPort
{
private:
unsigned int BaseAddress; unsigned char InDataPort1;
public:
ParallelPort(); ParallelPort(int baseaddress);
void WritePort0(unsigned char data); void WritePort2(unsigned char data); unsigned char ReadPort1();
virtual ~ParallelPort(){}
};
#endif
Listing 10-8 Function file for the ParallelPort class - pport.cpp.
#include <dos.h> #include "pport.h"
ParallelPort::ParallelPort()
{
BaseAddress = 0x378; InDataPort1 = 0;
}
ParallelPort::ParallelPort(int baseaddress)
{
BaseAddress = baseaddress; InDataPort1 = 0;
}
void ParallelPort::WritePort0(unsigned char data)
{
outportb(BaseAddress,data);
}
void ParallelPort::WritePort2(unsigned char data)
316 10 VOLTAGE AND TEMPERATURE MEASUREMENT
{
outportb(BaseAddress+2,data ^ 0x0B);
}
unsigned char ParallelPort::ReadPort1()
{
InDataPort1 = inportb(BaseAddress+1);
//Inverting Most significant bit to compensate
//for internal inversion by printer port hardware. InDataPort1 ^= 0x80;
//Filter to clear unused data bits D0, D1 and D2 to zero. InDataPort1 &= 0xF8;
return InDataPort1;
}
So far we haven’t created a header file and a function file for the DAC module. These files are given in Listing 10-9 and Listing 10-10 respectively.
Listing 10-9 The header file for the DAC class - dac.h.
#ifndef DacH #define DacH
#include "pport.h"
class DAC : public ParallelPort
{
private:
unsigned char LastOutput;
public:
DAC();
DAC(int baseaddress);
void SendData(unsigned char data); unsigned char GetLastOutput(); ~DAC(){};
};
#endif
Listing 10-10 The function file for the DAC class - dac.cpp.
#include "dac.h"
10 VOLTAGE AND TEMPERATURE MEASUREMENT 317
DAC::DAC()
{
LastOutput = 0;
}
DAC::DAC(int baseaddress) : ParallelPort(baseaddress)
{
LastOutput = 0;
}
void DAC::SendData(unsigned char data)
{
ParallelPort::WritePort0(data); LastOutput = data;
}
unsigned char DAC::GetLastOutput()
{
return LastOutput;
}
Executable File Generation
|
Required Files |
|
Listing No. |
|
Project File Contents |
|
|
pport.cpp |
|
Listing 10-8 |
|
pport.cpp |
|
|
|
|
|
|
pport.h |
|
Listing 10-7 |
|
|
|
|
vco.cpp |
Listing 10-4 |
|
vco.cpp |
|
vco.h |
Listing 10-1 |
|
dac.cpp |
|
dac.cpp |
Listing 10-10 |
|
|
|
dac.h |
Listing 10-9 |
|
|
|
|
period.cpp |
Listing 10-6 |
|
period.cpp |
|
The table shown above lists all the files needed to form the executable file that should be stored in the one directory. Form a project file using the program development environment of your choice and add the files that are listed in the column titled ‘Project File Contents’. Then the compiler and linker can be directed to form the executable file. Tables such as the one shown above will be provided in this text whenever modules must be combined to form an executable file.
Make the connections on the interface board as shown in Table 10-1 to Table 10-3 before executing the program. These tables list the wiring needed to control the DAC and the VCO. Set the DAC output to unipolar mode by fitting the jumper across the position on the board marked LINK1. Remember to connect an operational 9V battery to its terminal block (J14) to allow proper DAC operation. Note that the VCO response is linear (typically 1%) for input voltages in the range
318 10 VOLTAGE AND TEMPERATURE MEASUREMENT
of 2.2V to 2.8V. Although linearity deteriorates outside this range, the VCO can be characterised across its entire input range and used effectively.
Table 10-1 Connections for the DAC.
BASE Address |
DAC0800 |
(Buffer IC, U13) |
(U8) |
D0 |
D0 (12) |
D1 |
D1 |
(11) |
D2 |
D2 |
(10) |
D3 |
D3 |
(9) |
D4 |
D4 |
(8) |
D5 |
D5 |
(7) |
D6 |
D6 |
(6) |
D7 |
D7 |
(5) |
Table 10-2 INPUT connections for the VCO.
LM358 |
VCO |
(U10B) |
(4046, U4) |
|
|
VDAC (7) |
VIN (9) |
|
|
NOTE
Table 10-3 OUTPUT connections for the VCO.
VCO |
BASE+1 Address |
(4046, U4) |
(Buffer IC, U6) |
|
|
VCO OUTPUT (4) |
D3 |
|
|
If any malfunction occurs; first check the 9V battery is operational – its voltage
should be greater than 7V when it is being used.
10.6 Graphics Programming – Square
Wave Display
A program was developed in Section 10.5 that can measure the period of the square wave generated by the VCO and produce a simple numerical output. In this section we will use graphics programming to generate a graphical display so the user can visualise the signal’s waveform.
10 VOLTAGE AND TEMPERATURE MEASUREMENT 319
The potentiometer circuit on the interface board provides a very convenient means of generating an analog voltage to apply to the input of the VCO. Varying the position of the potentiometer will change its output voltage (0V to +5V) and hence change the output frequency of the VCO. The connections that need to be made between the potentiometer and the VCO are shown in Table 10-4 and Table 10-5.
Table 10-4 INPUT connections for the VCO.
Potentiometer |
VCO |
(POT1) |
(4046, U4) |
OUTPUT |
VIN (9) |
Table 10-5 OUTPUT connections for the VCO.
VCO |
BASE+1 Address |
(4046, U4) |
(Buffer IC, U6) |
VCO OUTPUT (4) |
D3 |
|
|
10.6.1 Screen Programming
This program to be developed will display the signal from the VCO as a waveform inside a fixed area of the screen. The waveform being displayed will trace across the screen similar to the trace of an oscilloscope. This must happen in real-time; the changes shown on-screen matching the instantaneous changes of the VCO signal.
The standard library provides many graphics routines for our program to use. These routines can determine which graphics driver should be used, the appropriate graphics mode, the maximum number of pixels in x and y directions, etc. The screen uses an array of pixels, where each pixel is one element of the screen that is individually illuminated to form part of the picture. Because different screens contain different numbers of pixels, it is often necessary to determine the screen’s pixel count before deciding the size of the display area to be used by a program.
In any graphics program running under DOS, the system must first be configured in a graphics mode that uses a graphics driver. A driver is a module of executable code that is used to drive the actual graphics output. These drivers can operate in different modes that set the number of pixels used in x and y directions, and set which colour palette to use. The program must set the system in a suitable graphics mode and then determine the number of pixels in the x and y directions. This information allows the program to calculate the screen coordinates needed to centre the waveform on-screen inside the area known as the Viewport. Figure 10-6 shows the screen coordinates and the calculations performed by the program’s functions to generate the waveform.