3 1. Prepare a simple web page (I recommend using sites.google.com or just a plan
4 google doc and publishing it) with the following:
6 a. Text that briefly describes your software organization for mbed and the
7 host (e.g. event handlers, threads etc. and what they do in plain text),
8 and the precise protocol and format for data that is exchanged between
11 b. URLS for: (i) Code for PC as a .zip file (you could put the .zip file on
12 Dropbox or on Github), (ii) Code for mbed on mbed.org (you can publish it
13 there), and (iii) The video.
15 2. When you have everything ready, fill the form at
16 https://docs.google.com/forms/d/1AaTB7dhT99_khnrwIP3ZzDkjRRhPj7Ql9nE3RqRPwQw/viewform
20 <h2>Brief Description</h2>
22 <p>The objective of this homework is to explore organizing embedded software
23 using mbed as the platform in context of a simple system. Sensor data flows
24 in the direction of: mbed → PC → Xively.</p>
26 <h2>Embedded Target Design</h2>
28 <p>The mbed code is organized in a single main.cpp file which invokes libraries
29 to read the sensor data. The Accelerometer, Magnetometer, and Touch Sensor
30 libraries were acquired through the mbed website and the Analog Input and
31 Output libraries were included in the mbed SDK.</p>
33 <p>The software consists of preemptable sensor loop running at a fixed rate, a
34 serial data receive interrupt handler, and a direct-memory access serial
35 transmitter. On each iteration of the sensor loop a time counter is checked
36 to determine which sensor are due for reading. Each sensor function polls
37 data from the sensor, packs the data into an output frame, and then write
38 the frame to the output queue.</p>
40 <p><i>Note: the sensor reading was originally performed in a timer interrupt
41 routine, however, it moved to a background task to minimize interference
42 with the reception of serial commands.</i></p>
44 <h2>Data Logger Design</h2>
46 The data logger is implemented as a Graphical User Interface using Python and
47 the GTK+ Toolkit. The source code is organized around the following classes:
50 <li>A Main class which performs basic initialization</li>
51 <li>A Config class for storing user preferences</li>
52 <li>A Device class to interfaces with the mbed using PySerial</li>
53 <li>A Logger class to transmit the recorded data to Xively</li>
54 <li>A Visual class to display the user interface</li>
57 <h2>Data Collection</h2>
59 <p>The mbed FRDM-KL46Z is responsible for data collection and sending it to the
60 host via Serial-over-USB. Sensors data is collected at a periodic rate and
61 is transmitted to the PC using the DATA_FRAME format shown below. The Serial
62 data transmit is handled by the KL46Z Direct-Memory Access (DMA) controller
63 so that data transmission does not block the CPU. When sensor data is ready,
64 it is packed and appended to a transmit buffer. At the end of the periodic
65 loop the DMA controller is enabled and data transmission begins</p>
67 <p>Commands are sent to the mbed using the COMMAND_FRAME format and are
68 processed using a serial interrupt handler. The handler parses the incoming
69 messages and performs command processing when a valid COMMAND_FRAME is
72 <h2>Serial Message Formats</h2>
74 <p>As is mentioned above, the mbed and communicate via UART, thus working based
75 on serial protocol. Since the mbed can be perceived as a slave to the PC, we
76 let the mbed collect and send DATA_FRAME, while PC is responsible for
77 generating COMMAND_FRAME. The frame structure is as follows:</p>
80 <table cellspacing="0" cellpadding="2" border="1">
81 <tr><td>1 Byte</td><td>4 bits </td><td>4 bits </td><td>1 Byte </td><td>(Varied Size)</td><td>1 Byte</td></tr>
82 <tr><td>HEADER</td><td>dataType</td><td>snsType</td><td>dataNum</td><td>data </td><td>TAIL </td></tr>
85 <h4>Field Descriptions</h4>
86 <table cellspacing="0" cellpadding="2" border="1">
87 <tr><t4>HEADER: </td><td>0x02, constant, indicating the start of a frame</td></tr>
88 <tr><td>dataType:</td><td>Data Type:<table>
89 <tr><td style="padding-left:3em">0- int8</td><td style="padding-left:1em">1 - int16</td><td style="padding-left:1em">2 - int32</td></tr>
90 <tr><td style="padding-left:3em">3- uint8</td><td style="padding-left:1em">4 - uint16</td><td style="padding-left:1em">5 - uint32</td></tr>
91 <tr><td style="padding-left:3em">6- float</td><td style="padding-left:1em">7 - double</td><td style="padding-left:1em"> </td></tr>
93 <tr><td>snsType: </td><td>Sensor Type:<ul style="list-style-type: none;">
94 <li>0 - LIGHT_SENSOR</li>
95 <li>1 - ACC_SENSOR</li>
96 <li>2 - MAG_SENSOR</li>
97 <li>3 - TOUCH_SENSOR</li>
98 <li>4 - ADC_SENSOR</li>
100 <tr><td>dataNum: </td><td>Data number. Number of data pack in the frame</td></tr>
101 <tr><td>data: </td><td>Sensor data. How it is packed is based on dataType and dataNum</td></tr>
102 <tr><td>TAIL: </td><td>0x0A, constant, indicating the end of a frame</td></tr>
105 <h3>Command Frame</h3>
106 <table cellspacing="0" cellpadding="2" border="1">
107 <tr><td>1 Byte</td><td>4 bits </td><td>4 bits </td><td>4 Byte </td><td>1 Byte</td></tr>
108 <tr><td>HEADER</td><td>cmdType</td><td>snsType</td><td>Interval</td><td>TAIL </td></tr>
111 <h4>Field Descriptions</h4>
112 <table cellspacing="0" cellpadding="2" border="1">
113 <tr><td>HEADER: </td><td>0x02, constant, indicating the start of a frame</td></tr>
114 <tr><td>cmdType: </td><td>Command Type:<ul style="list-style-type: none;">
119 <tr><td>Interval:</td><td>sampling rate. Representing a float of 4 Bytes.</td></tr>
120 <tr><td>TAIL: </td><td>0x0A, constant, indicating the end of a frame</td></tr>
124 a. Text that briefly describes your software organization for mbed and the
125 host (e.g. event handlers, threads etc. and what they do in plain text),
126 and the precise protocol and format for data that is exchanged between
127 the host and the mbed.
130 <h2>Sampling Rate</h2>
132 <p>The following sampling rates were obtained for each sensor, and a combined
133 sampling rate when all sensors are sampling simultaneously. Data collection
134 was performed using a 230400 serial baud rate.</p>
137 <tr><th>Sensor </th><th style="padding-left: 1em;">Sampling Rate</th></tr>
138 <tr><td>Accelerometer </td><td style="padding-left: 1em;"> 560 Hz </td></tr>
139 <tr><td>Magnetometer </td><td style="padding-left: 1em;"> 530 Hz </td></tr>
140 <tr><td>Touch Sensor </td><td style="padding-left: 1em;">1930 Hz </td></tr>
141 <tr><td>Light Sensor </td><td style="padding-left: 1em;">2414 Hz </td></tr>
142 <tr><td>Analog to Digital</td><td style="padding-left: 1em;"> 820 Hz </td></tr>
143 <tr><td>All Combined </td><td style="padding-left: 1em;"> 150 Hz </td></tr>
146 <h2>Online Submission</h2>
149 <dt>Code for mbed</dt>
150 <dd><a href="http://mbed.org/users/andy753421/code/Sensors/">http://mbed.org/users/andy753421/code/Sensors/</a></dd>
153 <dd><a href="https://sites.google.com/a/g.ucla.edu/ibeaconnav/homework1/python.zip">https://sites.google.com/a/g.ucla.edu/ibeaconnav/homework1/python.zip</a></dd>
157 <dd>(we will do a demo during office hours)</dd>