Professional Documents
Culture Documents
Lab2 - 1 Eng
Lab2 - 1 Eng
• Understanding how to use a timer for creating delays and generating pulses.
REFERENCES:
EXPERIMENT 1:
a) Write a delay subroutine of 1 ms using Timer 0. Use this subroutine to generate a 500 Hz
pulse on pin PA0.
b) Simulate and modify the program to achieve accurate pulse generation.
c) Connect pin PA0 to an oscilloscope to verify.
EXPERIMENT 2:
a) Write a program to generate a 64 us square wave using Timer 0 in Normal mode. Use pin
OC0 as the output.
b) Write a program to generate a 64 us square wave using Timer 1 in CTC mode. Use pin
OC0 as the output.
c) Connect pin OC0 to an oscilloscope and observe.
EXPERIMENT 3:
a) Given the program for generating two PWM pulses on OC0A and OC0B, connect pins
OC0A and OC0B to two oscilloscope channels, measure and record the waveform, and
explain the obtained waveform.
.org 00
call initTimer0
https://doe.dee.hcmut.edu.vn/
LAB 2-1
USE TIMER TO GENERATE DELAY AND PULSES
start:
rjmp start
initTimer0:
out DDRB,r16
ldi r16, (1 << COM0B1)|(1 << COM0A1) | (1 << WGM00)|(1 << WGM01)
ldi r16, 75
ret
EXPERIMENT 4:
a) Modify the program for different combinations of TCCR0A and TCCR0B registers as
described in the table:
TCCR0A TCCR0B
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
1 COM0A1 COM0A0 COM0B1 COM0B0 WGM01 WGM00 FOC0A FOC0B WGM02 CS02 CS01 CS00
2 1 0 1 0 1 1 0 0 1 0
3 1 0 1 0 1 1 1 0 1 0
4 1 0 1 0 0 1 0 0 1 0
https://doe.dee.hcmut.edu.vn/
LAB 2-1
USE TIMER TO GENERATE DELAY AND PULSES
b) Connect pins OC0A and OC0B to two oscilloscope channels, measure and record the
waveforms, and explain the obtained results.
EXPERIMENT 5:
a) Write a program to generate a 1 kHz square wave with a duty cycle of 25% on pin OC0B.
b) Connect to an oscilloscope and measure the output waveform.
c) Connect OC0B to the R channel of an RGB LED. Write a program to increase the duty
cycle on OC0B from 0% to 100% and then decrease it back to 0% over 10 ms, with a 1%
increment.
https://doe.dee.hcmut.edu.vn/
LAB REPORT
Group:
Class group: Subject:
EXPERIMENT 1:
EXPERIMENT 2:
EXPERIMENT 3:
EXPERIMENT 4:
https://doe.dee.hcmut.edu.vn/
LAB REPORT
Group:
Class group: Subject:
2. Capture images of the waveforms corresponding to the different working modes and
explain the results.
EXPERIMENT 5:
https://doe.dee.hcmut.edu.vn/