$29
1
ELEC 3300
LAB 4: TIMER AND PWM FUNCTIONS
A. OBJECTIVE:
1. To familiarize yourself with the MINI-V3 Development Board.
2. To understand the Timer function of STM32.
3. To understand the control of the servo motor
B. PRE-LAB ASSIGNMENT:
1. Study the information about MINI-V3 Development Board from the course website.
2. Study the information about Fire Debugger from the course website.
3. Study the Tutorial for LAB4.
4. Study the SG90 Servo Motor Datasheet from the course website.
C. LAB SETUP DETAILS
1. Connect the Fire Debugger according to the information about Fire debugger. Make sure
that the Green LED of the Fire Debugger is ON.
2. Follow the Tutorial for CubeMX, and information on Tutorial for LAB4 generate a Project
for LAB4 Task 1 to Task 5 using CubeMX. Please be reminded to set the external clock and
debugger interface in CubeMX.
D. EXPERIMENT
In this LAB, there are 5 tasks.
Task 1 – Output SYSCLK via MCO.
Task 2 – Generate a student ID dependent PWM at TIM3_CH1, using SYSCLK as input source.
Task 3 – Generate a student ID dependent PWM at TIM4_CH1, using TIM3 as input source.
Task 4 – You need to change the optimization to see if you output a different frequency.
Task 5 – Control a SG90 servo motor by K1 and K2.
E. PROCEDURES
Task 1 – You need create a Project that configure the MCO to output the SYSCLK via MCO.
Please refer to the Tutorial for LAB4 for the details.
After that, run your program, such that you will be able to see an 8 MHz frequency
signal on the DMM.
Checkpoint 1 : Show your TA that you can output the SYSCLK
Please clearly show to the TA 8MHz frequency signal on the DMM
Task 2 – Generate a student ID dependent PWM at TIM3_CH1, using SYSCLK as input source.
Refer to the Tutorial for LAB4 for the frequency/duty cycle of PWM to your student
ID.
Please refer to Tutorial for LAB4, connect the Red terminal of your DMM to PA.6.
After that, run your program; check if you got the desired PWM on the DMM.
Checkpoint 2 : Show your TA that you finished Task 2
Please clearly show to the TA the duty cycle and the frequency with respect to your Student ID.
2
Task 3 – Generate a student ID dependent PWM at TIM4_CH1, using TIM3 as input source.
Refer to the Tutorial 4 for the frequency/duty cycle of PWM to your student ID.
Please refer to Tutorial for LAB4, connect the Red terminal of your DMM to PB.6.
After that, run your program; check if you got the desired PWM on the DMM.
Checkpoint 3 : Show your TA that you finished Task 3
Please clearly show to the TA the duty cycle and the frequency with respect to your Student ID.
Task 4 – You need to change the optimization to see if you output a different frequency signal.
Your C++ Optimization should already being set to Level 3 (-O3) when generated by
CubeMX.
Try to change your Optimization to Level 0 (-O0).
Compile your program and check the frequency using DMM. Did signal frequency
changed?
Please answer to the TA you if any changes after altering the optimization.
Checkpoint 4 : Show your TA that you finished Task 4
Task 5 – Control a SG90 servo motor by K1 and K2.
Refer to Tutorial for LAB4, and combining with your knowledge of LAB2, write a
program to perform the following task.
At start, servo will stay at the middle
If K1 is pressed, servo turns to one side by 30 degrees from the middle,
when K1 is released it will stay at that position
If K2 is pressed, servo turns to the opposite side by 30 degrees from the middle,
when K2 is released it will stay at that position
If both K1 AND K2 are pressed together, servo will stay at the middle.
when both K1 and K2 are released it will still stay at middle
Checkpoint 5 : Show your TA that you finished Task 5