Академический Документы
Профессиональный Документы
Культура Документы
Samuel Magana
CPE 133 - 01
Final Project
This guide will show how to implement an Alarm Clock using only a FPGA board. This project
was designed by Samuel Magana and Nicholas Alcazar for the CPE 133 course at Cal Poly San
Luis Obispo headed by Hummel. This alarm clock has functionality for: setting the current time,
setting the alarm time, arming or disarming the alarm, and snoozing the alarm. When the alarm
is activated, a game activates in order to stop the alarm. The goal of the game is the flip the
switches which correspond to the pattern of LEDs that light up. Pressing snooze will add 10
minutes to the alarm time and cancel the game.
Materials:
Basys 3 Xilinx Artix-7 FPGA (XC7A35T-ICPG236C)
Computer: Vivado HLx 2016.2
All the logic for the Alarm Clock takes place on the FPGA board. The Top level box diagram for
the alarm clock has 8 inputs and 6 outputs. The board uses 2 switches to set either the time or
the alarm and another switch to arm the alarm. The board also used 8 switches for the alarm
game. The board uses three of the buttons. Two of these buttons are used when setting the
time and the other button is used as the snooze. 11 of the LEDs on the board were used. 3 of
the LEDs were used to show what mode the alarm clock was in and the other 8 LEDs were
used for the alarm game. Lastly, there are a 4 bit bus and a 7 bit bus used to power the 4 digit 7
segment display on the board.
Step 3: Submodules
indicate if youre setting the alarm time), LEDBUS[7:0] (the bus of 8 LEDs used in the alarm
game), and O[15:0] (the value of alarm time pushed to the display).
Source Code:
-------------------------------------------------- DISPLAY_CLOCK MAIN MODULE
------------------------------------------------entity Digital_CLock is
Port ( CLK : in STD_LOGIC;
BHR :in STD_LOGIC;
BMIN :in STD_LOGIC;
SWITCH : in STD_LOGIC;
LEDSET : out STD_LOGIC;
LEDBUS :out STD_LOGIC_VECTOR (7 downto 0);
LEDGAME : in STD_LOGIC_VECTOR(7 downto 0);
LEDALARMSET : out STD_LOGIC;
LEDALARMON : out STD_LOGIC;
SNOOZEBUTTON : in STD_LOGIC;
ARM : in STD_LOGIC;
SETA : in STD_LOGIC;
D : out STD_LOGIC_VECTOR (3 downto 0);
O : out STD_LOGIC_VECTOR (6 downto 0));
end Digital_CLock;
architecture Behavioral of Digital_CLock i s
-------------------------------------------------- SUBMODULES COMPONENTS
-------------------------------------------------- CLOCK
component Time_mod Port (
BHR : in STD_LOGIC;
BMIN : in STD_LOGIC;
CLK : in STD_LOGIC;
LEDSET : out STD_LOGIC;
O : out STD_LOGIC_VECTOR ( 15 downto 0);
-- SETIN : in STD_LOGIC_VECTOR (15 downto 0);
switch : in STD_LOGIC);
end component;
-- ALARM FUNCTIONALITY
component alarm port(
CLK : in STD_LOGIC;
SETA : in STD_LOGIC;
BMIN : in STD_LOGIC;
BHR : in STD_LOGIC;
SNOOZEBUTTON : in STD_LOGIC;
SETTIME : in STD_LOGIC;
ARM : in STD_LOGIC;
currtime :in STD_LOGIC_VECTOR (15 downto 0);
O : out STD_LOGIC_VECTOR (1
5 downto 0);
LEDBUS :out STD_LOGIC_VECTOR (7 downto 0);
LEDGAME : in STD_LOGIC_VECTOR(7 downto 0);
LEDALARMSET : out STD_LOGIC;
-- LEDALARMR : out STD_LOGIC; -- rining alarm
LEDALARMON : out STD_LOGIC);
end component;
-- Display Selector
component MUXO Port ( ALARM : in STD_LOGIC_VECTOR (15 downto 0);
TIMEO : in STD_LOGIC_VECTOR (15 downto 0);
selector : in STD_LOGIC;
toDisp : out STD_LOGIC_VECTOR (15 downto 0));
end component;
-- Display Driver
component Display port(
CLK : in STD_LOGIC;
I : in STD_LOGIC_VECTOR (1
5 downto 0);
O : out STD_LOGIC_VECTOR (6
downto 0);
D : out STD_LOGIC_VECTOR (3 downto 0));
end component;
-------------------------------------------------- SIGNALS BETWEEM MODULES
------------------------------------------------signal DCLK : STD_LOGIC_VECTOR( 15 downto 0);
signal SETS: STD_LOGIC_VECTOR( 15 downto 0);
signal ALARMO : STD_LOGIC_VECTOR( 15 downto 0);
signal DisplayIN : STD_LOGIC_VECTOR( 15 downto 0);
begin
-------------------------------------------------- PORTMAPS
------------------------------------------------clock: time_mod port map( LEDSET=> LEDSET, O=>DCLK, CLK => CLK, SWITCH =>
SWITCH,BHR=>BHR,BMIN=>BMIN);
Driver: Display port map( CLK =
> CLK,I => DISPLAYIN , O => O, D=>D);
ALARMFUNC: ALARM port map(LEDBUS =>LEDBUS, SETTIME => SWITCH, LEDGAME =
>
LEDGAME, BHR=>BHR,BMIN=>BMIN, SETA => SETA ,SNOOZEBUTTON => snoozebutton,
ARM => ARM, CURRTIME => DCLK,O=>ALARMO,
CLK =>CLK);
todisplay: MUXO port map( TIMEO => DCLK, ALARM => ALARMO, selector => SETA, toDisp
=> DisplayIN);
end Behavioral;
-------------------------------------------------- SUNMODULE: CLOCK (hold, increment, and set the current time)
------------------------------------------------entity Time_mod is
Port ( CLK : in STD_LOGIC;
BHR: in STD_LOGIC;
BMIN : in STD_LOGIC;
LEDSET : out STD_LOGIC;
O : out STD_LOGIC_VECTOR (15 downto 0);
switch : in STD_LOGIC);
end Time_mod;
architecture Behavioral of Time_mod is
signal clock_one_hz : STD_LOGIC := '0';
signal m_1, m_10, h_1 : STD_LOGIC_VECTOR (3 downto 0);
signal h_10 : STD_LOGIC_VECTOR (2 downto 0);
signal am_pm : STD_LOGIC;
signal tmp : STD_LOGIC_VECTOR (15 downto 0);
--signal button :std_logic;
begin
-- convert 100Mhz to 1 hz
clock_conv: process (CLK) is
variable count: unsigned (24 downto 0) :="0000000000000000000000000";
-- variable countB: unsigned (25 downto 0) :="00000000000000000000000000";
begin
if (rising_edge(CLK)) THEN
count := count + 1;
--countB := countB +1;
if (count > 12500000) THEN
--50000000 (5 is used for simulation purposes)
clock_one_hz <= not clock_one_hz;
count := "0000000000000000000000000";
end if;
end if;
end process clock_conv;
else
if ( hours_1 > 9 ) THEN
hours_10 := "001";
hours_1 := "0000";
end if;
end if;
end if;
else
LEDSET <= '0';
sec := sec + 1;
if ( sec > 240 ) THEN
sec := "00000000";
mins_1 := mins_1 + 1;
end if;
if(bhr = '1') THEN
hours_1 := hours_1 + 1;
if ( (hours_1 = 2) AND (hours_10 = 1) ) THEN
am := not am;
end if;
if ( hours_10 > 0 ) THEN
if (hours_1 > 2) THEN
hours_1 := "0001";
hours_10 : = "000";
end if;
else
if ( hours_1 > 9 ) THEN
hours_10 := "001";
hours_1 := "0000";
end if;
end if;
end if;
else
LEDALARMSET <= '0';
end if;
-------------------------------------------------- SNOOZEBUTTON FUNCTIONALITY INCREMENTS SET ALARM TIME BY 10 MINS
------------------------------------------------If(SNOOZEBUTTON = '1') THEN
if(arm = '1') THEN
mins_10 := mins_10 +1;
if ( mins_10 > 5 ) THEN
mins_10 := "0000";
hours_1 := hours_1 + 1;
if ( (hours_1 = 2) AND (hours_10 = 1) ) THEN
am := not am;
end if;
if ( hours_10 > 0 ) THEN
if (hours_1 > 2) THEN
hours_1 := "0001";
hours_10 := "000";
end if;
else
if ( hours_1 > 9 ) THEN
hours_10 := "001";
hours_1 := "0000";
end if;
end if;
end if;
end if;
end if;
end if;
--end if;
--end if;
end process alarm;
alarmOFF: process (clock_one_hz,currtime,ARM, snoozebutton,LEDGAME) is
variable count : unsigned (1 downto 0) := "00";
begin
-------------------------------------------------- LED "GAME" USES SECOND CLOCK 'CLOCKW' TO 'RANDOMLY' CHOOSE FROM THE 4
CASES
-- COUNTER STOPS INCREMENTING WHEN ARM = '1'
------------------------------------------------if(rising_edge(clockw)) THEN
If(arm = '1') THEN
count := count;
else
count := count + 1;
end if;
if(rising_edge(clock_one_hz)) THEN
if(arm = '1') THEN
LEDALARMON <='1';
if(count = 0 and (alarmtime = currtime)) THEN
LEDBUS(0) <= '1';
LEDBUS(2) <= '1';
LEDBUS(6) <= '1';
LEDBUS(7) <= '1';
if((LEDGAME(0) = '1' and LEDGAME(2) = '1' and LEDGAME(6) = '1' and LEDGAME(7)=
'1' ) or SNOOZEBUTTON = '1' ) THEN
LEDBUS(0) <= '0';
LEDBUS(2) <= '0';
LEDBUS(6) <= '0';
LEDBUS(7) <= '0';
end if;
elsif(count = 1 and (alarmtime = currtime) ) THEN
LEDBUS(1) <= '1';
end if;
end process clockd;
end Behavioral;
----------------------------------------------- DISPLAY SELECTOR(BETWEEN ,SET TIME, SET ALARM TIME AND CURRENT TIME)
--------------------------------------------entity MUXO is
Port ( ALARM : in STD_LOGIC_VECTOR (15 downto 0);
TIMEO : in STD_LOGIC_VECTOR (15 downto 0);
selector : in STD_LOGIC;
toDisp : out STD_LOGIC_VECTOR (15 downto 0));
end MUXO;
architecture Behavioral of MUXO is
-- selects output of cuRrent time and clock set and SET ALARM TIME
begin
display: process(selector) is
begin
if(selector = '1') THEN
toDisp <= alarm;
else
todisp <= timeO;
end if;
end process display;
end Behavioral;