assigment 1 report
TRANSCRIPT
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 1/20
Abstract
Embedded system might appear less user friendly to most people but the reality is that all the
systems they think to be more user friendly are composed of one or more embedded systems.
Moreover, the use of embedded systems in the design of our daily used devices is becoming
inevitable.
The design and simulation of a serial terminal device which can be control remotely has been
illustrated in this report. Focus has been on the interfacing of peripheral devices such as
keypads, LCD and virtual terminals to a microcontroller.
1
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 2/20
1.0 Introduction
Embedded systems come in handy when a system needs to be cost effective and still delivers
its purpose of design efficiently. Thus embedded systems can be defined as computing
systems with tightly coupled hardware and software integration, which are designed to
perform a specific task [1]. Though it limits the developer’s ability to exploit the system, it
has all the components needed to perform a designated function. Embedded systems can
found in most of our daily used devices such MP3, printers, routers, and even vehicles.
Basically, embedded systems are microcontrollers or microprocessors which are quite
different from the traditional processors which serve general purpose functions. This project
will be focusing on PIC microcontroller and it interface with some peripheral devices. It will
also look expected results when the interfaced circuit is simulated using the MPLAB
software.
2.0 Problem Analysis
2
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 3/20
This project has been aimed to design a serial terminal system to control a remotely operated
4-bit pattern generator. A PIC18F4520 microcontroller will be interfaced with a Liquid
Crystal Display (LCD) and a numeric keypad. Each of the four I/O pins will be
independently controllable to provide steady state high and low or pulse signal with
separately controllable high of low periods within 1ms – 5s. The current state of the device
will be shown by a liquid Cristal Display (LCD) which will also be used as a user interface
during the adjustment of the pattern generator through a numeric keypad. The expected
results when the system is designed using a FreeRTOS running on a PIC18F4520
microcontroller will be discussed.
The serial connection can be used for debugging purposes. But since its function it not very
evident in this project, it will be rarely conversed. Figure 1.0 shows a simplified block
diagram of the device interconnectivity.
Figure 1.0: Block Diagram of Component Interconnections
3.0 Problem Solution
3
MICROCONTROLLER
LCD DISPLAY
SERIAL
CONNECTIO
KEYPAD
I/O
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 4/20
A PIC18F4520 will be used as microcontroller generating the 4-bit pattern; a LM016L will
serve as the LCD to display device status while the KEYPAD-PHONE will be the numeric
keypad for manipulating the pattern generator. The FreeRTOS will be used to write a C code
to implement the system and finally simulation and testing will be done using the MPLAB
IDE and the Proteus VSM.
3.1 Hardware Component Overview
Components needed for this project are:
• Microcontroller - PIC18F4520
• LCD - LM016L
• Numeric keypad – KEYPAD-PHONE
• Virtual terminal - Serial Port
3.1.1 Microcontroller - PIC18F4520
In general, PIC microcontrollers are very common and often used by developers because the
availability of development tools such as compilers, assemblers, debuggers and emulators.
Moreover, it is believed to come from a reliable source - Microchip Technology Corporation.
However, this project will be using a microcontroller from PIC18 family which has RISC
architecture with on-chip program ROM, data RAM, data EEPROM, timers, ADC and
USART and I/O ports.
PIC18F4520 particularly has the following advantages:
•
Economically high computational power (nanoWatt Technology)
• High endurance
• Enhanced flash program memory
• Design enhancement capability
4
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 5/20
Figure 2.0: PIC18F4520 Microcontroller
5
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 6/20
Features PIC18F4520
Operating frequency DC – 40 MHz
Program memory (bytes) 32768
Program Memory(Instructions) 16384
data memory(bytes) 1536
data EEPROM memory(bytes) 256Interupt Sources 20
I/O Ports Ports A,B,C,D,E
Timers 4
Capture/Compare/PWM Modules 1
Enhanced Capture/Compare/PWM Modules 1
Serial communications MSSP, Enhanced USART
Parallel Communications (PSP) Yes
10-bits A/D Module 13 Input Channels
Resets (and delays) POR, BOR, RESET INSTRUCTION, Stack
Underflow (PWRT,OST), MCLR (optional),
WDT
Programmable High/low-voltage detect Yes
Programmable Brown-out reset Yes
Instruction Set 75 Instructions; 83 with Extended Instruction
Set Enabled
Packages 40-Pin PDIP
44-Pin QFN
44-Pin TQFPTable 1.0: PIC18F4520 Features
3.1.2 LCD - LM016L
LCDs are becoming more popular and commonly used as user interface displays in
embedded system design because of its numerous advantages over the traditional LEDs.
These advantages include:
• Unlike LEDs it can display graphics in addition to numbers and characters
• Characters and graphics are easily programmed
• Gets cheaper by the day
• Ability to refresh on its own
6
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 7/20
LM016L comprises of 14 pins as shown in Table 2.0
Pin Symbol I/O Description
1 Vss -- Ground
2 Vcc -- +5 V power supply
3 VEE -- Power supply to
control contrast
4 RS I RS = 0 to select
command register,
RS = 1to select data
register
5 RW I R/W = 0 for write,
R/W = 1 for read
6 E I/O Enable7 DB0 I/O The 8-bit data bus
8 DB1 I/O The 8-bit data bus
9 DB2 I/O The 8-bit data bus
10 DB3 I/O The 8-bit data bus
11 DB4 I/O The 8-bit data bus
12 DB5 I/O The 8-bit data bus
13 DB6 I/O The 8-bit data bus
14 DB7 I/O The 8-bit data bus
Table 2.0: Pin position of the LCD
3.1.3 Numeric keypad – KEYPAD-PHONE
7
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 8/20
Figure 3.0: Internal structure of keypad phone
Just as briefly shown in Figure 3.0, the keypad is organised in 3X4 matrix of rows and
columns which is accessed by the microcontroller through ports. This access always involves
two processes, key detection and key identification, when programming the interfaced
keypad. The processor can implement the key detection process by using either interrupt
method or scanning method as shown in Figure 4.0.
8
No
Start
Ground all rows
Read all columns
Al
keys
ope
n?
Ground next row
Read all
Row
identified?
1
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 9/20
Figure 4.0: a flow chat of the key press detection (Interrupt method)[2]
3.1.4 Serial Port
Serial data communication transfers data using two methods, asynchronous and synchronous,
which is done one bit at a time as opposed to the parallel communication. It can be connected
to interfaces such as Ethernet, firewire, USB etc enabling the device to be operated efficiently
from a remote location.
3.2 Software Components overview
• FreeRTOS - “FreeRTOS is a small footprint, premtive, open source, real time kernel
that has been designed specifically for use on microcontroller”[3]. It is becoming very
popular now with a lot of developers switching to its use because of the following
features: pre-emptive r co-operation, flexible task priority assignment, queues, binary
9
Yes
Yes
Initialise RBIF
Wait for interrupt
RBIF
?
Wait for
debounce
Read all columns
Find which key is
pressed
Get scan code
from table
Return frominterrupt
1
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 10/20
semaphores, counting semaphores, recursive semaphores etc. But unfortunately, it has
been rarely used in this project for reasons explained later in this report.
• Protues Virtual System Modelling (VSM) – this a software that “combines mixed
mode spice circuit simulation, animated components and microprocessor models to
facilitate co- simulation of complete microcontroller based designs”[4]. It has played
a major role in the accomplishment of this project. If you can design a circuit using
this software (which is not very hard), then the physical prototype of your design will
be run through.
• MPLAB Integrated Development Environment (IDE) – “is a free, integrated toolset
for the development of embedded applications employing Microchip PIC and dsPIC
microcontrollers”[5]. This software has been used to write and compile the C program
that runs the LCD.
4.0 Problem Implementations
4.1 LM016L (LCD) Interfacing
10
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 11/20
Figure 5.0: LCD Interfacing
This LCD consists of 14 pins as show in figure 0.0 where the Vcc was used to supply +5V
and the Vss terminal was connected to the ground while the VEE was used to control the
contrast of the LCD. The RS pin was used to allow the sending of commands to the LCD
when it was set to 0 (RS = 0) and also the sending of data to be shown on the LCD when RS
is set to 1 (RS =1). Moreover, the R/W (Read/Write) pin was used to allow the reading of information from the LCD when it set to 1 (R/W = 1) and when set to 0 (R/W = 0) allows the
writing of information to LCD. T o latch information that is currently at the LCD’s data pins,
a high-low pulse was sent to the En pin. The 8-bit data pins of the LCD are basically used to
send information or read the content of the LCD. However, there are two methods of sending
either commands or data to the LCD.
• Implementing a delay before sending the next character
• Using the busy flag to Verify that the LCD is ready for the next character
4.2 Numeric keypad – KEYPAD-PHONE interfacing
11
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 12/20
Figure 6.0: Keypad Interfacing
Two methods can be employed for the key press detection of the keypad:
• Interrupt method- using the PORTB-Change, the rows are connected to the
PORTB.Low and the columns are connected to PORTB.High such that any changes
made to the pins (connected to the column) will cause an interrupt signifying a key press.
• Scanning method- the processor provides 0 to the output latch by grounding all the
rows then reads data from the columns, unless these data are not equal to 1111, a key
has not been pressed. The microcontroller continues to loop this process until a key
press is identified.
4.3 Device implementation
12
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 13/20
Figure 7.0: Device Interfacing
The circuit, as shown in Figure 7.0, was designed using Protues VSM and was supposed to be
simulated using the MPLAB IDE. The MPLAB which act as assembler, linker and simulator
is a PIC microcontroller tool provided for free by Microchip Corporation. The program was
written using a C programming language.
4.3.1 A Pseudocode on how the system program works
Displays a request, “Pls Enter Pin No.”, for the user to select an output channel on the LCD
(line 1)
Check keypad to identify key pressed
Verify that a valid key has been pressed if not keep requesting for a valid user input
Display a request, “Pls enter pulse width”, for the user to enter the pulse period of the signal
Verify that 1ms ≥ input ≤ 5s if not keep requesting for a valid period within the period range
Display the output pin number on line 1 and the pin status on line 2
Return to keypad scan
4.3.2 Additional sub program for enhanced performance
13
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 14/20
If “ * ” key is pressed, decrement the pulse width by 1ms unless it is already 1ms
If “ # “ key is pressed increment the pulse width by 1ms unless it is already 5s
Figure 8.0 shows the flow chart of the system operation
Figure 8.0: System Flow Chart
5.0 Results
When the device is powered (simulated), a user input request (“ Pls Enter Output pin “) is
displayed on the LCD indicating that the device is well interfaced. This is the only output
14
No
LCD display:
channel
Vali
d
entr
y ?
Keypress
LCD display: enter
period
Keypress
1ms ≥ delay
≤ 5s ?
1
LCD display:
enter channel
Return to
scan
keypads
1Start
Yes
No
Yes
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 15/20
produced by device since the programs for other components has not been included. Figure
9.0 shows the simulated device on ISIS.
Figure 9.0 Device in Running Mode
6.0 Discussion of Results
Ideally the status of any of the output pins is to be displayed on the LCD with respect to the
user input through the keypad. But the program to run the numeric keypad and the
microcontroller was unavailable, so only the LCD which had its program well written was
running on the device. Moreover, the fact that the LCD was able to come on and display the
required characters showed that it has been properly connected to the microcontroller.
Besides, the LCD did not display anything initially after interfacing it with microcontroller. I
had to connect a resistor to the RE3 pin of the microcontroller which acts as a reset. There
was also limited time for me to carry out some required research to improve the current
performance of the system.
However, it would have been more challenging and interesting if all the required codes for the device components was available. Though it would take more time and dedication, a more
15
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 16/20
intrinsic understanding of the device operation would have been appreciated. Nevertheless,
was happy to have designed a working embedded system.
7.0 Conclusion
The design and simulation of an embedded system device to provide a serial terminal and
remote control of a 4-bit I/O has been the aim of this project. All the required components
16
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 17/20
was able to be interfaced but only the LCD, which had its code written, was able to run fully
during simulation
On completion of the project, I realised that embedded systems, known for its limited user
interface, should be carefully designed to avoid confusion or misunderstanding to end users.
This project, though basically software has all the required ideas to produce a physical
hardware prototype.
This project can be said to be a fundamental to many embedded system design because of it
structure and application. Its application can be found in weather monitoring devices where
the user does not necessarily be in this location with the device.
References
[1] Qing, L. (2003) Real-Time Concepts for Embedded Systems. New York: Elsevier Science
& Technology.
17
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 18/20
[2] Mazidi, M. (2008) PIC Microcontroller and Embedded Systems Using Assembly and C
PIC18. New Jersey: Pearson Education, Inc.,
[3] Barry, R. Summary Information on FreeRTOS project and the FreeRTOS product family.
[Online] (http://www.freertos.org/). 2010. (Accessed Decenmber 7, 2010).
[4] Labcenter Electronics, The VSM Advantage. [Online] (URL
http://www.labcenter.com/products/vsm_overview.cfm). (Accessed December 5, 2010).
[5] Microchip, MPLAB Integrated Development Environment. [Online] (URL
http://www.microchip.com/stellent/idcplg?
IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002).
2010. (Accessed December 9, 2010).
Appendices
18
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 19/20
Appendix 1 Bill of Materials
19
8/3/2019 Assigment 1 Report
http://slidepdf.com/reader/full/assigment-1-report 20/20
Appendix 2: Programming and compilation using MPLAB
Appendix 3: Designed Circuit on Run Mode
20