Created
January 14, 2025 14:08
-
-
Save Jay-davisphem/99bf9f2231981c152125b6966f1fb69b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Here is a step-by-step guide to implementing the IoT-Enabled Weather Station using VHDL on your DE2-70 board. The solution includes all necessary VHDL code, configurations, and explanations. | |
| --- | |
| Step 1: Install and Set Up Quartus II 9.1 | |
| 1. Install Quartus II: | |
| Ensure Quartus II 9.1 is installed. | |
| Connect your DE2-70 board to your PC and verify drivers are installed. | |
| 2. Create a New Project: | |
| Open Quartus II. | |
| Navigate to File > New Project Wizard. | |
| Specify the working directory and project name (e.g., IoT_WeatherStation). | |
| For the device, select Cyclone II EP2C70F896C6. | |
| --- | |
| Step 2: Simulate Sensor Inputs Using Switches | |
| 1. Write VHDL Code to Simulate Sensors: | |
| Use the DE2-70 switches to represent temperature, humidity, and pressure sensors. | |
| Example VHDL Code: | |
| library IEEE; | |
| use IEEE.STD_LOGIC_1164.ALL; | |
| use IEEE.STD_LOGIC_ARITH.ALL; | |
| use IEEE.STD_LOGIC_UNSIGNED.ALL; | |
| entity SensorSimulator is | |
| Port ( | |
| SW : in STD_LOGIC_VECTOR (2 downto 0); -- Switch inputs | |
| TEMP : out STD_LOGIC_VECTOR (7 downto 0); -- Temperature | |
| HUMIDITY : out STD_LOGIC_VECTOR (7 downto 0); -- Humidity | |
| PRESSURE : out STD_LOGIC_VECTOR (7 downto 0) -- Pressure | |
| ); | |
| end SensorSimulator; | |
| architecture Behavioral of SensorSimulator is | |
| begin | |
| TEMP <= "00011001" when SW(0) = '1' else "00000000"; -- 25°C | |
| HUMIDITY <= "00110010" when SW(1) = '1' else "00000000"; -- 50% | |
| PRESSURE <= "01100101" when SW(2) = '1' else "00000000"; -- 101 kPa | |
| end Behavioral; | |
| 2. Compile the Code: | |
| Save the file as SensorSimulator.vhd. | |
| Add it to your Quartus project and compile. | |
| --- | |
| Step 3: Display Sensor Values on the LCD | |
| 1. Understand the LCD Module on DE2-70: | |
| The LCD has specific control signals (e.g., RS, E, DATA[7:0]). | |
| Refer to the DE2-70 manual for pin mappings. | |
| 2. Write VHDL Code for LCD Controller: | |
| Implement a driver to send data to the LCD. | |
| Example Code: | |
| library IEEE; | |
| use IEEE.STD_LOGIC_1164.ALL; | |
| use IEEE.STD_LOGIC_ARITH.ALL; | |
| use IEEE.STD_LOGIC_UNSIGNED.ALL; | |
| entity LCDController is | |
| Port ( | |
| CLK : in STD_LOGIC; -- Clock | |
| TEMP : in STD_LOGIC_VECTOR (7 downto 0); | |
| HUMIDITY : in STD_LOGIC_VECTOR (7 downto 0); | |
| PRESSURE : in STD_LOGIC_VECTOR (7 downto 0); | |
| LCD_DATA : out STD_LOGIC_VECTOR (7 downto 0); | |
| LCD_RS : out STD_LOGIC; | |
| LCD_E : out STD_LOGIC | |
| ); | |
| end LCDController; | |
| architecture Behavioral of LCDController is | |
| signal message : STD_LOGIC_VECTOR (23 downto 0); | |
| signal count : integer range 0 to 24 := 0; | |
| begin | |
| process(CLK) | |
| begin | |
| if rising_edge(CLK) then | |
| message <= TEMP & HUMIDITY & PRESSURE; -- Combine values | |
| LCD_DATA <= message(count * 8 + 7 downto count * 8); -- Send each byte | |
| count <= count + 1; | |
| if count = 3 then | |
| count <= 0; | |
| end if; | |
| LCD_RS <= '1'; -- Data mode | |
| LCD_E <= '1'; | |
| end if; | |
| end process; | |
| end Behavioral; | |
| 3. Compile and Test: | |
| Save this file as LCDController.vhd. | |
| Add it to your project and ensure compilation succeeds. | |
| --- | |
| Step 4: Implement UART Communication | |
| 1. Write UART Transmitter Module: | |
| Transmit sensor data via UART. | |
| Example Code: | |
| library IEEE; | |
| use IEEE.STD_LOGIC_1164.ALL; | |
| use IEEE.STD_LOGIC_ARITH.ALL; | |
| use IEEE.STD_LOGIC_UNSIGNED.ALL; | |
| entity UARTTransmitter is | |
| Port ( | |
| CLK : in STD_LOGIC; | |
| DATA : in STD_LOGIC_VECTOR (7 downto 0); | |
| TX : out STD_LOGIC | |
| ); | |
| end UARTTransmitter; | |
| architecture Behavioral of UARTTransmitter is | |
| signal baud_counter : integer := 0; | |
| signal tx_data : STD_LOGIC_VECTOR (9 downto 0); | |
| signal tx_index : integer range 0 to 9 := 0; | |
| signal sending : STD_LOGIC := '0'; | |
| begin | |
| process(CLK) | |
| begin | |
| if rising_edge(CLK) then | |
| if sending = '0' then | |
| tx_data <= '0' & DATA & '1'; -- Start + Data + Stop bits | |
| sending <= '1'; | |
| tx_index <= 0; | |
| elsif baud_counter = 5208 then -- Assuming 50 MHz clock for 9600 baud rate | |
| TX <= tx_data(tx_index); | |
| tx_index <= tx_index + 1; | |
| baud_counter <= 0; | |
| if tx_index = 9 then | |
| sending <= '0'; | |
| end if; | |
| else | |
| baud_counter <= baud_counter + 1; | |
| end if; | |
| end if; | |
| end process; | |
| end Behavioral; | |
| 2. Integrate UART with Sensor Data: | |
| Combine the UARTTransmitter with the SensorSimulator. | |
| 3. Test UART: | |
| Use a USB-UART adapter and a serial terminal to verify transmitted data. | |
| --- | |
| Step 5: Combine All Modules | |
| 1. Write Top-Level Module: | |
| Integrate SensorSimulator, LCDController, and UARTTransmitter. | |
| Example: | |
| library IEEE; | |
| use IEEE.STD_LOGIC_1164.ALL; | |
| entity WeatherStation is | |
| Port ( | |
| SW : in STD_LOGIC_VECTOR (2 downto 0); | |
| CLK : in STD_LOGIC; | |
| LCD_DATA : out STD_LOGIC_VECTOR (7 downto 0); | |
| LCD_RS : out STD_LOGIC; | |
| LCD_E : out STD_LOGIC; | |
| TX : out STD_LOGIC | |
| ); | |
| end WeatherStation; | |
| architecture Structural of WeatherStation is | |
| signal TEMP, HUMIDITY, PRESSURE : STD_LOGIC_VECTOR (7 downto 0); | |
| begin | |
| SensorSim : entity work.SensorSimulator | |
| Port map (SW => SW, TEMP => TEMP, HUMIDITY => HUMIDITY, PRESSURE => PRESSURE); | |
| LCDCtrl : entity work.LCDController | |
| Port map (CLK => CLK, TEMP => TEMP, HUMIDITY => HUMIDITY, PRESSURE => PRESSURE, | |
| LCD_DATA => LCD_DATA, LCD_RS => LCD_RS, LCD_E => LCD_E); | |
| UARTTx : entity work.UARTTransmitter | |
| Port map (CLK => CLK, DATA => TEMP, TX => TX); | |
| end Structural; | |
| 2. Compile and Generate Programming File: | |
| Click Processing > Start Compilation. | |
| Generate a .sof file. | |
| --- | |
| Step 6: Program the Board | |
| 1. Assign Pins: | |
| Open Assignments > Pin Planner. | |
| Map: | |
| SW[2:0] to the switches. | |
| LCD_DATA, LCD_RS, LCD_E to LCD pins. | |
| TX to UART TX pin. | |
| 2. Program the Board: | |
| Open Tools > Programmer. | |
| Load the .sof file and program your DE2-70 board. | |
| --- | |
| Step 7: Verify | |
| 1. Flip switches and observe: | |
| Correct sensor values on the LCD. | |
| Correct UART data on the serial terminal. | |
| 2. Debug any issues by revisiting individual modules. | |
| --- | |
| This guide ensures everything is covered. Let me know if you encounter any issues! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment