// --------------------------------------------------------------------
// Copyright (c) 2011 by Terasic Technologies Inc.
// --------------------------------------------------------------------
//
// Permission:
//
// Terasic grants permission to use and modify this code for use
// in synthesis for all Terasic Development Boards and Altera Development
// Kits made by Terasic. Other use of this code, including the selling
// ,duplication, or modification of any portion is strictly prohibited.
//
// Disclaimer:
//
// This VHDL/Verilog or C/C++ source code is intended as a design reference
// which illustrates how these types of functions can be implemented.
// It is the user's responsibility to verify their design for
// consistency and functionality through the use of formal
// verification methods. Terasic provides no warranty regarding the use
// or functionality of this code.
//
// --------------------------------------------------------------------
//
// Terasic Technologies Inc
// 356 Fu-Shin E. Rd Sec. 1. JhuBei City,
// HsinChu County, Taiwan
// 302
//
// web: http://www.terasic.com/
// email: support@terasic.com
//
// --------------------------------------------------------------------
//
// Major Functions: G Sensor utilization
//
// --------------------------------------------------------------------
//
// Revision History :
// --------------------------------------------------------------------
// Ver :| Author :| Mod. Date :| Changes Made:
// V1.0 :| Rosaline Lin :| 02/16/2011 :| Initial Revision
// --------------------------------------------------------------------
//=======================================================
// This code is generated by Terasic System Builder
//=======================================================
module DE0_NANO_G_Sensor(
//////////// CLOCK //////////
CLOCK_50,
//////////// LED //////////
LED,
//////////// KEY //////////
KEY,
//////////// Accelerometer and EEPROM //////////
G_SENSOR_CS_N,
G_SENSOR_INT,
I2C_SCLK,
I2C_SDAT
);
//=======================================================
// PARAMETER declarations
//=======================================================
//=======================================================
// PORT declarations
//=======================================================
//////////// CLOCK //////////
input CLOCK_50;
//////////// LED //////////
output [7:0] LED;
//////////// KEY //////////
input [1:0] KEY;
//////////// Accelerometer and EEPROM //////////
output G_SENSOR_CS_N;
input G_SENSOR_INT;
output I2C_SCLK;
inout I2C_SDAT;
//=======================================================
// REG/WIRE declarations
//=======================================================
wire dly_rst;
wire spi_clk, spi_clk_out;
wire [15:0] data_x;
//=======================================================
// Structural coding
//=======================================================
// Reset
reset_delay u_reset_delay (
.iRSTN(KEY[0]),
.iCLK(CLOCK_50),
.oRST(dly_rst));
// PLL
spipll u_spipll (
.areset(dly_rst),
.inclk0(CLOCK_50),
.c0(spi_clk), // 2MHz
.c1(spi_clk_out)); // 2MHz phase shift
// Initial Setting and Data Read Back
spi_ee_config u_spi_ee_config (
.iRSTN(!dly_rst),
.iSPI_CLK(spi_clk),
.iSPI_CLK_OUT(spi_clk_out),
.iG_INT2(G_SENSOR_INT),
.oDATA_L(data_x[7:0]),
.oDATA_H(data_x[15:8]),
.SPI_SDIO(I2C_SDAT),
.oSPI_CSN(G_SENSOR_CS_N),
.oSPI_CLK(I2C_SCLK));
// LED
led_driver u_led_driver (
.iRSTN(!dly_rst),
.iCLK(CLOCK_50),
.iDIG(data_x[9:0]),
.iG_INT2(G_SENSOR_INT),
.oLED(LED));
endmodule |