Homework 9: Software Design Considerations

quarterceladonΚινητά – Ασύρματες Τεχνολογίες

10 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

148 εμφανίσεις

ECE 477

Digital Systems Senior Design Project

Rev 8/09


Homework
9
:
Software Design Considerations




Team Code Name: _____
FUTURE REGISTER
___________________ Group No. __
14
__

Team Member Completing This Homework: ___
SAMUEL OSHIN
_
_______

E
-
mail Address of Team Member:
soshin
@ purdue.edu


Evaluation:


SCORE

DE
SCRIPTION

10

Excellent



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

9

Very good



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

8

Good



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

7

Average



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

6

Marginal



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
req
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:

Comments from the grader w
ill be inserted here.


ECE 477

Digital Systems Senior Design Project

Rev 8/09


-
1
-

1.0

Introduction


The future register is a register that will eliminate the use

of paper during a transaction
through

the use of the NFC by the NXP PN532
[2]
. 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
Google
, 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
[3]
.
It will also

be able to
receive receipts

through the
SPI peripheral
. Attached to the
dsPIC30

is

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
ce.
The overall microcontroller is organized in a
flag driven fashion designed in embedded C.

2.0

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.
To
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
strobed.
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
oth

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

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


-
2
-

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
written.


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
2
<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
nd

conversion
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.
To
ge
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
SPI (
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


-
3
-

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
MHz
, 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
dsPIC30F.
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
it’s

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

read.


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
22
K. The
instructions we shall be running are not computational intensive or exceedingly large.
22
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


-
4
-

dsPIC30F5011 Memory Map

000000h

Reset

=
䝏呏⁩湳
瑲畣瑩on
=
〰〰〲M
=
oe獥琠

=
呡rge琠
䅤A牥獳
=
〰〰〴M
=
〰〰㝅M
=
f湴n牲異琠噥c瑯爠呡扬e
=
〰〰㠰M
=
oe獥牶rd
=
〰〰㠴M
=
〰〰M䕨
=
䅬瑥A湡瑥⁖ec瑯爠ta扬b
=
〰〱〰M
=
〰䅆c䕨
=
啳r爠rla獨⁐牯杲a洠䵥浯my
=
⠲㉋⁩湳=牵r瑩潮猩
=
〰M〰と
=
㝆c_c䕨
=
oe獥牶rd
=
㝆cC〰M
=
㝆cccch
=
䑡瑡⁅䕐o位
=
⠱⁋byteF
=
=
=
c潲⁤o扵杧楮g⁰畲=潳e猬s睥⁨=癥=ex瑲t⁰楮⁨敡摥r猠s瑴ac桥搠瑯畲⁐C_⁦=r⁤=扵杧楮g=
a湤瑨敲⁩獳略猠瑨慴ay⁡物獥⸠周.se⁰楮猠睩汬⁢=⁵獥搠瑯潮楴潲⁳楧湡汳⁴桲潵h栠e楴桥爠楴猠rmf=
晵湣瑩潮o汩ty爠=a獩挠smfl⁦畮=瑩潮o汩ty⸠周.re⁡牥⁳=癥牡l
=
睡y猠瑨a琠摥扵杧楮g⁣a渠潣cu爮⁗楴栠
瑨t猠浥瑨潤⁡⁨潯欠異⁴漠愠汯=楣ia湡lyze爠r潵汤⁢e⁩摥=氠l漠o桥c欠瑨攠獩g湡氠le癥汳⁡湤⁷桡琠
exac瑬y⁩猠潣=u牲楮g.
=
䄠Ae扵b潤e⁷潵汤⁢==
c牥a瑥搠t桩捨⁷楬氠敮l扬e⁡l氠摥扵杧楮g⁦ea瑵tes

扵琠
ca渠
潮oy
=
be⁡c瑩癡瑥t⁢=景fe
=
p牯g牡浭楮g⸠.桥渠摥扵g潤攠楳⁡c瑩癥Ⱐ瑨敲e⁷楬=⁢=⁳=g湡氠
iC䐠獩g湡汳⁲潵瑥搠瑯⁒䜰ⱒ䜱ⱒ䜲ⱒ䜳ⱒ䜱㈬刱㌬d䜱㐬⁡湤⁒䜱㔮⁔桥獥⁷楬=潮=瑯爠瑨t=
摡瑡⁳楧na汳⁧潩og⁴桲潵杨⁴桥giC䐮
=
周楳⁷楬氠慬汯眠摥扵杧楮i映瑨f=iCa⸠䅮潴桥爠浥瑨潤t
c潵汤⁢攠畳楮o⁴桥=
O
nd

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.
These
debugging methods are not finalized.




ECE 477

Digital Systems Senior Design Project

Rev 8/09


-
5
-

3.0

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

application
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
System.Speech.Recognition
namespace

[
4]

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
receipt

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

[
6]
, 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
namespace

[
5]

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
ule
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


-
6
-

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

go

through the general flow of the program as outlined in
Appendix B
.
The
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
m.
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
advance

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

modules

provided by MP
LAB are the p30f5011.h and libpic30.h.
P30f5011.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


-
7
-

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

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

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

functions supplied by MPLAB.

Status: In
progress [
1]
.


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
2.0.
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
term
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


-
8
-

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
als
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 (
str
) function
, it

will accep
t an address to send, and
return the data
received
in the SPI2
RXB
.
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
transmit_receive_
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.

4.0

Summary

The
Future Register project aims to rid the transaction process of paper, both cash
and
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
sPIC30F5011
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
n

LCD.
ECE 477

Digital Systems Senior Design Project

Rev 8/09


-
9
-

List of References


[1]

BallSoHard. “LCD.C”, [Online], Availabl
e:
https://engineering.purdue.edu/477grp14/Documents/LCD.c

[Accessed March 21, 2012]


[2]

BallSoHard. “PN532

LONG DATA SHEET”, [Online], Available:
https://engineering.purdue.edu/477grp14/Specs/NFC/PN532
--
%20LONG%20DATA%20SHEET.pdf
. [Accessed March 21, 2012]


[3]

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

ww1.microchip.com/downloads/en/DeviceDoc/70046D.pdf

. [Accessed March 21, 2012]


[4]

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

http://msdn.microsoft.com/
en
-
us/library/system.speech.recognition.aspx
. [Accessed March
21, 2012]


[5]

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

http://msdn.microsoft.com/en
-
us/library/system.security.cryptography%28v=vs.71%29.aspx
. [Accessed March 21, 2012]


[6]

MSDN. “SerialPort Class (System.IO.Ports)”, [Online], Available:
http://msdn.microsoft.com/en
-
us/library/system.io.ports.serialport.aspx
. [Accessed March
21, 2012]
























ECE 477

Digital Systems Senior Design Project

Rev 8/09


-
10
-


Appendix A: Flowchart/Pseudo
-
code for Main Program

ECE 477

Digital Systems Senior Design Project

Rev 8/09


-
11
-

Appendix
B
: H
ierarchical Block Diagram of Code Organization