[go: up one dir, main page]

0% found this document useful (0 votes)
141 views21 pages

Embedded Systems Lab01 V2

This document provides instructions for setting up an embedded systems development environment for an introductory lab. Students will install Code::Blocks IDE with an AVR toolchain to create and build projects for Atmega328p microcontrollers. The lab objectives are to 1) install Code::Blocks and WinAVR, 2) create an AVR project with correct compiler settings, and 3) test the project using AVRDUDE. This will allow students to begin developing embedded software for AVR microcontrollers.

Uploaded by

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

Embedded Systems Lab01 V2

This document provides instructions for setting up an embedded systems development environment for an introductory lab. Students will install Code::Blocks IDE with an AVR toolchain to create and build projects for Atmega328p microcontrollers. The lab objectives are to 1) install Code::Blocks and WinAVR, 2) create an AVR project with correct compiler settings, and 3) test the project using AVRDUDE. This will allow students to begin developing embedded software for AVR microcontrollers.

Uploaded by

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

NED University of Engineering & Technology

Department of Electrical Engineering

LAB MANUAL

EMBEDDED SYSTEMS
(EE-354) For T.E.(EE)

Instructor name:
Student name:
Roll # Batch:
Semester: Year:
LAB MANUAL
For the course
EMBEDDED SYSTEMS
(EE-354) For T.E.(EE)

Developed by:

Mr. Hassan-ul-Haq, Mr. Hafiz Muhammad Furqan & Ms. Aiman

Spring, 2023

Approved By

The Board of Studies of Department of Electrical Engineering

____________________ ____________________

____________________ ___________________

____________________ ____________________
EE-354 Embedded Systems

About this Lab:

In this lab, the characteristics of a series and parallel circuits, the fundamental electric circuit laws
and theorems will be learned and verified experimentally. Students will use them extensively
during the entire semester.

You will be communicated Problem Based Learning (PBL) Lab at the start of the session which
will be evaluated at the respective weeks during the session. In these labs, students will be working
in group of 3-5 students to develop, investigate and perform experiments and submit lab report
accordingly.

Lab Assessment:

Labs will be evaluated according to the decided rubrics individually and then the final score will
be calculated. The lab marking rubrics are attached with the rubric based experiments.

At the end of this lab:

After the successful completion of lab tasks, student will be able to:
● Measure Resistance and Capacitance in an electric circuit.
● Verify the equivalent forms of Ohm’s Law.
● Have command on understanding the characteristics of a series and parallel DC circuit.
● Have command on understanding different circuit analysis techniques and laws.
● Have command on understanding the characteristics of an AC circuits.
● Develop ability to think logically and verify the results of developed experiments through
Problem Based Learning labs.
EE-354 Embedded Systems

CLO assessment methods, KPIs

Course Code: EE-354

Course Title: Embedded Systems

Department: Electrical Semester:


Spring, 2023

Domain/Taxonomy Timeline for


Assessment Method KPI
level evaluation

Individual: >50%
Psychomotor Lab demonstration will be considered as At the end of every
Level 3 which will be Average lab
evaluated as per Cohort level: >=60%
decided lab rubrics will be considered as
Good
CONTENTS
Psychomotor: P3
CLO: Duplicate wiring connections for given circuit design while manipulating the embedded software with
C/Assembly IDE in order to change system behavior.
PLO: Lifelong Learning- PLO 12

S. No. Date Title of Experiment Total Marks Signature

To set-up the Code::Blocks IDE with AVR toolchain


1 and test an AVR project on the Atmega328p
microcontroller

10

11

12

* RUBRIC based assessment


Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

LAB SESSION 01

OBJECTIVE:
To set-up the Code::Blocks IDE with AVR toolchain and test an AVR project on the Atmega328p
microcontroller

LAB OUTCOMES:
By the end of the lab, you would be able to:

1) Install the Code::Blocks IDE with an AVR toolchain using (WinAVR)


2) Create an AVR project with the required compiler settings
3) Test the created project on Atmega328p microcontroller using AVRDUDE

RATIONALE / BACKGROUND:
Block diagram or flow to understand the need of each,

AVRDUDE

WinAVR (Toolchain)

Compiler and Assembler / Debugger

Atmega328p and Arduino UNO R3 Dip

LAB TASKS
The first two lab tasks guide you to installation of the required IDE and toolchain. The setup files can be
easily found and downloaded from the internet. However, these setup files are available on this shared
folder too.

TASK 1: To install Code::Blocks IDE with AVR Toolchain


Follow the given step-by-step procedure to first install the Code::Blocks IDE on your system.

1) To download the required setup files from the internet, search CodeBlocks and go to
https://www.codeblocks.org/downloads/. Select Download the binary releases. Select the setup
package depending upon your platform like Microsoft Windows in our case. From the given setup files,
select codeblocks-20.03-setup.exe as shown in Figure 1. Click on one of the Download From options
for example Sourceforge.net. For a 32-bit operating system type, you can select codeblocks-20.03-
32bit-setup.exe.
2) Once the setup file is downloaded, click on it to begin the installation process. Select the default option
and follow the installation steps as suggested by the wizard. After a few minutes of decompressing and
install files, click YES when prompted to start Code::Blocks. This should yield the IDE shown in
Figure. For now, select OK if it fails to auto-detect the compiler.

1
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

Figure 1: Download Code::Blocks


Figure 2: Select Source and File Type

Figure 3: Downlod Source


Figure 4: Starting Installation Wizard

Figure 6: Plug-in Selection


Figure 5: License Agreement

2
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

Figure 7: Destination Folder for Installation Figure 8: Installation Completion

Figure 9: Code::Blocks IDE Figure 10: Ignore Compiler Status

3) The Code::Blocks IDE is now ready and would allow you to create projects. Since our aim is to develop
AVR Projects, therefore, we first need to install AVR Toolchain. For this we will make use of WinAVR.
4) Search for WinAVR and go to https://sourceforge.net/projects/winavr/files/latest/download. Click on
Download. It will start downloading the latest WinAVR package.
5) Click on the downloaded file to start the setup wizard. Follow the steps shown in figures and select the
correct features to be installed. The WinAVR package has the required avrdude as well as GNU GCC
Compilers.

3
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

Figure 12: Run Dwonloaded Application File


Figure 11: Source to Download WinAVR

Figure 13: Setup Wizard Figure 14: License Argeement

Figure 15: Destination Folder Figure 16: Choose Components for Installation

4
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

Figure 17: Finish Installation

6) Before you create and start working on a project, verify that directories are correctly added to the system
path. To do this, open the command prompt by searching cmd in the Windows search option. In the
command prompt, simply write avrdude. You will see the message shown in Figure if it is correctly
added else you will see the error message shown in Figure.

Figure 18: Testing avrdude through Command Prompt

5
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

Figure 19: Error-avrdude is not recognized as internal command

7) After this write path to verify that the required directories shown in the figure are added to the system
path.

Figure 20: Verifying Directories Added in System Path

TASK 2: To create an AVR Project with the required compiler settings


Now you are ready to create and build an AVR project through the Code::Blocks IDE. The following steps
guide you to create the project and set the compiler settings required to build the project. Follow the steps
given below.

a) Creating AVR Project:

1) Open the Code::Blocks. Go to File> Create >Project…. Select AVR Project and click Go. Select
Next.
2) At this step, you are asked to give project title and select folder to create project files. Give any
suitable name to your project for example here, we have called it Project1. A new folder ES Labs is
created on the desktop and is chosen as project folder. After this, click Next.
3) Now, make sure the selected compiler is GNU GCC for AVR and keep the remaining settings as
shown in the figure. Then click Next.
4) The processor we have selected for ES labs is Atmega328p. Select it from the dropdown menu
carefully and keep the rest of the settings as shown in the Figure. Then click Finish
5) You will see your created project Project1 folder created in the Projects tab workspace. Click on the
Project Name > Sources. This folder will show 2 files; main.c and fuse.c, double click on the main.c
file to open it. It is a blank file template created for the AVR project. This is where you will write a
code.

6
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

Figure 21: Creating AVR Project

Figure 22: AVR Project Wizard

Figure 24: Compiler Selection


Figure 23: Project Details

7
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

Figure 26: Created Empty Project with main.c and fuse.c


Figure 25: Choosing Processor for AVR Project files

b) Compiler Settings:

Before we write instructions for our first test project, let’s first complete the required compiler settings
that will be needed for all AVR projects.

6) Now, go to Settings > Compiler.

Figure 27: Accessing Compiler Settings Option

7) Under the Selected Compiler dropdown menu, select GNU GCC Compiler for AVR and click Set
as default. From the different tabs right below this, select Toolchain executables. For Compiler’s
installation directory, click Auto detect. It should show the auto detected installation path as the one
where WinAVR destination folder was selected earlier. If it fails to do so, you can manually select the
folder by browsing through … option beside Auto-detect. Click OK.

8
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

Figure 28: Specifying the Compiler and Installation Directory in Toolchain Executables

This will update a number of things for these settings. Verify each as shown in the following figures.

Figure 29: Specifying the Program Files in the Compiler’s Installation Directory

The Program Files and Additional Paths tabs under the Toolchain executables will be updated as
shown.

Figure 30: Additional Paths in Toolchain Executables


9
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

Go to Search directories tab and check that C:WinAVR\avr\include is added in the Compiler tab.

Figure 31: Verifying the Search Directories

Select Compiler settings tab at the left-most. Check the Optimize generated code (for size) [-Os]
option.

Figure 32: Optimization Settings for Compiler

8) Click OK to close the window. The GNU GCC Compiler is set as default with the required compiler
settings needed for now.

c) Add Code and Build Project:


1) Update the main.c file opened in the Editor window with the code given in Figure and save the file
(Ctrl+S). This is a test code that causes the LED on board blink with a delay of 1000msec (1sec).

10
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

#include <avr/io.h>
#define BLINK_DELAY_MS 1000
#include <util/delay.h>
int main (void)
{
// Arduino digital pin 13 (pin 5 of PORTB) for output
DDRB |= 0B100000; // PORTB5
while(1) {
// turn LED on
PORTB |= 0B100000; // PORTB5
_delay_ms(BLINK_DELAY_MS);
// turn LED off
PORTB &= ~ 0B100000; // PORTB5
_delay_ms(BLINK_DELAY_MS);
}
}

Figure 33: Test Code - LED Blink

Figure 34: Updating main.c File with Test Code

2) Now select Build > Build. For a successful build, the Build Log below will show the following
message with 0 errors and 0 warnings.

11
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

Figure 35: Build Log (Successful Build)

3) Upon successful build, you will see some new folders and files added to the project folder. Go to bin
and verify the addition of .hex file as shown in the figure.

Figure 36: Project Folder Updated after Building the Project

Figure 37: Generated Files

Congratulations! You have generated the output file for our code written in the C language. This .hex
file is the one that will be uploaded to the flash memory of microcontroller atmega328p for execution
of the code.
12
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

TASK 3: To test the project on Atmega328p microcontroller


Arduino UNO R3 DIP uses Atmega328p microcontroller IC. Therefore, we will be using the Arduino
UNO board to program the Atmega328p.

1) Connect Arduino UNO USB cable with your system port. The LEDs on your board should light-up to
verify that connection is made. The system might start installing the required drivers. To verify the
correct connection, go to Device Manager of your system, and check Ports (COM & LPT). If the
device is detected as Arduino UNO or USB Serial Device, note the port it is connected to. Here, we
can see Arduino UNO (COM3) so COM3 is the port. In case the system fails to identify the device,
you need to install Arduino Drivers. For this download the drivers from the internet or access through
the shared drive. Extract the folder contents. Then, right click on the device under Ports in the Device
Manager, and select Update Driver Software… and follow the Wizard. You will have to specify the
path of downloaded driver files.

Figure 38: Arduino UNO R3 DIP (Atmega328p)


Figure 39: Arduino UNO Connection Port

There are 2 approaches to upload the generated code on Atmega328p flash memory. First we will
use AVRDUDE through Command Prompt instructions. Through this, you will be able to understand
the working of AVRDUDE for uploading the file to our microcontroller. Later, we will integrate this tool
to our Code::Blocks to eliminate the manual Command Prompt steps for our ease. Let’s begin the
interesting part of this lab.

a) Uploading code to Atmega328p microcontroller using AVRDUDE through Command


Prompt

1) Open the Command Prompt by typing cmd in the Windows search.


2) First change the current directory to the folder path where Project1.hex file is saved.
For example: C:\Users\Aiman\Desktop\ES Labs\Project1\bin\Debug
To do this, use cd command
cd C:\Users\Aiman\Desktop\ES Labs\Project1\bin\Debug

13
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

3) Now, type avrdude to verify that it is recognized (as has already been done). It display a list
of options available for usage with avrdude command. Read the description written with
each.
4) For now, we will use only the required ones and the details of which are given below. Note
that these are case sensitive. You can read more about it in
Table 1: avrdude Usage Options and Description

Options Description Example as applicable to the test case


-p Part No. (To specify the AVR device) In our case, it is m328p (Atmega 328p)

-P Port (To specify the Connection port) In our case, it is COM3


-c Programmer (To specify Programmer In our case, it is Arduino
Type)

-U Memory operation specification. In our case, flash is the memory type where
Required format is: we want to write the code saved in the
<memory type>:w:<file name> generated Project1.hex file
Where, w shows
read the specified file and write it to the
specified device memory
5) Based on the above, write (type, don’t copy-paste) the following command in the Command
Prompt.
avrdude –p m328p –P com3 –c arduino –U flash:w:Project1.hex
It will display some messages shown in Figure below. For successful upload of the hex file,
you will see the LED blinking at the specified rate.

Figure 40: Uploading the .hex File to Atmega328p through Command Prompt avrdude
14
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

b) Uploading code to Atmega328p microcontroller using Code::Blocks tool

To avoid the time-consuming and intimidating Command Prompt interface, we will now add the
AVRDUDE tool to Code::Blocks. Follow the following steps:

1) In your Code:Blocks IDE, click on Tools > Configure Tools > Add. In the Edit Tool
window, set the Name, Executable, Parameters and Working Directory as shown in Figure.
To set the executable browse the specified path of WinAVR folder, and select avrdude.exe.
Note, that in the parameters option, we have written the same avrdude command used earlier.
The working directory is set to be the one containing the .hex file. Click OK and close the
Tools Window.

Figure 41: Required Tool Settings

Figure 42: Added Tool avrdude

2) Now, select Tools from the top menu bar once again. The name of tool just added for
example: avrdude will be available now above the Configure Tools option. Click the
avrdude and that’s it. The Log Window below will show the execution. Once the code is
uploaded to Atmega328p, you will observe the blinking LED.

15
Embedded Systems Lab Lab 01 Setting-up the Code::Blocks IDE with AVR Toolchain
NED University of Engineering & Technology Electrical Engineering Department

3) To make it more generalized, we will now add a tool using macros. Here, instead of
specifying the exact file and project names and path, we will use macros that will do the
job and you won’t have to type it again and again for each of your projects.
4) Go to Tools> Configure Tools. Either Edit the previous tool or use Add to add another
one. This time set the Parameters and Working Directory in terms of macros replacing
project name and path. Click OK.

Figure 43:Adding avrdude with Generic Parameters and Working Directory

5) Now, modify the delay in your main.c file by replacing 1000 to 5000 for 5sec delay. Save it and
Rebuild the file using the Build> Rebuild option. The new file will replace the previously generated
.hex file.
6) Now, upload this one by selecting the newly added Tool through Tools>avrdudedirect. Verify the
successful upload by blinking of LED at 5msec delays.

Congratulations! You have successfully created, built and tested your first AVR project on
Atmega328p using Code::Blocks with AVR Toolchain.

16

You might also like