ELEX Now You See Me. Project Report

Similar documents
Topics Introduction to Microprocessors

Parallel Input/Output. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Today s Menu. Near Infrared Sensors

Image Acquisition Method Based on TMS320DM642

Fig 1: The symbol for a comparator

I2C Demonstration Board I 2 C-bus Protocol

SPI Slave to PWM Generation

I hope you have completed Part 2 of the Experiment and is ready for Part 3.

International Research Journal in Advanced Engineering and Technology (IRJAET)

Serial Communication AS5132 Rotary Magnetic Position Sensor

Multi-Channel Charge Pulse Amplification, Digitization and Processing ASIC for Detector Applications

SPI, Talking to Chips, and Minimizing Noise

Linear Integrated Circuits

TSL260, TSL261, TSL262 IR LIGHT-TO-VOLTAGE OPTICAL SENSORS

AUTOMATIC RAILWAY CROSSING SYSTEM

DS1307ZN. 64 X 8 Serial Real Time Clock PIN ASSIGNMENT FEATURES

DS1801 Dual Audio Taper Potentiometer

DS1803 Addressable Dual Digital Potentiometer

Unit-6 PROGRAMMABLE INTERRUPT CONTROLLERS 8259A-PROGRAMMABLE INTERRUPT CONTROLLER (PIC) INTRODUCTION

DS2165Q 16/24/32kbps ADPCM Processor

DNT24MCA DNT24MPA. Low Cost 2.4 GHz FHSS Transceiver Modules with I/O. DNT24MCA/MPA Absolute Maximum Ratings. DNT24MCA/MPA Electrical Characteristics

802.11g Wireless Sensor Network Modules

PIC Functionality. General I/O Dedicated Interrupt Change State Interrupt Input Capture Output Compare PWM ADC RS232

RW1026 Dot Matrix 48x4 LCD Controller / Driver

ECE U401/U211-Introduction to Electrical Engineering Lab. Lab 4

FLD00042 I 2 C Digital Ambient Light Sensor

INF8574 GENERAL DESCRIPTION

RayStar Microelectronics Technology Inc. Ver: 1.4

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

PNI MicroMag 3. 3-Axis Magnetic Sensor Module. General Description. Features. Applications. Ordering Information

Three-Stage Coil Gun

Dedan Kimathi University of technology. Department of Electrical and Electronic Engineering. EEE2406: Instrumentation. Lab 2

DS1075 EconOscillator/Divider

TIL306, TIL307 NUMERIC DISPLAYS WITH LOGIC

Hello and welcome to this Renesas Interactive Course that provides an overview of the timers found on RL78 MCUs.

DS1075. EconOscillator/Divider PRELIMINARY FEATURES PIN ASSIGNMENT FREQUENCY OPTIONS

8253 functions ( General overview )

Blind Spot Monitor Vehicle Blind Spot Monitor

ELEX 7660: Digital System Design Project Report Automatic Garage Door Opener

Data Logger by Carsten Kristiansen Napier University. November 2004

DS1807 Addressable Dual Audio Taper Potentiometer

PC-OSCILLOSCOPE PCS500. Analog and digital circuit sections. Description of the operation

Chapter 9. sequential logic technologies

Microprocessor & Interfacing Lecture Programmable Interval Timer

IS31FL3190 IS31FL CHANNEL FUN LED DRIVER. Preliminary Information November 2015

DSP Project. Reminder: Project proposal is due Friday, October 19, 2012 by 5pm in my office (Small 239).

DS1307/DS X 8 Serial Real Time Clock

Application Note. Smart LED Dimmer Controlled via Bluetooth AN-CM-225

Using a Sharp GP2D12 Infrared Ranger with BasicX

PRODUCT OVERVIEW OVERVIEW OTP

DNT90MCA DNT90MPA. Low Cost 900 MHz FHSS Transceiver Modules with I/O

CS302 Digital Logic Design Solved Objective Midterm Papers For Preparation of Midterm Exam

Digital Controller Chip Set for Isolated DC Power Supplies

SC16C750B. 1. General description. 2. Features. 5 V, 3.3 V and 2.5 V UART with 64-byte FIFOs

Battery Powered People Counter with Integral LCD Display & 418Mhz Data Transmitter

DS1307ZN. 64 X 8 Serial Real Time Clock

FEATURES DESCRIPTION APPLICATIONS BLOCK DIAGRAM. PT2272 Remote Control Decoder

LM12L Bit + Sign Data Acquisition System with Self-Calibration

11 Counters and Oscillators

ULTRASONIC TRANSMITTER & RECEIVER

description REF GND REF + (A1) V CC 2 1(MSB) A0 A2 A3 A4 A5 A10/D1 A11/D (LSB) R/ W CLK RS CS A12/D3 A13/D4 A14/D5 A15/D6 R

Simultaneous Co-Test of High Performance DAC-ADC Pairs May 13-28

USB4. Encoder Data Acquisition USB Device Page 1 of 8. Description. Features

GFT1012 2/4 Channel Precise Slave Generator

Autonomous Crash Avoidance System. Kristen Anderson Kat Kononov Fall 2010 Final Project Report

The rangefinder can be configured using an I2C machine interface. Settings control the

Robotic Development Kit. Powered using ATMEL technology

Fixture Built-in Sensor Daylight Harvest Version

± SLAS262C OCTOBER 2000 REVISED MAY 2003

CS/ECE/EEE/INSTR F241 MICROPROCESSOR PROGRAMMING & INTERFACING MODULE 8: I/O INTERFACING QUESTIONS ANUPAMA KR BITS, PILANI KK BIRLA GOA CAMPUS

HIGH LOW Astable multivibrators HIGH LOW 1:1

Embedded Systems and Software

DS1867 Dual Digital Potentiometer with EEPROM

SCLK 4 CS 1. Maxim Integrated Products 1

RF4463F30 High Power wireless transceiver module

The counterpart to a DAC is the ADC, which is generally a more complicated circuit. One of the most popular ADC circuit is the successive

HT1620 HT1621 HT1622 HT16220 HT1623 HT1625 HT1626 HT1627 HT16270 COM

Hello, and welcome to this presentation of the FlexTimer or FTM module for Kinetis K series MCUs. In this session, you ll learn about the FTM, its

SC16C650B. 1. General description. 2. Features. 5 V, 3.3 V and 2.5 V UART with 32-byte FIFOs and infrared (IrDA) encoder/decoder

Roland Kammerer. 13. October 2010

Application Circuits 3. 3V R2. C4 100n G PI O. 0 G PI O S e t u p d a ta G PI O. 5 G PI O M o t i o n I n t G PI O. 4 G PI O.

Manual IF2008A IF2008E

DS1802 Dual Audio Taper Potentiometer With Pushbutton Control

Chapter 9. sequential logic technologies

Lab 1.2 Joystick Interface

Temperature Monitoring and Fan Control with Platform Manager 2

Introduction. Theory of Operation

HOMANN DESIGNS. DigiSpeed. Instruction manual. Version 1.0. Copyright 2004 Homann Designs.

GFT1504 4/8/10 channel Delay Generator

Revolutionizing 2D measurement. Maximizing longevity. Challenging expectations. R2100 Multi-Ray LED Scanner

PART TOP VIEW V EE 1 V CC 1 CONTROL LOGIC

DNT2400. Low Cost 2.4 GHz FHSS Transceiver Module with I/O

Shock Sensor Module This module is digital shock sensor. It will output a high level signal when it detects a shock event.

νµθωερτψυιοπασδφγηϕκλζξχϖβνµθωερτ ψυιοπασδφγηϕκλζξχϖβνµθωερτψυιοπα σδφγηϕκλζξχϖβνµθωερτψυιοπασδφγηϕκ χϖβνµθωερτψυιοπασδφγηϕκλζξχϖβνµθ

HD44102D. (Dot Matrix Liquid Crystal Graphic Display Column Driver) Features. Description. Ordering Information

Combinational Logic Circuits. Combinational Logic

Characteristic Sym Notes Minimum Typical Maximum Units Operating Frequency Range MHz. RF Chip Rate 11 Mcps RF Data Rates 1, 2, 5.

ISSN: ISO 9001:2008 Certified International Journal of Engineering and Innovative Technology (IJEIT) Volume 4, Issue 11, May 2015

DS1868B Dual Digital Potentiometer

DS1073 3V EconOscillator/Divider

Transcription:

ELEX 7660 Now You See Me Project Report Ken Do, 4-14-2017

Contents 1 - Overview... 3 1.1 - Project Motivation... 3 1.2 - Goals... 3 1.3 - System Block Diagram... 3 1.4 - IP and Hardware Descriptions... 4 2 - Outcome... 5 2.1 - Results and Successes... 5 2.2 - Design Reviews... 5 2.3 - Possibilities for Future Work... 5 3 - Description of Design Blocks... 6 3.1 - Infrared Sensors... 6 3.2 Photo-resistor and ADC... 7 3.3 - Timer Algorithm... 8 3.4 - Street Light Circuit Model... 9 4 - Systemverilog Code... 12 4.1 - ADC.sv Module... 12 4.2 - top.sv Module... 17 p. 1/19

Table of Figures Project Report: Now You See Me Ken Do Figure 1: System Block Diagram.... 3 Figure 2: Infrared light can't be seen with the naked eye but can be as purple light with your phone's camera. This image was taken while cycling through the IR emitter/receiver pairs.... 6 Figure 3: Infrared emitter LEDs (clear) directed at the infrared light detectors (black).... 7 Figure 4: Photo-resistor circuit..... 8 Figure 5: States of the scount[i] signal..... 9 Figure 6: The TSL267 side-looker infrared receiver..... 10 Figure 7: Circuit diagram of the model street light system.... 10 Figure 8: As-built model of the street light system containing rows of Street lights (top), IR emitter (middle), and IR receiver (bottom). Vcc are the red wires, common are the black wires. Photo-resistor circuit located on top right. FPGA connections are the row of wires on the top left... 11 p. 2/19

1 - Overview Project Report: Now You See Me Ken Do 1.1 - Project Motivation Our street lighting requirements consume the largest amount of energy in our road infrastructure. The transition to more efficient light technology such as LED fixtures have improved the situation, but further reduction of energy consumption can only be realized by improving the lighting control systems. The current control scheme turns on the lights at a set time or ambient light level. Once the set point is reached, the fixtures remain on at 100% output throughout the night. In locations with minimal to no traffic, these fixtures are consuming energy with no purpose. It is equivalent to leaving a light on in a vacant room overnight. 1.2 - Goals Exting the lighting control systems ability to detect traffic will allow the system to provide sufficient light output when needed, and return to a low energy state once traffic has cleared. This is achieved by implementing the following system components: Use the FPGA s ADC to determine the output from a photo-resistor which will determine the amount of ambient light and trigger the device to enter night mode or day mode. Use the output from infrared sensors to detect motion on different sections of the modelled street. This could be accomplished using the ADC, external comparators, or directly using the outputs from the sensors as signals, if the voltage levels are consistent with logic levels. When at night and motion (a passing car) has been detected, turn on street lights where the car currently is as well as lights ahead of its path. o Automatically turn off these lights once the car has passed, by creating timers on the FPGA. 1.3 - System Block Diagram Figure 1: System Block Diagram. p. 3/19

1.4 - IP and Hardware Descriptions Project Report: Now You See Me Ken Do Hardware / IP Core Function Creator(s) CDS Photoconductive Photocell Photocell designed to sense light from 400 to 700 nm. Dark resistance = 500 kω Illuminated resistance = 33 kω Luna Optoelectronics Day/Night Detection System Simple resistor divider circuit containing a photocell. Voltage output at the center of the resistor divider varies due to changes in light intensity detected by the photocell. Andrew, Ken TI ADC128S022 Built-in ADC module used to read Day/Night Detection voltage output levels. Texas Instruments Adcspi Interfaces with the serial output of the built-in ADC module on the FPGA and stores the quantized data from channels 0 and 1. Ed Casas myfifo First In First Out interface to with adcspi. Ken, Andrew IR Emitter (LTR-4206E) Emits Infrared light with a wavelength of 940 nm LITEON IR Light to Voltage Converter (TLS267) Converts 940nm IR light intensity to output voltage TAOS Traffic Detection System Reads the voltage output from the IR detector associated to a street light location to detect traffic. Andrew, Ken Top Control System Sets street light output levels according to information provided by Day/Night and Traffic detection systems. Ken, Andrew p. 4/19

2 - Outcome Project Report: Now You See Me Ken Do 2.1 - Results and Successes The Day/Night detection system used a simple resistor divider circuit containing the photocell and was successful in detecting ambient lighting levels. The ADC quantization provided sufficient information to allow the programmer to set desired thresholds to distinguish between day and night scenarios. The traffic detection system used the IR emitter/receiver pair to detect traffic. Each IR pair was addressed to match the light fixture location. The voltage output of the IR receiver provided a digital signal to the Top Control system. When sufficient IR light is detected, a high digital logic signal is sent to the Top Control system. The Top Control system used the information provided by the previous two systems to control street light output. During day mode, all the street lights are deactivated. When night mode is detected, the street light output is determined by the traffic detection system. The traffic detection and the Timer algorithm within the Top Control system allowed for an active street lighting control system. When traffic is detected, the fixture in that location and the two sections ahead of that location are activated. This system successfully reduced the energy consumption of the street lights by only providing sufficient street lighting output when needed. The Timer algorithm ensured the correct street lights were activated for a sufficient amount of time. The timer allowed for the street lights to remain active for a set period after traffic has cleared in that location. The traffic in that area will observe adequate lighting on the road ahead and behind them. The development of the timer algorithm within Quartus provided challenges due to Quartus not generating the expected hardware. Drawing out the state diagram helped produce the simplest code, which then generated the required hardware. 2.2 - Design Reviews Our original plan was to use the ADC to determine the output level from the IR receivers, as initial testing determined that the blocked and unblocked voltages were approximately 0.6V and 1V respectively. We designed the system based on using one ADC channel to measure all 10 IR receivers, by only turning one transmitter/receiver pair on at a time and syncing this with the ADC conversion time. This was based on the incorrect assumption that the receiver outputs were high impedance. When this didn t work, we tested the receiver outputs with a higher intensity IR from the transmitters, and determined that the blocked and unblocked output voltages were 0.3V and 3.2V respectively, when using the FPGA s Vcc of 3.3V. This is sufficient for logic levels, and when combined with having all of the transmitters and sensors on 100% of the time rather than cycling through them, was used directly as the signal for the zone being tripped. 2.3 - Possibilities for Future Work The model designed in this project serves as a basis for future expansion of features of a smart street light control system. Different scenarios could be implemented based on where the section of road is located. If the road is in a remote area, the auto-off system would be ideal as there would be limited vehicle traffic and no pedestrian traffic at night. In a more highly populated area, it might be more practical to have the lights dimmed rather than completely turned off when there is no traffic. This could simply be done using pulse-width modulation. p. 5/19

As stated previously, we attempted to use the ADC to measure the IR intensity at the receiver. Using the ADC would likely be the best way to implement this, as you could use any kind of IR sensor. This would require either using more ADC channels, or a means of isolating individual sensors. The system as-built only supports one-way traffic, due to the way the timer module was designed to turn on the next two lights when a sensor is tripped. Upgrading to bi-directional movement would be possible with using an extra sensor at either of the road segment to determine the direction of a moving vehicle. 3 - Description of Design Blocks 3.1 - Infrared Sensors Infrared light sensors are commonly used for motion detection. While some, such as the yard light sensors found on many houses, are sensitive enough to pick up the infrared given off as body heat, others use a transmitter and receiver to create a stronger beam of infrared light whose intensity is determined by the receiver. This setup is commonly used as the safety sensor for automatic garage doors, to stop the door from closing if something or someone gets in the way, similar to Figure 3. We will use this technology as the motion sensors for our street light control system. Figure 2: Infrared light can't be seen with the naked eye but can be as purple light with your phone's camera. This image was taken while cycling through the IR emitter/receiver pairs. p. 6/19

Figure 3: Infrared emitter LEDs (clear) directed at the infrared light detectors (black). The IR sensors blocked and unblocked output voltages are approximately 0.3V and 3.2V respectively, when using the FPGA s Vcc of 3.3V. These voltage levels are sufficient for high and low logic levels, and are used as signals to directly drive the IR_LED_TxRx_Enable[i] signals for the light timer algorithm. 3.2 Photo-resistor and ADC The simple photo-resistor circuit shown in Figure 4 is widely used to detect ambient lighting levels due to its simplicity. The light intensity detected by the photocell changes its resistance. This allows the output voltage to vary with changes in light level intensity. Using the built-in ADC on the FPGA board allowed for adjusting day/night detection threshold. The adjustability of this parameter enables this system to meet the requirements of different locations. The ADC chip on the FPGA board was interfaced with the adcspi.sv module developed by Ed Casas. This module provides the ADC chip with signals for chip select, SCLK, and data in. It also receives the data out from the ADC. This module is configured to read ADC values from channels 0 and 1 on the ADC chip. Both values are stored as data register in the adcspi.sv module. Interfacing myfifo.sv module with adcspi.sv ensured that the first data conversion in was the first data conversion out. p. 7/19

Figure 4: Photo-resistor circuit. 3.3 - Timer Algorithm The auto-off timer control block is used to turn off individual street lights after they have they have been turned on by the IR_LED_TxRx_Enable[i] from the infrared receivers. The lights themselves are turned on by the scount[i] signal being greater than 0. The timer algorithm can be visualized by the state transition diagram for the scount[i] signal below in Figure 5. Whenever a sensor is tripped, the value of ON_TIME (150,000,000 clock cycles, which is approximately 3 seconds), is loaded into scount[i] for the corresponding street light that is to be turned on. Because we wish to light the path ahead of the moving vehicle, the code also resets scount[i] for the next two street lights in series. The value of scount[i] is decremented every clock cycle, until it reaches 0, in which case it stays there. At any time, the value of scount[i] can be reset back to the value of ON_TIME, thus resetting the counter if the corresponding sensor or one of the previous two sensors are tripped. The timer control block will only run if the operating mode is set to AUTO_OFF. p. 8/19

Figure 5: States of the scount[i] signal. 3.4 - Street Light Circuit Model The street lights, modelled as a row of LEDs, are individually powered by the output signals Street_Light[i]. They use a 1kΩ resistor to control the current. The IR transmitter LEDs also use a 1kΩ resistor to limit current, but are all powered by the 3.3V Vcc of the FPGA. Both of these sets of LEDs are wired to common rails and connected to common on the FPGA. The IR receivers, Figure 6, are a 3-pin device, requiring Vcc and common from the FPGA. There is a 10kΩ resistor from output to common, and the output pin is also directly connected to the IR_LED_TxRx_Enable[i] input signal to the FPGA. p. 9/19

Figure 6: The TSL267 sidelooker infrared receiver. Figure 7: Circuit diagram of the model street light system. p. 10/19

Figure 8: As-built model of the street light system containing rows of Street lights (top), IR emitter (middle), and IR receiver (bottom). V cc are the red wires, common are the black wires. Photo-resistor circuit located on top right. FPGA connections are the row of wires on the top left. p. 11/19

4 - Systemverilog Code Project Report: Now You See Me Ken Do 4.1 - ADC.sv Module // ADC.sv module - This module interfaces with the ADC of the FPGA board. // The ADC is used to detect day time status using a photocell. // Modified by: Ken Do, // Date: April 9, 2017 `define MAXIRPAIR 9 // the largest address for IR pairs `define CLOCK_DIV 10000 // Divisor for the ADC clock `define THRESHOLD 300 // LED comparison threshold module ADC ( input logic CLOCK_50, input logic [1:0] KEY, output logic [3:0] IRPAIR, // reset_n // selects IR pair to be sampled. // GATE indicates the traffic status on the road. Bits 0 - MAXIRPAIR // represent the status of the IR sensors. Bit MAXIRPAIR + 1 // represents the PHOTOCELL status. output logic [(`MAXIRPAIR+1):0] GATE, ); // ADC SPI interface output logic ADC_CS_N, // ssn output logic ADC_SADDR, // mosi output logic ADC_SCLK, // sclk input logic ADC_SDAT // miso logic ready, valid, oready, ovalid; logic [31:0] data, odata; logic reset_n, clk; assign reset_n = KEY[0]; // Divide module input clock by CLOCK_DIV. logic [31:0] count; always_ff @(posedge CLOCK_50) begin if (count <= 0) begin count <= `CLOCK_DIV; clk <= ~clk; else count <= count - 1'b1; adcspi a0 (.sclk(adc_sclk),.mosi(adc_saddr),.ssn(adc_cs_n),.miso(adc_sdat), // output to ADC clock // output to ADC DIN (address) // output to ADC chip select // input from ADC (DATA) p. 12/19

.ready(ready),.valid(valid),.data(data), // input // output // the ADC conversion data.clk(clk),.reset(~reset_n) ); // Photocell data control and output status. myfifo fifo0 (.ready(ready),.valid(valid),.data(data),.oready(oready),.ovalid(ovalid),.odata(odata),.irpair(irpair), // OUTPUT TO SYNCHRONIZE IR PAIR WITH ADC DATA.reset(reset_n),.clk(clk) ); assign oready = '1; logic [11:0] PHOTOCELL, TRAFFIC; assign PHOTOCELL = data[27:16]; assign TRAFFIC = data[15:0]; always_ff @(posedge clk) GATE[10] = (IRPAIR!= 9)? GATE[10] : (PHOTOCELL < 3000)? 1'b1 : 1'b0; module // -- start of adcspi.sv --- // SPI master interface for TI ADC128S022 // for ELEX 7660 201710 Lab 5 // Ed.Casas 2017-2-16 // reads channels 0 and 1 // sclk is clk is divided by 16 // output is 16-bit samples from channels 0 and 1 // samples packed into 32 bits (ch 0 in MS byte) // ADC128S0022 interface: // 16 bit transfers // mosi and cs* change on falling edge of sclk // mosi bits 13:11 are (next) channel number // miso sampled on rising edge of sclk // miso data is on ls 12 bits of miso // sample rate is sclk rate / 16 p. 13/19

// sample rate must be 50 to 200 khz // sclk rate must be 800 khz to 3.2 MHz // e.g. 50 MHz / 32 = 1.5625 MHz sclk, ~98kHz sampling // mosi timing relative to rising edge of sclk: // setup is >10ns, hold >10ns // miso timing is relative to falling edge of sclk: // access is <27ns, hold ~4ns module adcspi ( output logic sclk, mosi, ssn, // SPI master input logic miso, input logic ready, output logic valid, output logic [31:0] data, // ready/valid data out ); input logic clk, reset parameter MISO = {5'b00001,27'b0} ; // clock/bit counter struct packed { logic wordcnt ; logic [3:0] bitcnt ; logic sclk ; logic [3:0] clkcnt ; } cnt, cnt_next ; logic [31:0] sr ; // shift register logic rising, falling, done ; assign sclk = cnt.sclk ; // done all bits assign done = cnt ==? '{'1,'1,'1,'1} ; // clock/bit counter assign cnt_next = ( reset done )? '0 : cnt+1'b1 ; always@(posedge clk) cnt <= cnt_next ; assign rising = cnt_next.sclk && ~cnt.sclk ; assign falling = ~cnt_next.sclk && cnt.sclk ; always@(posedge clk) begin if ( falling ) mosi <= sr[31] ; if ( rising ) sr <= {sr[30:0],miso} ; // shift mosi out // shift miso in p. 14/19

if ( done ) begin data <= sr ; sr <= MISO ; mosi <= MISO[31] ; valid <= '1 ; if ( ready && valid ) valid <= '0 ; // copy to parallel out // channel select serial out // data ready // data was read always@(posedge clk) ssn <= reset ; // run continously module // myfifo.sv - FIFO with ready/valid input and output // for ELEX 7660 201710 lab 5 // Created by: Ed Casas // Modified by: Ken Do, module myfifo ( output logic ready, input logic valid, input logic [31:0] data, // ready/valid input input logic oready, // Avalon-ST output output logic ovalid, output logic [31:0] odata, output logic [3:0] IRPAIR, ); input logic reset, clk parameter W = 3 ; parameter N = 8 ; logic [31:0] DPRAM [7:0]; // Dual-ported RAM logic [2:0] readp, readp_next,writep, writep_next; // DPRAM in/out pointers always_ff @(posedge clk) begin if (reset) begin readp <= 3'b0; writep <= 3'b0; IRPAIR <= 4'b0; p. 15/19

if (ready) begin DPRAM[writep] <= data; if (IRPAIR >= 0 IRPAIR < `MAXIRPAIR) IRPAIR <= IRPAIR + 1'b1; else IRPAIR <= 4'b0; if (valid) writep <= writep_next; Project Report: Now You See Me Ken Do if (ovalid && oready) readp <= readp_next; always_comb begin // combinational logic for RAM status // input combinational logic ready = ((writep + 1'b1)!= readp)? 1'b1 : 1'b0; writep_next = (valid && ready)? (writep + 1'b1) : writep; // output combinational logic ovalid = (readp!= writep)? 1'b1 : 1'b0; readp_next = (oready && ovalid)? (readp + 1'b1) : readp; odata = DPRAM[readp]; module p. 16/19

4.2 - top.sv Module // BCIT ELEX 7660 Final Project - Now You See Me // Ken Do & Project Report: Now You See Me Ken Do `define LED_COUNT 10 model `define DAY_MODE 0 `define ALWAYS_ON 1 intensity `define AUTO_OFF 2 when no traffic `define AUTO_DIM 3 when no traffic // # of LED sensors and lamps on street // Day mode: all lights off // Night mode: all lights always on full // Night mode: power saving, (auto) lights off // Night mode: power saving, (auto) lights dim `define ON_TIME 32'd150000000 for street lights when tripped // 3 seconds (3 x 50MHz clock) = on time module top (input logic CLOCK_50, input logic [1:0] KEY, // System clock // Reset signal for ADC low) output logic ADC_CS_N, output logic ADC_SCLK, output logic ADC_SADDR, input logic ADC_SDAT, // ADC chip select (active // ADC clock signal // ADC control signal out // ADC miso input logic [`LED_COUNT - 1:0] IR_LED_TxRx_Enable, // Input from IR recievers output logic Street_Light [`LED_COUNT - 1:0], // Output to individual street lights ); output logic [7:0] LED // on board LED's for testing logic [3:0] IRPAIR ; // Input signal from ADC module to turn on selected IR Transmitter/Reciever Pair logic [11:0] Lumen_Sensor; // Lumen sensor result from 12-bit ADC from lumen sensor logic [11:0] ADC_Result; // Result of ADC conversion logic Street_Light_Mode_Enable [`LED_COUNT - 1:0]; enable signal from mode selector block // Street-Light logic gate [`LED_COUNT - 1:0]; tracker // IR beam broken (motion detected) logic [`LED_COUNT:0] GATE; // Beam broken signal from ADC module (bits 0 to 9) Night sensor (bit 10) // Please note that GATE[9:0] originally was inted to use the ADC to determine whether the sensors were tripped p. 17/19

// This was changed due to technical difficulties, and only GATE[10] was used (for the photoresistor). logic [1:0] Operating_Mode; // System operating mode: day/night/power saving logic [31:0] scount [`LED_COUNT - 1:0]; // Counters for each light to turn off logic count_reset [`LED_COUNT - 1:0]; // Count reset signal for timer block ADC a1 (.*); // Instantiate ADC module // Night/Day selector: change the night mode to one of 3 options based on desired // operating preferences. See defines above for details. always_comb begin if (GATE[10]) begin // GATE[10] is ADC result from ADC module for the photoresistor Operating_Mode = `AUTO_OFF; // Adjust this for operating mode LED[7] = 1; // Turn on on-board LED #7 for verification else begin Operating_Mode = `DAY_MODE; LED[7] = 0; // On-board LED's #0-6 for IR sensor verification assign LED[0] = ~IR_LED_TxRx_Enable[0]; assign LED[1] = ~IR_LED_TxRx_Enable[1]; assign LED[2] = ~IR_LED_TxRx_Enable[2]; assign LED[3] = ~IR_LED_TxRx_Enable[3]; assign LED[4] = ~IR_LED_TxRx_Enable[4]; assign LED[5] = ~IR_LED_TxRx_Enable[5]; assign LED[6] = ~IR_LED_TxRx_Enable[6]; // Operating mode selector always_comb begin unique case(operating_mode) `DAY_MODE: begin // Day mode - disable lights Street_Light_Mode_Enable[`LED_COUNT-1:0] = '{10{'0}}; `ALWAYS_ON: begin // Night mode - enable all lights at full power Street_Light_Mode_Enable[`LED_COUNT-1:0] = '{10{1'b1}}; `AUTO_OFF: begin // Power saving mode (auto off when no motion detected) Street_Light_Mode_Enable[`LED_COUNT-1:0] = '{10{1'b1}}; `AUTO_DIM: begin // Power saving mode (auto dim when no motion detected) (not implemented) Street_Light_Mode_Enable[`LED_COUNT-1:0] = '{10{1'b1}}; case p. 18/19

// Auto-off timer control block always_ff @(posedge CLOCK_50) begin if(operating_mode == `AUTO_OFF) begin // Only use if this mode is enabled for(int i = 0; i < `LED_COUNT; i = i + 1) begin // Generate hardware for each light gate[i] <= ~IR_LED_TxRx_Enable[i]; // When a gate is tripped, latch the signal if(gate[i]) begin // If a gate has been tripped and latched: count_reset[i] <= 1; // Signal the count reset for the light and the next 2 in series if(i < `LED_COUNT-1) // Stop generating hardware if at the of the road segment count_reset[i + 1] <= 1; if(i < `LED_COUNT-2) count_reset [i+2] <= 1; gate[i] <= 0; // Reset the gate-tripped latch // Reset counter to starting position when gate is tripped, or count down if count has been reset if(count_reset[i]) begin scount[i] <= `ON_TIME; count_reset[i] <= 0; // Reset the count_reset signal every time beam is triggered else if(scount[i] > 0) // Otherwise keep counting down if count is not finished scount[i] <= scount[i] - 1; else scount[i] <= 0; // Stay at 0 if count is finished // Final enable signal to LED street lights. Must be enabled by both the night/day sensor and the counters. // Signal from street light timers is the scount[i] signal. Lights will only be on when this counter > 0. always_comb begin for(int i = 0; i < `LED_COUNT; i = i + 1) Street_Light[i] = (scount[i] > 0) & Street_Light_Mode_Enable[i]; module p. 19/19