0% found this document useful (0 votes)
11 views26 pages

3 - Timer Excersics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views26 pages

3 - Timer Excersics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Basics Timer

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*

- Configure the DAC to observe the TIM4 Counter


Value [UP/Down/UPDOWN]
- Configure the TIM4 in OUTPUT Compare NO
Output Mode [5 kHz Update Event Rate].
- Enable the Interrupt and Toggle the PD12 pin.
- Observe the Pulses at Respective Pin for Different
UP/Down/UpDown operation of counter.
*Exercise 7*

- Configure the DAC to observe the TIM4 Counter


Value [UP/Down/UPDOWN]
- Configure the TIM4 in OUTPUT Compare CH1
(using Output PIN) [5 kHz Update Event Rate].
- Enable the Interrupt and Toggle the PD12 pin.
- Observe the Pulses at Respective Pin for Different.
*Exercise 8 [Self Exercise]*
- Generate the Phase shifted Pulse using the PWM OC Unit.
- Switching Frequency= 50 kHz, [Choose Appropriate Counting Mode]
- Phase shift Variation Range= 0 Degree to 180 Degree
- Display the Phase Shift on Display.
- Vary the Phase shift using Key Press
- Key1 : Enter Key,
Key2: Start/Stop Key,
Key3: Increase phase shift by 10 Degree and
Key 4: Decreases phase shift by 10 Degree
- Change in Phase Shift should apply after the pressing of Key 1 and Phase shift
should increment or decrement by rate of 10 Degree/2 Sec.
*Exercise 9 [Self Exercise]*
- Generate the Phase shifted Pulse using the PWM OC Unit.
- Switching Frequency= 50 kHz, [Choose Appropriate Counting Mode]
- Phase shift Variation Range= -90 Degree to 90 Degree
- Display the Phase Shift on Display.
- Vary the Phase shift using Key Press
- Key1 : Enter Key,
Key2: Start/Stop Key,
Key3: Increase phase shift by 10 Degree and
Key 4: Decreases phase shift by 10 Degree
- Change in Phase Shift should apply after the pressing of Key 1 and Phase shift
should increment or decrement by rate of 10 Degree/2 Sec.
*Exercise 10* [PWM Operation]
- Generate the 4 PWM Pulse using TIM3
- Switching Frequency= 10 kHz, UP Counting Mode
- Duty of different PWM= 10 %, 45%, 85%, 60 %
- PWM MODE 1/ PWM MODE 2
- Compare Polarity HIGH/ Compare Polarity LOW
Step 3: Analyze the results for Down count mode, PWM MODE 1, 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 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 Main.C file -> Main () function before while (1)

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)

In Main.C file -> in while (1)

In Main.C file -> after Main ()


*Exercise 13* [PWM Input (To measure Frequency
and Duty Cycle)]
- Generate the PWM Pulse using TIM3 CH1, 5 kHz, 30 % Duty
- Configure the TIM2 in Dual Channel PWM INPUT mode to measure the
Frequency and Duty Cycle of the signal generated using TIM3 CH1.
- Change the frequency of the TIM3 CH1 PWM pulse using ARR value and
verify the frequency measurements.
- Change the Duty Cycle of the TIM3 CH1 PWM pulse using CCR value and
verify the duty cycle measurement.
- And Print the Frequency and Duty Cycle on the LCD
Step 1: utilize TIM3 CH1 PWM Generation, 5 kHz 30 % duty. Now, Setup the TIM2
CH1 in PWM Input mode
Step 1 (Continue): Setup the TIM2 CH1 in PWM Input mode and Generate the Code
*Exercise 12* [QEP or Encoder Mode]
- Generate Two 20 kHz pulses with 50% duty cycle and phase shifted by 90%
to each other using TIM4. [Virtual A and B pulse]
- Set the TIM1 into ENCODER MODE.
- Show the Mechanical Angle using DAC and Display the Direction on LCD.
*Exercise 13* [Advanced Timer PWM]
- Generate the PWM Pulses using TIM8
- Switching Frequency= 5 kHz
- Duty Cycle= 5 %, 35 %, 65 %
- Complement Pulse Generation with Dead Band of 1 uSec
- Enable the Timer Shutdown option
*Exercise 14* [SPWM V/F Code]

- Generate the PWM Pulses using TIM8


- Switching Frequency= 5 kHz
- Complement Pulse Generation with Dead Band of 1 uSec
- Key Settings:
- PD3- Start/Stop
- PD4- Increment MI
- PD5- Decrement MI
- PD6- Applied MI
- Display the “Actual MI” and “MI to be applied”
- Display the ON/OFF Status on Display.
- Arrange the Soft-Start for the Same.

You might also like