Homework 9: Software Design Considerations

quarterceladonMobile - Wireless

Dec 10, 2013 (4 years and 7 months ago)


ECE 477

Digital Systems Senior Design Project

Rev 8/09

Software Design Considerations

Team Code Name: _____
___________________ Group No. __

Team Member Completing This Homework: ___

mail Address of Team Member:
@ purdue.edu






among the best papers submitted for this assignment. Very few
corrections needed for version submitted in Final Report.


Very good

all requirements aptly met. Minor additions/corrections needed for
version submitted in Final R



all requirements considered and addressed. Several noteworthy
additions/corrections needed for version submitted in Final Report.



all requirements basically met, but some revisions in content should
be made for the version su
bmitted in the Final Report.



all requirements met at a nominal level. Significant revisions in
content should be made for the version submitted in the Final Report.


Below the passing threshold

major revisions required to meet report
uirements at a nominal level.
Revise and resubmit.

Resubmissions are due within
one week

of the date of return, and will be awarded a score of
“6” provided all report requirements have been met at a nominal level.


Comments from the grader w
ill be inserted here.

ECE 477

Digital Systems Senior Design Project

Rev 8/09




The future register is a register that will eliminate the use

of paper during a transaction

the use of the NFC by the NXP PN532
. There are 3 parts to the project, the Atom
board, microcontroller and
the test
er module
The Atom board shall handle all its peripherals
through a class structure written in C#. The tester module shall be written through the android
SDK supplied by
, and shall interface with the onboard NFC on the device. The tester
module sha
ll be sending credit card credentials through its NFC antenna to the PN532 attached
to our microcontroller, the dsPIC30F5011
It will also

be able to
receive receipts

through the
SPI peripheral
. Attached to the


an infrared sensor to determine

the presence of a
customer. This shall be interfaced through the microcontroller’s ATD port. There will be an LCD
interfaced with the microcontroller through general purpose pins. This will be used to prompt the
user when and where to place their NFC devi
The overall microcontroller is organized in a
flag driven fashion designed in embedded C.


Software Design Considerations

The main control station of our project is the dsPIC30F. This micro controls most of our
functionality that deals with interfacin
g with all the important aspects of our project. The
dsPIC30 interfaces with the Atom, PN532, Long range IR Sensor, and the LCD.

The LCD will be interfaced through
the PORTD pins on the dsPIC30F, RD0 to RD10.
initialize the LCD several specific sets of

instructions need to occur. The first part of initializing
is turning on the LCD and waiting for a minimum of 15ms. This is to make sure the internal
initializations are done completely.

Through the entire process of initialization, RD0 and RD2
will stay
at 0 to ensure instructions are written to the
internal registers.

Following the internal
initialization, RD7 and RD8 have to be logic 1 for at least 4.1ms, after the enable signal has been
RD7 and RD8 shall remain logic 1 for another at least 100

us after another enable signal
strobe. Finally to use the 8
Bit interface, you strobe this command once more and wait until the
busy flag isn’t 1, RD10. After initializing the LCD to 8
Bit mode, the remaining configurations
can be taken place. First
set b

RD6 and RD5 to set a 2 line 5x10 LCD. Then turn the display

by de
asserting other RD pins and asserting RD

and strobing RD1 (enable pin). Wait for
LCD to not be busy, then de
assert all pins and set RD3 then strobe RD1 to clear the display.
Wait fo
r the LCD to not be busy then de
assert all pins and set RD5 and RD4 and strobe RD1 to
set the address to increment and not shift the screen. Finally, to set the cursor and blinking mode,
ECE 477

Digital Systems Senior Design Project

Rev 8/09


wait for LCD to not be busy, then clear RD pins and set RD3, RD4, RD
5, and RD6, this will turn
the cursor on and blinking. After this, initialization is complete.
During initialization, the
PORTD pins are set to output in order to send the correct bits to the LCD to choose the correct
mode and achieve proper initialization
. However, these pins are switched from inputs to outputs
throughout the course of interfacing with the LCD. The method of changing the direction is
governed by the TRISD registers. To make the pins output you need to set each bit in the register
to 0 or 1

for input. Data can be retrieved from these pins through the PORTD registers, and can
be written through the LATD register, through these registers the LCD can be sent bytes to be

The IR Sensor will be interfaced through the ATD peripheral onbo
ard the dsPIC30F. It
will be using the port RB1/AN1/CN3/VR
, pin 15.

The ATD initialization is quite a daunting
process. To configure the ATD for the IR Sensor, we will first select the AN1 pin to be used as
an analog input by making ADPCFG = FD. Next we s
elect where the voltage reference will be
taken from through ADCON
<15:13> being 000. Then the conversion clock is selected to be
32*TCY by ADCON3<5:0> being 111111. Since this conversion isn’t too complex we can
simply select CH0 for AN1 by de
asserting A
DCON2<9:8>. Next we pick the channels to be
sampled individually and as an input scan. We also need to select a positive input through AN1
at CH0 through ADCHS being 1. An appropriate conversion trigger source is the internal
counter, and control of when
sampling should start is in our control. For this we need to make
ADCON1<7:0> = E0. And seeing as we want to sample at a quite slower rate, a 31*TAD is
chose for samplin
g which is ADCON3<12:8> = 11111. We want the conversion to be unsigned
integers to simp
lify calculation of the distance, ADCON1<9:8> = 00.
After every 2

and sample we want to have an interrupt. Finally we turn on the ATD module through
ADCON1<15> = 1. If need be further configuration of the ATD interrupt could be attained.
t the ATD sample, read the value at ADCBUF0.

The PN532 will be interfaced through the SPI interface and 2 GPIO pins on the
dsPIC30F. The 2 GPIO pins are the RC1 and RC2 pins. These pins are meant to select the host
interface for the NFC chip. Since the N
FC chip can be configured to interface through several
ways (UART, SPI,
and I2C
). These pins will select the
01) mode. These pins shall be
configured through TRISC = 0 for output. Then LATC = 4 will output “01” on those lines. The
next step is to init
ialize the SPI interface to communicate with the PN532.
The PN532 will be
ECE 477

Digital Systems Senior Design Project

Rev 8/09


utilizing 4 pins from the dsPIC30F, the SCK2, SDI2, SDO2, and SS2.
The SPI interface consists
of 4 pins, Serial Data Input, Serial Data Output, Shift Clock Input or Output (based on
mode) and
Slave Select.
To interface with the PN532 we will be using the dsPIC30F in master mode. To
accomplish this we need to assert SPI1CON<5> to enable master mode. Next we clear the
overflow flag to restart the operation. Next we set the primary presc
aler for the SPI clock to 1:1
and the secondary prescaler to 2:1, seeing as we running at 7.37
, this should effectively
lower the SPI clock speed to
3.685 MHz
, well under PN532’s Max SPI rate of
5 MHz
Next we
enable the SPI operation by setting the SP
IEND bit (SPI1STAT<15>).

The Atom communication shall be accomplished through the use of a MAX3232 chip to
step up voltage from the 5V being supplied. This chip also utilizes the UART peripheral on the
The MAX3232 is connected to pin 31 and pin

32, U2RX and U2TX respectively.

The baud rate of 9600 shall be accomplished by setting the U2BRG register to 47. This will
effectively create a baud rate of 9596.4, which is a 0.03% error.
The UART setting we shall aim
for is 8
bit data, no parity, and 1

stop bit. To achieve this, we will set U2MODE<2:0> to 000.
Then the UART will be enabled through U2EN (U2STA<10>). This process will initialize the
UART for both transmitting and receiving. To send load bytes into U2TXREG until U2STA<9>
is set. To receive
, poll
U2STA<0> till its set. If

set, there is a word in the buffer that
can be


The main function shall be flag driven or polled. The flow of the program can be broken
up into stages, which allows polling to be more favorable. We continue to p
oll the ATD until it
meets our threshold. Then we transmit through UART and poll the UART receive buffer until we
receive a message, check the message then send to LCD and poll SPI until it receives
information. Transmit through UART and poll UART receive
buffer until we receive another
message. Then send to LCD and send through SPI to PN532. This is our basic flow which
greatly favors polling, if there were interrupts, when we aren’t expecting

information, the
program could be interrupted, slowing the oper
ation as a whole.

Currently our code will be located in the flash memory which boasts
K. The
instructions we shall be running are not computational intensive or exceedingly large.
K is
large enough to contain all sufficient code. Temporary storage of

local variables, heap, and stack
shall reside in the SRAM. A temporary storage of the credit card information and the information
to recreate the receipt on the NFC device shall also be stored in the SRAM.

ECE 477

Digital Systems Senior Design Project

Rev 8/09


dsPIC30F5011 Memory Map






SPI on our dsPIC30F. With this method we can debug all 11 signals that
go to the LCD instead of just 8.

To debug other aspects of our project, simple print statements to
the LCD screen will be used. This will give us a visual look at what exactly is go
ing on, and
makes it easier to debug because it mimics print statements which we are all used to.
debugging methods are not finalized.

ECE 477

Digital Systems Senior Design Project

Rev 8/09



Software Design Narrative

The project consists of 3 main software areas, the Atom board, the dsPIC30F, and the
Tester application. The tester application is a simple send and receive

through NFC

built on
Android SDK.

The software on the atom board will be a Windows 7 application, developed in C#. The
application will be comprised of 6 modules. These m
odules are the GUI, class hierarchy, speech
recognition, serial port communication, security and cryptography, and database backup. The
GUI is where the cashier or manager will process the order and manage the inventory of the
restaurant via the touch scre
en. Because Windows development is fairly new to the entire group,
the GUI is still in the research and design phase. The class hierarchy will make up the
infrastructure of the application. Here, there will be classes such as menuItem and comboItem
that wi
ll build up into one main class called restaurant. The restaurant class will contain the
inventory of the restaurant along with information about the restaurant plus the administrative
password used for encrypting and changing settings. The class hierarchy

has been completed and
is ready for implementation. The speech recognition module will take the voice input from the
customer and convert it to text. This module will be developed using the


in the .NET 4.0 framework
. This namespace used the
Windows voice recognition software. Due to the complexity of the namespace, this module is
still being researched. The serial port module will be used by the GUI to send and receive
payment and

information to the microcont
roller. This will be accomplished using
serialPort class in the System.IO.Ports

, which is also in the .NET 4.0 framework.
This module is in the
pseudo code

stage. The next module, security, will serve the purpose of
encrypting payment informa
tion before it is stored onto the hard drive. The security module will
use the System.Security.Cryptography


in order to encrypt the data using AES.
This module has not yet been started, but it has a fairly simple implementation. The final mod
is the database backup module. In order to avoid storing a large number of credit cards on a local
disk, the application will be able to dump its payment information onto a secure database. The
database will be created on Microsoft SQL Server, and the
communication will be handled using
LINQ in the .NET 4.0 framework.

The dsPIC30F hierarchical arrangement is a polling type structure that will involve 6
different modules, 4 of which will be manually coded and 2 which are provided b
y the MPLAB.
ECE 477

Digital Systems Senior Design Project

Rev 8/09


There wil
l be a main controller which abides over all 6 modules and directs where the flow of the
program is and where it should be going.
The main controller will be connected to the ATD
module, UART module, LCD module, SPI module, p30F5011 module, and libpic30 mo
dule. The
main controller will


through the general flow of the program as outlined in
Appendix B
main controller’s purpose is to oversee the general flow of the program is in order, and to bring
each modularized segment together into one big progra
To check the ATD threshold a .25s
delay shall be implemented before each check of the ATD buffer.
The main controller is also in
charge of making sure the data received is correct in order to continue through the flow of the
program. For example, making

sure the signal received from the UART is the “GO” signal in
order to continue to writing to the LCD. The main controller shall be implemented through a
series of while loops. This is because the flow could be broken up into stages. The flow can’t

until a certain requirement has been met. With the while loops, you can be assured the
required conditions have been met before continuing.
The main program in progress but very
little progress has been made. Status: Not Done

The 2


provided by MP
LAB are the p30f5011.h and libpic30.h.

simplifies accessing all the ports and registers. They give each register a name instead addressing
them by their hexadecimal digit, a simple and easy to remember name is in place. I
ndividual bits
can also
be accessed individually through this module. The libpic30.h module makes it easy to
implement delays, mainly for LCD interfacing and the IR sensor threshold.
Since these 2
modules are given by MPLAB, the status is completed, and it just needs to be integr
ated into the
main program.

The LCD module

is the main interface with the LCD. It contains all the functions that
will be

able to communicate with the LCD and all its initializations. The LCD module is there to
add a layer of abstraction to interfacing w
ith the LCD display itself. It provides useful functions
such as putc, gotoxy, init, cursor on, and other such functions. This will simplify the main
controller’s code exponentially.
The LCD module works by
utilizing GPIO pins to communicate
with the LCD.
The initialization module will initialize the LCD accordingly as described in
Section 2.0. There is gotoxy function, which will move the cursor to the position specified by the
input parameters. There is a putc function, which will be able to write a strin
g specified through
the input arguments to the LCD, this function heavy relies on send_byte. The send_byte function
is a corner stone to interfacing with the LCD. The send_byte function is responsible for sending
ECE 477

Digital Systems Senior Design Project

Rev 8/09


raw data directly to the LCD by putting the

address on the proper data line, strobing the enable
signal and waiting for the appropriate time needed. Another important function is the

function. This is the opposite of send_byte and it’s mostly used to check the busy signal and
know when to

The LCD module is 75% done. It contains almost all necessary functions
and more. It is a complete rewrite of the

functions supplied by MPLAB.

Status: In
progress [

The ATD module is the interface with the IR sensor. It contains

all the func
tions that will
be needed to accomplish customer detection. Its main purpose is to return information of the
current ATD sample in order for the main function to determine the presence of a customer. This
module will contain 2 functions, init and cur_sampl
e. The
init (
) function is the initialization of
the ATD in order to perform a 1 channel conversion on AN1. This initialization has been
outlined extensively in Section 2.0. The cur_
sample (
) function will be a simple function that
will return the value of

ADCBUF0. With this value the threshold can be compared to the current
sample. Coding for this module has not begun. Status: Not started
, but it has been outlined, and
research has been conducted.

The UART module is the interface with the COM port and MA
X3232. It contains all
functions needed to communicate with the Atom board. The purpose of this module is to ease the
communication with the COM port and allow for an easier interface to send and receive
information. This module will contain
3 functions in

order to interface with the COM port.
Init (
will initialize the UART to a baud rate of 9600 and all other configurations outlined in Section
Send (
str) will send a string through the UART. It will loop through the string while
monitoring the TXBUF
to make sure there isn’t an overrun and keep filling
the buffer

as it
becomes available until there are no more characters to be sent. The
Receive (
) function will
receive a string through the UART. It will continue to receive through the UART until a
inator character is received. The function will then return the string accumulated by the
Receive function.
Coding for this module has

not begun. Status: Not Started, but it has been
outlined, and research has been conducted.

The SPI module is the interf
ace with the PN532. It contains all functions needed to
communicate with the PN532 NFC controller chip. The purpose of this module is to simplify
communication through SPI by only bottlenecking it into 4 lines.
It is also our only
communication with the PN
532 FIFO manager. With the SPI with can communicate with the
ECE 477

Digital Systems Senior Design Project

Rev 8/09


FIFO manager, read data, write data, and c
onfigure the SPI communication. The SPI module will
contain functions to initialize and because SPI transmits and receive in one operation there will
o be a transmit_
receive (

function. The SPI module will initialize to master mode and all
other configurations outlined in Section 2.0. It will also use
RC1 &

RC2 to select the SPI mode
for PN532. In the transmit_recieve
read (
) function
, it

will accep
t an address to send, and
return the data
in the SPI2
This function will be used to monitor the FIFO status,
and also read information once the FIFO has been filled.
Another variation will be the
write (str, str
). This functio
n will accept both an address and a string to send

through the SPI and it won’t return.
This function is used only to write data to the FIFO manager
on the PN532.



Future Register project aims to rid the transaction process of paper, both cash
receipts. The project is comprised of 3 parts, an atom board, a touch screen, and the payment
package. The Atom board is coded in C# and comprised of 6 modules, GUI, Speech, Menu,
Serial, Cryptography, and Database backup. The project also utilizes a d
microcontroller which is coded in embedded C. The project utilizes the ATD, SPI, UART, and
several GPIO to completely interface with an IR sensor, NFC Controller, Max3232, and a

ECE 477

Digital Systems Senior Design Project

Rev 8/09


List of References


BallSoHard. “LCD.C”, [Online], Availabl

[Accessed March 21, 2012]


BallSoHard. “PN532

LONG DATA SHEET”, [Online], Available:
. [Accessed March 21, 2012]


Microchip Technology. “dsPIC30F Family Reference Manual”, [Online]
, Available:


. [Accessed March 21, 2012]


MSDN, “System.Speech.Recognition Namespace ()”, [Online], Available

. [Accessed March
21, 2012]


MSDN, “System.Security.Cryptography Namespace”, [Online], Availble:

. [Accessed March 21, 2012]


MSDN. “SerialPort Class (System.IO.Ports)”, [Online], Available:
. [Accessed March
21, 2012]

ECE 477

Digital Systems Senior Design Project

Rev 8/09


Appendix A: Flowchart/Pseudo
code for Main Program

ECE 477

Digital Systems Senior Design Project

Rev 8/09


: H
ierarchical Block Diagram of Code Organization