3 - Timer Excersics
3 - Timer Excersics
Exercises
*Exercise 1*
• Calculation of 1 kHz update event using TIM6
(Polling)
Q. What is problem of poling Method ??
Ans.
Keep One Delay of 5 Sec before if loop and
verify the results again for 1 KHz pulse.
is it same ? Or any change happened in
output ?
Analyze it.
*Exercise 2*
TIM6 programming in interrupt mode.
Toggling LED in Interrupt Function
[Method 1]
*Exercise 3*
TIM6 programming in interrupt mode.
Toggling LED in Interrupt Function
[Method 2]
(This is to made easy programming when many
variables are required in interrupt function)
*Exercise 4*
Exercise to know about round robin programming
style for low priority Tasks
- Design Generalized Key_Scan Function and scan it
at every 50 mSec [configure PD3,PD4,PD5,PD6,PD7
as input where keys are connected]
- Design the generalized Display function and scan it
at every 0.5 Sec
- Configure PD12, PD13, PD14 and PD15 as ouput
where LEDs are connected
*Exercise 5* [Self Exercise Continuation of Ex4]
Addition to Exercise 4, Arrange the following Task
-Generate the Three PWM Pulse with 1 kHz Frequency at PD12, PD13, PD14
using basic TIM7.
-PD12 and PD13 PWM should have fix Duty cycle of 30 % and 80 % though out
the operation.
- PD14 PWM should have capability of variable duty cycle. Duty should vary in
range of 10% to 90 % in step of 10 %.
- Use PD3 key to increase the duty and PD4 to decrease the duty of PD14
PWM.
- Display the duty Cycle on the 16x2 Display.
- Addition to it, use PD5 pin [as key] for Turn ON/OFF control of the all the
PWM pulses. When PD5 in OFF state then all the PWM should be in RESET
state.
General Purpose
PWM Timer and
DAC
Exercises
*Exercise 6*
Step 4: Analyze the results for Down count mode, PWM MODE 2, COMPARE HIGH POLARITY.
Check the following wave forms in DSO
i) PA6 (CH1) and PA4 (DAC1)
ii) PA7 (CH2) and PA4 (DAC1)
iii) PB0 (CH3) and PA4 (DAC1)
iv) PB1 (CH4) and PA4 (DAC1)
v) PD14 (LED3) and PA4 (DAC1)
Step 5: Analyze the results for Down count mode, PWM MODE 1, COMPARE LOW POLARITY.
Check the following wave forms in DSO
i) PA6 (CH1) and PA4 (DAC1)
ii) PA7 (CH2) and PA4 (DAC1)
iii) PB0 (CH3) and PA4 (DAC1)
iv) PB1 (CH4) and PA4 (DAC1)
v) PD14 (LED3) and PA4 (DAC1)
Step 6: Analyze the results for Down count mode, PWM MODE 2, COMPARE LOW POLARITY.
Check the following wave forms in DSO
i) PA6 (CH1) and PA4 (DAC1)
ii) PA7 (CH2) and PA4 (DAC1)
iii) PB0 (CH3) and PA4 (DAC1)
iv) PB1 (CH4) and PA4 (DAC1)
v) PD14 (LED3) and PA4 (DAC1)
*Exercise 11* [Self Exercises PWM Operation]
- Generate the Variable duty cycle PWM Pulse using TIM3
- Switching Frequency= 50 kHz
- Duty Variation Range= 5 % to 95 %
- Display the Duty on Display.
- Vary the Duty using Key Press
- Key1 : Enter Key,
Key2: Start/Stop Key,
Key3: Increase duty by 5 Degree and
Key 4: Decreases duty by 5 Degree
- Change in duty should apply after the pressing of Key 1 and Duty should
increment or decrement by rate of 5 Degree/2 Sec.
*Exercise 12* [Input Capture (Frequency
Measurement)]
- Generate the PWM Pulse using TIM3 CH1, 5 kHz, 30 % Duty
- Capture the pulse using TIM2 CH1 and Measure the Frequency of the signal
generated using TIM3 CH1.
- Change the frequency of the TIM3 CH1 PWM pulses using ARR value and
very the frequency measurements.
- And Print the Frequency and Duty Cycle on the LCD
In Main.C file initialization
In IT.C file
In IT.C file
In IT.C file
In Main.C file -> after Main ()
In Main.C file -> Before while (1)