Professional Documents
Culture Documents
Fac Jung002 CYENG 237 Lab System Wire Wireless Interface
Fac Jung002 CYENG 237 Lab System Wire Wireless Interface
4
Gannon University LabReport
GANNON UNIVERSITY
Cyber Engineering 237: Introduction to Cyber-Physical
Systems
Lab
Wire & Wireless System
Interface
1. Design Objective
1
ECE349/GECE551 Rapid Prototyping with FPGA
Electrical and Computer Engineering Department
Gannon University
Establish a wireless communication channel between a sensor system and an
FPGA module to display the distance measured by an ultrasound sensor module on a
VGA monitor via VGA interface. The wireless communication channel is built by
employing a pair of XBee modules.
A short pulse is sent from the Arduino to the sensor to trigger a 40 kHz “click”
event. The click is transmitted from the sensor and an “echo” is returned from any objects
that were in the click’s path. The sensor will return an echo time pulse, which will be high
until the echo returns. Since this distance
2
ECE349/GECE551 Rapid Prototyping with FPGA
Electrical and Computer Engineering Department
Gannon University
is equal to the echo time pulse duration times the speed of sound (in desired units) it can be
observed that this device is truly only limited to the precision of the microcontrollers
clock.
1.4. ZigBee
ZigBee is a common wireless protocol that is used in various applications. Our device
transmitted at 2.4 GHz and can achieve data rates up to 250 kbit/second. This is excessive
given our small displacement message was a fixed length of 12 bytes. On the transmitter, the
ZigBee RX was connected to the TX of the Arduino. On the receiver, the ZigBee TX was
connected to the RX of the FPGA.
1.5. FPGA
Figure 3 shows the layout of the FPGA code layout.
The top level (dist_view) is used to instantiate each of the subcomponents. The
inputs into this module are the clock for synchronization, a key reset and the data passed to
the uart. The data passed to the uart is the displacement message passed from the ZigBee
receiver. The outputs of this top level module are everything required to display to the VGA
monitor: red, green and blue output (red_out, blue_out, and green_out) for a given pixel and
the horizontal and vertical sync signals (hsync and vsync).
There are three main subcomponents to the distance display which are the uart,
vga_sync and pixel_gen_dist. The vga_sync was provided in the lab 8 manual and was not
3
ECE349/GECE551 Rapid Prototyping with FPGA
Electrical and Computer Engineering Department
Gannon University
modified. A semi functioning uart was also provided but was modified to meet our design
requirements.
1.6. UART
The purpose of the uart is to receive the serial message from the ZigBee which
contains the displacement message. Once the data is received it separates the data buffer
into the three digits and the unit characters (“ cm”). The digits and unit characters are stored
in the variables dig_0 through dig_5.
Pixel_gen_dist determines the corresponding ASCII letter and how to display that
letter within its allocated space by doing a lookup within the font_rom. Font_rom contains
an 8x16 binary array for each ASCII character. The ones are pixels that should be
illuminated to properly display the ASCII character.
Vga_sync returns the current x and y pixel that is being updated. The FPGA code
does a look up to determine if the current position is within bounds of a digit. Figure 1
shows that each digit starts at y_start in the y axis and then ends at y_start + length of array
representing ASCII characters(16) * scale factor (to increase size of font). If the y position is
outside of these bounds then the red, green, and blue are set to zeros so that black is
displayed. The current x position can be compared to each digit’s boundary to determine
which digit should be evaluated in the font rom.
4
Figure 4. Monitor Display Layout
Once it is determined which digit is current being updated the code does a look up on the ASCII
table (font rom) for the digits ASCII code. The displacement message is always comprised of three
numeric characters (‘0’ through ‘9’), and then a space and then followed by ‘c’ and ‘m’. Table 1 shows
the ASCII code associated with the desired characters. The font_rom represents each ASCII character in
an 8x16 array that is concatenated together for every ASCII character. So to determine the starting row of
a character, the ASCII code was multiplied by 16 to return the corrected offset in the table.
5
e
99 63 c
109 6D m
Within an individual character it is determined which part of the ASCII array corresponds to the
current x and y pixel. Within the boundary of the digit, it is divided into 16 parts in the y axis and 8 parts
in the 8 axis. As the vga_sync moved along the viewable region of the individual digit then it is
determined which individual bit of the font_rom should be used for display. Figure 5 shows how the
individual digit is divided and then how font from the array is mapped into the display. Figure 5 uses the
example of the character ‘8’ which is ASCII code 0x38.
If the ASCII table value was a zero, then red, green, and blue are set to zero so that the pixel
matches the black background. If the ASCII table value was one, then red, green and blue were also set to
one to make the font white.
The ZigBee module passes in a serial message of characters. Since the modules were only setup
to transmit from the Arduino side and receive from the FPGA there was no guarantee that the message
would be received in the correct order or that multiple transmissions were not mixed up. This
asynchronous transmission would sometimes shift the message such that instead of displaying the 3
numeric digits, a space and the unit labels we would display them out of order or only partially with other
garbage characters. To correct this asynchronous transmission, a design was put in place to compare the
characters as they were received. It was known that the last character would always be a ‘m’ of ‘ cm’. So,
each character is the message buffer was compared to the ASCII value for ‘m’. Once an ‘m’ was found,
6
then we knew the buffer was full and the transmission had finished. The display should only be updated
once the ‘m’ was received.
The following procedures can be used as references of your design and implementation on both of
the microcontroller and FPGA boards:
An implementation procedure of an XBee transmitter module to microcontroller board
1. First Part include interface XBee with an adapter (Chosen adapter is XBee Adapter Kit
V1.1).
2. Connect Power from Arduino to 5V. XBee adapter in which XBee module is mounted on.
3. Connect GND from Arduino to GND in XBee adapter in which XBee module is mounted
on.
4. Connect Tx pin from Arduino to Rx pin in XBee adapter in which XBee module is
mounted on.
5. Connect Rx pin from Arduino to Tx pin in XBee adapter in which XBee module is
mounted on.
Controlling Logic has been done based on the received sensor signal and with the use of AD
pins, 0, 1, 3, and 4, wireless commands have been issued from Arduino board and sent via XBee
module wirelessly to trigger an action according to those pins status ( High or Low).
Appendix 1 include a sample of Arduino code sent to set pin AD4 High and Low.
2. For the receiver module AD pins on XBee adapter (AD0, AD1, AD3, AD4) has been
soldered with junction wires for FPGA interfacing purposes.
3. J4 and J2 header extensions on FPGA Spartan 3E has been used to interface XBee receiver
module with the board since those headers have an IO pins in which can swiftly be used for
our design.
4. J4 VCC is connected to 3.3 V of the XBee module to power the XBee module .
7
9. IO8 (F7) of J2 header extension is connected to AD3 of the XBee module .
Logic received wirelessly through XBee can be used to apply action on FPGA board as
indicated by Appendix 2 code and Appendix 3 which represents UCF file for that code.
3. Test Plan
While sitting on a table (so that it is stationary), place the PING sensor x distance away
from a solid wall. Use table 2 below to determine the desired distance, x, for each test case.
Measure the distance from the sensor to the wall with a tape measure.
4. Report
The Design and verification report should be a written report including all the detailed aspects of the lab
activities.
5. Appendix 1
/* Ping Sensor (3-pin Ultrasonic sensor module) The
circuit:
* +V connection of the PING attached to +5V
* GND connection of the PING attached to ground
* SIG connection of the PING attached to digital pin 7
*/
// this constant won't change. It's the pin number of the sensor's output:
const int pingPin = 7;
8
long interval = 100; long
previousMillis = 0; void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
unsigned long currentMillis = millis(); long
duration, inches, cm;
char str[7];
previousMillis = currentMillis;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2); digitalWrite(pingPin,
HIGH); delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
9
}
void xBeeSignalHigh()
{
Serial.write(0x7E);//Start byte, represents the start of data frame
Serial.write(0x00);//Length of the frame (MSB)
Serial.write(0x10);//Length of the frame (LSB)
Serial.write(0x17);//Frame ID represents AT command
Serial.write(0x00);//No reply for AT command
Serial.write(0x00);//Start of the MAC address of the receiver XBee
Serial.write(0x00);// MAC address set to 00 means broadcast .
Serial.write(0x00);
Serial.write(0x00);
Serial.write(0x00);
Serial.write(0x00);
Serial.write(0x00);
Serial.write(0x00);//End of the MAC address of the receiver XBee
Serial.write(0xFF);//Destination Network ID (Broadcast)
Serial.write(0xFE);//Second byte of the Destination Network ID
Serial.write(0x02);//For Payload to be applied (accept settings)
Serial.write(0x44);//Represents Digital Pin number (first byte)
Serial.write(0x34); //Represents Digital Pin number (second byte)
Serial.write(0x05); // Represents Value to be assigned for the pin
Serial.write(0xFA); // Checksum Value
}
void xBeeSignalLow()
{
Serial.write(0x7E);//Start byte, represents the start of data frame
Serial.write(0x00);//Length of the frame (MSB)
Serial.write(0x10);//Length of the frame (LSB)
Serial.write(0x17);//Frame ID represents AT command
Serial.write(0x00);//No reply for AT command
Serial.write(0x00);//Start of the MAC address of the receiver XBee
Serial.write(0x00); // MAC address set to 00 means broadcast .
Serial.write(0x00);
Serial.write(0x00);
Serial.write(0x00);
10
Serial.write(0x00);
Serial.write(0x00);
Serial.write(0x00);//End of the MAC address of the receiver XBee
Serial.write(0xFF);//Destination Network ID (Broadcast)
Serial.write(0xFE);//Second byte of the Destination Network ID
Serial.write(0x02);//For Payload to be applied (accept settings)
Serial.write(0x44);//Represents Digital Pin number (first byte)
Serial.write(0x34);//Represents Digital Pin number (second byte)
Serial.write(0x04);//Represents Value to be assigned for the pin
Serial.write(0xFB); //Checksum Value
}
6. Appendix 2
A wireless communication model for XBee in VHDL for an FPGA implementation
library IEEE;
use IEEE.STD_LOGIC_1164.ALL; use
IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY PWM_gen is
Port ( Clk : in STD_LOGIC; input1:
in std_logic; input2: in
std_logic; input3: in std_logic; xbeereset:
in std_logic;
led : out std_logic_vector(6 downto 0)); end PWM_gen;
11
elsif ( input1 <='0' and input2 <= '0' and input3 <= '0' ) then
led_pattern <= "0000000"; led_pattern_en <='1'; end if;
led <= led_pattern; end if;
end process led_display;
7. Appendix 3
# These four connections are shared with the J4 6-pin accessory header NET "input1" LOC = "D7" |
IOSTANDARD = LVCMOS33 | SLEW = FAST |DRIVE= 8
8 ; #second pin
12