0% found this document useful (0 votes)
24 views

Group 408 Short Report Microprocessor (Digital I.O and Timer)

The document describes an experiment using the input/output and timer functions of an ATmega32 microprocessor. It includes: 1) Objectives to initialize I/O ports, calculate delays using the timer, and simulate outputs using AVR IDE Simulator. 2) Equipment used including an ATmega32 development board, debugger, and software. 3) Procedures that initialize I/O ports, program the microprocessor, write a delay function using Timer 0, and implement a program to control LED patterns from button presses. 4) Results showing the LED patterns generated from different button presses as programmed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Group 408 Short Report Microprocessor (Digital I.O and Timer)

The document describes an experiment using the input/output and timer functions of an ATmega32 microprocessor. It includes: 1) Objectives to initialize I/O ports, calculate delays using the timer, and simulate outputs using AVR IDE Simulator. 2) Equipment used including an ATmega32 development board, debugger, and software. 3) Procedures that initialize I/O ports, program the microprocessor, write a delay function using Timer 0, and implement a program to control LED patterns from button presses. 4) Results showing the LED patterns generated from different button presses as programmed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

FACULTY OF ENGINEEERING

SCHOOL OF ELECTRICAL ENGINEERING

SEEE3732-04
SESSION 2022/2023-1
SHORT REPORT
MICROPROCESSOR
DIGITAL INPUT/OUTPUT AND TIMER ON ATMEGA32

Group: 408

Group members:
No Name No. Matric
.
1. Alexander Wong Heng Yii A20EE0009
2. Fong Jun Xian A20EE0053
3. Mohammed A.M. Abujarad A19EE4071
4. Teo Jun Long A20EE0215
Date:

Title:

Using Input/Output, Timer on AVR IDE Simulator

Objectives:

1. To initialize input/output port.


2. To calculate and programming delay using Timer.
3. To simulate the outputs of firmware using AVR IDE Simulator.
4. To add additional code to upgrade the operation of firmware.

Equipment/Software/Reference:

1. A computer system running either Window 8 or Window 10


2. Atmel Studio 6 is installed on the system.
3. AVR JTAGICE mkll Debugger.
4. Gotronik ATmega32A Target Board.
5. Reference 1 - Appendix C For SKEE3732 Laboratory 1 Sheet.pdf
6. Reference 2 - Appendix A For SKEE3732 Laboratory 2 Sheet.pdf
7. Referebce 3 - Atmega32 Reference manual.pdf
8. Reference 4 - Embedded C Programming and the Atmel AVR, Second Edition.pdf
9. Reference 5 – AVR libc function reference.pdf
Procedures:

1. The project created during pre-lab session was opened.


The project named “Lab2Exp1” which had created as instructed in section 1 of
“Preliminary Report” was opened by double clicking “Lab2Exp1.atsln” in the
“Lab2Exp1” directory.

2. Atmel Studio Project “Lab2Exp1” was connected to an ATmega32A target


board via a JTAGICE mkII debugger (Software connection of current project in
Atmel Studio to the JTAGICE MkII).
The ATmega32A target board was connected as shown in the Figure 1.1 below.

(a) Project ‘Lab2Exp1’ was connected to the JTAGICE mkll and Target board.
(b) ‘Selected Debugger/programmer’ was selected as JTAGICE mkll and the Interface
was JTAG.
(c) The CPU frequency was ensured to be 1MHz.

3. ‘Lab2Exp1’ project was programmed to ATmega32A chip.


(a) Referring to A.9(e) of ‘Appendix A For SKEE3732 Laboratory 2 Sheet.pdf’,
ATmega32A chip after successfully compiling the project ‘Lab2Exp1’.
(b) Result was reported as required In Table 1(a).
4. A program was written to generate delay.
By using Timer 0 and normal mode, TCNT value was calculated to generate 200ms
delay. The calculation was shown clearly and the ‘Delay200msUsingTimer0’ function
was written.
5. The Complete Function of ‘Lab2Exp1.c’ was implemented as required in Table
2.
The program was modified such that the program will execute the pattern sequence as
specified in Table 2 for command if SW2 and SW3 was pressed respectively. The
program was run after modification and an endorsement was obtained in Figure 3
from the supervising lecturer after showing the working program.

Results:
Figure 1.2: Connection of ATmega32A Target Board

For Procedure 1-3:

Table 1.1: Result to be taken in Procedure 3

Input Describe Display at Seven Describe Pattern generated at


Segment Panel LED Panel
No Push Button
pressed

1) The 7segmant display show “S”

2) The 7segmant display show “K”

3) The 7segment display show “E”


As shown in the circuit above, it As shown in the circuit above,
the seves segment panel only There are no leds that blink
show ske with delay 1s between when there are no push button
each letter. is pressed
SW0 pressed & hold
As shown in the circuit above, As shown in the circuit above,
the seven segment panel stop to leds 0 is been light up while
show anything. other leds is still off
SW1 pressed & hold
As shown in the circuit above, As shown in the circuit above,
the seven segment panel stop to leds from 0 to 3 is been light
show anything. up while other leds is still off
SW2 pressed & hold Still there are no function for this pushbutton
SW3 pressed & hold Still there are no function for this pushbutton

For Procedure 4:

200ms Delay calculations using Timer 0:

As shown in APENDEX A, The speed of counting can be controlled by varying the


speed of clock input to it. In ATmega32 we have three different kinds of timers as
follows

Timer 0 8 bit counter Can count up to 255 = MAX

Timer 1 16 bit counter Can count up to 65,535 = MAX

Timer 2 8 bit counter Can count up to 255 = MAX

So can use 8 bit, max 255 for timer0, And to chouse suitable prescalar we use this
table and this law :

Required Delay = 200ms; XTAL frequency = 1MHz


1 Prescaler
Clock Time Period = ¿
f XTAL freqency

Prescale Clock Time Timer Count For 8bit timers (Timer 0 & Timer 2)
r Period (Hz)
1 1 1999999 Not Suitable because Timer Count >
1000000 255
8 8 24999 Not Suitable because Timer Count >
1000000 255
64 64 3124 Not Suitable because Timer Count >
1000000 255
256 256 780.25 Not Suitable because Timer Count >
1000000 255
1024 1024 194.3215 Suitable, Timer Count < 255
1000000

By calculation

Timer clock(Hz) = 1M/1024 = 976.563Hz

Clock Time Period=1/976.563Hz=1.024 ms

Timer count = (200ms/1.024ms) -1

=194.3125

Time count = 194

TCNT0 =255-194

“Delay200msUsingTimer0” Function coding:


For Procedure 5:
Table 2: Result to be taken in Procedure 5

Switch LEDs panel display requirement when respective button is selected Remarks
Pressed

No Time delay
switches for each
pressed blinking is
800ms

The word ‘SKEE3732-408’ was shown in 7-Segment LED Displays Panel


consecutively and every alphabet or number held for 800ms. There was no PORTA
LED ON since the PORTA = 0 in the code.
SW2 Time delay
for each
blinking is
400ms

#State 0 #State 1
There was nothing shown on the 7-segment display since PORTA = 0 in the code.
The Pattern 1 was successfully displayed on LEDs indicated by PORTD which
$33 = 0b00110011 displayed at the first 400ms, then $CC= 0b11001100 displayed at
the next 400ms.
SW3 Time delay
for each
blinking is
400ms

#State 0 #State 1 #State 2 #State 3

#State 4 #State 5 #State 6


There was nothing shown on the 7-segment display since PORTA = 0 in the code.
The Pattern 2 was successfully to be displayed on LED indicated by PORTA which
$E7 = 0b11100111 displayed at the first 400ms, then $DB = 0b11011011 displayed
at the next 400ms, $BD = 0b10111101, $7E = 0b01111110 and reversed back from
$BD to $E7 with time delay 400ms for each changing.
7.0 Discussion

Based on the preliminary exercise, Port D is initialised as an input port and $00 is loaded,
which implies all '0's in 8-bit binary in DDRD, making PORT1 a high-active pushbutton that,
when pressed, would send a 0 signal to ATMEGA32. Port A and Port B are initialised as
output ports and $FF is loaded, which signifies all '1's in 8-bit binary in both DDRB and
DDRA, and don't forget that all 7-segment and leds are high active, which means that when
the output is 0, they will be on and when it is 1, they will be off. Therefore, PIND is used as
the switch-like input pin register. The PD0-PD7 Circuit was toggled for the experiment.

In Procedure III, we utilised the code written in the preceding exercise to demonstrate the
outcome. According to Table 1, when no push button is touched, PIND is loaded with the
value 0b1111111 and PORTB is loaded with the values $92, $89, and $86, which correspond
to the letters 'S', 'K', and 'E' displayed on the 7-Segment LED Displays Panel. Since PORTA
is also loaded with $FF = 0b1111111, none of the LEDs on the 8xLED Board will illuminate.

For the situation where SW0 is pressed, the PD0 switch at Circuit is pressed and the PIND
variable is loaded with 0b11111110, as shown in the code. Since PORTD is loaded with $FE
= 0b11111110, the first LED of PORTA, PORTA[0], will light up and blink since $FE =
0b11111110 is assigned to PORTD. The 7-Segment LED Displays Panel connected to
PORTB will not display anything due to the absence of coding for PORTB in this
circumstance.

For the situation where SW1 is pressed, the PD1 switch in our circuit is pressed and the value
0b11111101 is loaded into PIND. Since PORTC is loaded with $0F = 0b11110000, the first
four LEDs of PORTA, namely PORTA[0], PORTC[1], PORTC[2], and PORTC[3, are on
and blinking. Similar to when SW0 is pressed, the 7-Segment LED Displays Panel connected
to PORTB will not display anything in this state, as there is no coding for PORTB.

Since there is a "else" in the coding, the 7-Segment LED Displays Panel and 8xLED Board
both gave the identical result for the scenario where SW2 and SW3 are pressed individually.
However, PIND is loaded with 0b11111011 and 0b11110111 since the pressed switches in
the Circuit are PD2 and PD3.

In process IV, the issue is posed to add a new function for a 200ms delay using timer0, thus
we begin by attempting to obtain the time count using the following law:
Then, we obtain 194 as the time count and write code in the manner shown in appendix A to
obtain the code displayed above. Therefore, the Delay200msUsingTimer0 function is
calculated and programmed. Due to the fact that the specified time delay is 200ms and the
system clock is 1MHz, we chose 1024 as the prescaler, as demonstrated by the Procedure IV
calculation result. After performing the computation, we chose the value 61 (255-194) for
TCNT0, which was then programmed into the code. To set the prescaler value, the code was
written as TCCR0 = (1<<CS02) | (1<<CS00). This portion utilises a while loop. The
following code is coded to wait until the TOV0 bit is set, which indicates overflow while
TCNT0 continues to count in the background. The TOV0 bit is cleared by writing 1 to it
when it is set. TIFR = TIFR | TIFR data is used to clear the TOV0 bit once more to ensure
that it is cleared.

In procedure V, the programme code is altered to produce Table 2's output. After the changed
software is put into the circuit, the 7-Segment LED Displays Panel will display SKEE3732-
408 in a sequence with a time interval of 800ms. This means that the letter 'S' will be
displayed first, followed by the letter 'K,' and so on until the entire string is displayed. This
procedure will repeat indefinitely until a switch is toggled or the power is cut to the circuit.

When PIND2 (switch 2) is toggled, the LEDs on the 8xLED Board will illuminate according
to pattern 1 as specified by the circuit. The first state containing LED2, LED3, LED6, and
LED7 will illuminate, as indicated by the code "PORTC = 0x33." The LED0, LED1, LED4,
and LED5 will then illuminate in the second state, as indicated by the code "PORTC =
0xCC." Each state has a 400ms time interval. This procedure will repeat indefinitely until a
switch is toggled or the power is cut to the circuit.

When PIND3 (switch 3) is toggled, the LED on the 8xLED Board will illuminate as
described in the labsheet (pattern 2). After the switch is toggled and turned on, LED3 and
LED4 will illuminate in the initial condition. The second state including LED2 and LED5
will illuminate next, followed by the third state containing LED1 and LED6, the fourth state
containing LED0 and LED7, the fifth state containing LED6 and LED1, the sixth state
containing LED5 and LED2, and the seventh state containing LED3 and LED4. Similar to the
preceding procedure, each state has a 400ms time period. This procedure will repeat
indefinitely until a switch is toggled or the power is cut to the circuit.

8.0 Conclusion

In summary, we have learned how to initialise the input and output ports and how to
programme a 7-Segment LED Displays Panel to display an alphabet, number, or symbol
before assembling it into a working circuit. The programming to create a time delay in Atmel
Studio comes last. We have gained more knowledge about the Atmega32 timer and digital
input/output through this project. Since we were able to collect all of the results, we can draw
the conclusion that the experiment's stated goals were met. When no push button is hit, we
were able to display the letters "S," "K," and "E" on the 7-Segment LED Displays Panel in
Procedure III. While the first LED of PORTA is on and blinking for the state of SW0. The
first four LEDs of PORTA are on and blinking for SW1 condition. We were able to write
coding in Procedure IV to produce a 200ms time delay after the calculation, allowing it to
function smoothly and precisely in this experiment. When no push button was used, we were
able to adjust the coding in Procedure V and have our group code, "SKEE3732-420," shown
at the 7-Segment LED Displays Panel. When SW2 was present, the LEDs lit up in the pattern
1 pattern displayed on the labsheet, while SW3 was present, the pattern 2 pattern showed on
the labsheet.

You might also like