Professional Documents
Culture Documents
Experiments Report
2
2.2 Summarize the main functions of LED_Init().
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE,
ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_SetBits(GPIOE,GPIO_Pin_5);
}
.
2.3 Explain the meaning of every row in the delay_ms() function.
void delay_ms(u16 nms)
{
u32 temp;
SysTick->LOAD=(u32)nms*fac_ms; // the time loading (systick->Load=24bit)
SysTick->VAL =0x00; // defines the initial value of the systick counter=0
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; // enables the systick to start
do
3
{
temp=SysTick->CTRL;
} while((temp&0x01)&&!(temp&(1<<16))); //this awaits the time to arrive
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //close counter
SysTick->VAL =0x00; // rests the systick counter to 0
}
2.4 Modify the main() function to control the two LED lights on and off at the same
time.
int main(void)
{
delay_init(); //ÑÓʱº¯Êý³õʼ»¯
LED_Init(); //³õʼ»¯ÓëLEDÁ¬½ÓµÄÓ²¼þ½Ó¿Ú
while(1)
{
delay_ms(300); //ÑÓʱ300ms
delay_ms(300); //ÑÓʱ300ms
}
}
4
Experiment 2 Buzzer and key
I. Experimental purpose
1. Understand the different structure of general purpose IOs in the STM32.
2. Understand the configuration code of GPIOs.
3. Know the method to scan a key pressing.
II. Experimental content
1. Read the main() function in the Experiment 2 source code to understand the meaning of
several functions in it , including delay_init (), LED_Init (),BEEP_Init (), and so on.
2. Connect the hardware emulator to debug the source code, observe the result of the
experiment.
III. Experimental steps
1. Write the different modes of GPIO structure and explain them .
> Input floating: the input resistance is too high to allow current to flow
> Input pull-up: is when only the upper transistor is considered to gain the input
> Input-pull-down: is when we have no high transistor so the lower is unbiased
> Analog
> Output open-drain
> Output push-pull
> Alternate function push-pull
> Alternate function open-drain
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE,
ENABLE); //enables the clock command for the required GPIOs
5
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //assign the GPIO pin =pin5
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //defines the GPIO mode as
output mode
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //assign the GPIO speed to
50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //defines GPIOB data type as initstructure
GPIO_SetBits(GPIOB,GPIO_Pin_5); //sets the bits of GPIOB to pin 5
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_ResetBits(GPIOB,GPIO_Pin_8);
}
.
2.3 Combine LED_Init() and BEEP_Init() into one function, the total function to be
realized is unchanged, write the program code. Compile and run the project to
6
verify the correctness of the modification.
int main(void)
{
delay_init(); //ÑÓʱº¯Êý³õʼ»¯
LED_Init(); //³õʼ»¯ÓëLEDÁ¬½ÓµÄÓ²¼þ½Ó¿Ú
//BEEP_Init(); //³õʼ»¯·äÃùÆ÷¶Ë¿Ú
while(1)
{
GPIO_WriteBit(GPIOB, GPIO_Pin_5, Bit_RESET); //LED0=0;
GPIO_WriteBit(GPIOB, GPIO_Pin_8, Bit_RESET); //BEEP=0;
delay_ms(300);//ÑÓʱ300ms
delay_ms(300);//ÑÓʱ300ms
}
}
Experiment 3 KEY
I. Experimental purpose
1. Understand the configuration code of GPIOs.
2. Know the method to scan a key pressing.
II. Experimental content
1. Read the main() function in the Experiment 2 source code to understand the meaning of
several functions in it , including delay_init (), LED_Init (),BEEP_Init (), and so on.
2. Connect the hardware emulator to debug the source code, observe the result of the
7
experiment.
III. Experimental steps
1. Write the different modes of GPIO structure and explain them .
4.Repeat the above steps to measure the deflection sensitivity of the Y2 and fill the
measurement results in Table 3-2.
Table 3-2 measurement of Y2 axis deflection sensitivity
Y2 axis deflection
0.5V 1.0V 2.0V 5.0V
sensitivity (V/cm)
The reading value of Y
axis of the
oscilloscope(V)
The real voltage
measured by
multimeter(V)
error
Note: after each time the knob sensitivity is changed, the coupling button must be set to
the ground, the level knob should be aligned to a horizontal scale. Then the coupling
mode be set up for DC and then begin to measure.
5. Determination of horizontal deflection sensitivity
8
1)Connect the CH2 probe to the output of the signal generator, then switch on the power
supply of the signal generator, select the signal generator output waveform to be sine
wave, and the amplitude be adjusted to Up-p=1V,regulate the signal source frequency
according to the values listed in the following table. Measure the amplitude and period of
the sinusoidal signal by the oscilloscope, and fill the results in Table 3.
Table 3-3 Determination of sine wave
Signal source frequency 0.1 0.2 0.4 0.8 1.6 3.2 6.4 12.8 20
(KHz)
period(mS)
frequency(KH z)
error
2)Observe the waveforms of triangular wave, square wave and sawtooth wave, and
preserve the figures of them.
9
Experiment 4 AC voltage
measurement
I. Experimental purpose
Understand the basic principle of AC voltage measurement, analyze the response of
several typical voltage waveforms to the voltmeter with different detection characteristics
and the conversion relationship between them, last make error analysis for the
measurement results.
1 T
T 0
Full wave mean U u (t ) dt
1 T 2
u t dt
T 0
Effective value U
U
Waveform factor KF
U
UP
Wave peak factor KP
U
Because the measured AC voltage is mostly sinusoidal voltage, and people usually just
want to measure their effective value, therefore, unless specifically stated, the AC
voltmeter is measured with a sinusoidal wave and is determined according to the effective
value, i.e. the indication of the meter is an effective value when the sinusoidal voltage is
measured. When measuring non-sinusoidal signals, readings of voltmeter must be
converted by waveform factor or wave peak factor:
for the mean voltmeter U
KF
10
2. Function signal generator
3. multimeter
Multimeter reading
Peak calculated
value value
Up Oscilloscope
reading
calculated effective
value U
calculated Mean
value U
Multimeter reading
calculated peak value
UP
calculated effective
value U
calculated mean
value U
12
Experiment 5 Measurement of time
I. Experimental purposes
1.Master the method of measuring the cycle and time by the oscilloscope.
2.Master the method of measuring time interval by oscilloscope.
3. Measuring the rising or descending time and pulse width of a pulse by an oscilloscope
Fig 5-3 Measurement of pulse rising Fig 5--4 Pulse width measurement
or descending time
2) Measurement of pulse width
Adjust the vertical displacement to make the midpoint of the amplitude of the pulse wave
staying at the level center, then read the distance between the front and the back along
the horizontal center line, i.e. the distance between the middle point of the front and the
back edge, as shown in Fig 5-4. The measured horizontal distance multiplied by the
indication value of the "t/cm" knob is the width of the pulse being measured.
calculated value / /
14
relative error(℅) / /
Cur1 Cur2 △T
measured value
calculated value / /
Cur1 Cur2 △T
measured value
calculated value / /
Cur1 Cur2 △T
measured value
calculated value / /
15
Experiment 6 Measurement of phase
difference and frequency
I. Experimental purposes
1. Master the method of measuring phase difference by oscilloscope;
2. learn to use the Lissajous figure to measure signal frequency and phase difference.
16
frequency of the signal source to show a circular or oval shape on the oscilloscope screen
indicates that the frequency of the signal is the same as that of the standard signal, but the
phase is not consistent. When the adjustable frequency range of signal source is so small
that it cannot be transferred to the accurate frequency of the measured signal, The signal
source frequency can be adjusted to a multiple or a divisor of the measured signal
frequency, i.e., only when the two frequency is an integer multiple, a stable closed loop
pattern will appear on the screen.
Figure 6-2 is a Lissajous figure with different frequency ratios and different phase
differences,If the ratio m/n can be determined from these figures and the frequency of the
standard signal source is known, the frequency of the measured signal can be calculated.
(b)Lissajous figures with standard signal frequency higher than measured signal frequency
(c)Lissajous figures with standard signal frequency lower than measured signal frequency
18
slowly adjust the first signal generator frequency (< 1000Hz) while remain the second
signal generator unchanged. When the shape of the Lissajous figure in fig 6-2 (c) is
observed, record the frequency of the first signal generator in table 6-3.
19
Experiment 7 CMRR measurement for
3-opamp circuit
I. Experimental purposes
1. Master the principle of 3-opamp circuit;
2. Understand the definition of common mode gain and differential gain of amplifier circuit.
3. Understand the definition of common mode rejection ratio(CMRR).
4. Learn how to measure CMRR.
R6
R7
R8
R9
b. Measure the voltage on the negtive terminal of D1, it should be close to 5V; Adjust W1
slowly with a small screwdriver meanwhile measure the voltage of the middle terminal
until it is 2.5V, adjust W2 in the same way to get its middle terminal to 2.5V. Then connect
these two middle terminals together as shown with dashed line in the circuit, this is the
common mode voltage Uc inputting to later differential amplifier, measure and record it in
table 7-2. Measure the output voltage Uco of the last amplifier and also record the value in
table 7-2.
20
+15V
B
R6 R7 5 TL 084
1K 1K 7
R2 20K
6
Rz
1K -15V
R4
11
20K
W1 A
R1 10K
1K R3 2 TL 084
Ud 10K 1
Ud2 R1 10K
3
R4
W2
R2
4
1K 20K
20K
C
D1 9 TL 084 +15V
1N4733 R8 R9 8
1K 1K 10
Fig 7-1
First disconnect the middle terminals of the two potentiometers as shown in figure 7-2.
Adjust W1 and make its middle terminal voltage 2.60V, while adjust W2 and make its
middle terminal voltage 2.40V, measure the precise voltage of Ud and record in table1.
+15V
B
R6 R7 5 TL 084
1K 1K 7
R2 20K
6
Rz
1K -15V
R4
11
20K
W1 A
R1 10K
1K R3 2 TL 084
Ud 10K 1
Ud2 R1 10K
3
R4
W2
R2
4
1K 20K
20K
C
D1 9 TL 084 +15V
1N4733 R8 R9 8
1K 1K 10
Fig 7-2.
21
3 Gain(c)
6 Gain(d)
7 CMRR
22
Experiment 8 Temperature
measurement with amplifier
I. Experimental purposes
1. Master the principle of 3-opamp circuit and know the calculation of the gain;
2. By measurement of the different points of voltage, understand deeply the working
mechanism of 3-opamp amplifier.
3. Learn to use thermometer in real circuit to measure temperature and know the basic
automatic measurement system by demonstration.
23
+15V
B
R6 R7 5 TL 084
1K 1K 7
R2 20K
6
Rz
1K -15V
R4
11
20K
A
R1 10K
R3 2 TL 084
Ud 10K 1
Ud2 R1 10K
3
R4
R2
4
20K
20K
C
D1 9 TL 084 +15V
1N4733 R8 R9 8
1K 1K 10
Fig 8-1
2. Measurement of 3-opamp circuit
Measure voltages on Ud, Ud2 and final output Vout and fill in table 8-1, calculate the
different gains according to measured values and compare them with theoretical values
calculated in 3rd step. At last measure different pins’ voltage showing in table 8-1 and
record them.
table 8-1
Pin Number Voltage(V)
Ud
Ud2
Vout
G1
G2
Gtotal
Pin5
Pin6
Pin9
Pin10
Pin2
Pin3
thinking: why pin5 and pin6, pin9 and pin10, pin2 and pin3 are almost equal
respectively?
3. measurement of temperature
1) Remove R8 in figure 8-1, add PT1000 thermal resistor into that path and make the
circuit to be figure 8-2. The circuit in the small red rectangle is the equivalent circuit of
thermal resistor PT1000.
24
+15V
B
R6 R7 5 TL 084
1K 1K 7
R2 20K
6
Rz
1K -15V
R4
11
20K
A
R1 10K
R3 2 TL 084
Ud 10K 1
Ud2 R1 10K
3
Vout
r R4
D1 R2
4
1N4733 20K
R9 20K
1K C
PT1000 9 TL 084 +15V
8
10
r
r
Fig 8-2
2) Next measure and record voltages listed in following table 8-2. Also remember that we
have got the real total gain Gtotal in step 2 which is a constant during the whole
measurement process, and the measured data in table 8-2 will again verify that result.
table 8-2
Pin Number Voltage(V)
VD1
Pin5
Pin10
Vout(corrected)
note: the corrected Vout should be the measured Vout subtracts common mode voltage UCO
recorded in table7-2.
3) According to VD1, R6( the precise resistance is already recorded in Table 7-1) and the
measured voltage in Pin5(that is also the middle voltage of left path of the Wheastone
bridge), we can calculate the current PT1000 resistance which is changing with
temperature. Record the calculated resistance into table 8-3 and lookup the Resistance
-temperature table of PT1000 to get current temperature and record it in table 8-3.
4) Put the PT1000 thermal resistor into boiling water and measure its temperature in same
process as 3), record it into table 8-3.
Every time of measuring, also record the temperature with standard thermometer and
compare them to see whether your measurement are accurate.
table 8-3 temperature record
PT1000 measured standard
resistance(Ω) temperature(℃) temperature(℃)
room environment
boiling water
25
cannot be measured directly in automatic measurement system, but the output voltage
Vout could be measured by AD converter for calculation by computer and it can calculate
the voltage in Pin10 from Vout. Furthermore the computer can compute temperature by
this voltage. In this way we could construct an automatic temperature measurement
system. This system will be demonstrated by teacher.
26