trafficproject.docx
《trafficproject.docx》由会员分享,可在线阅读,更多相关《trafficproject.docx(19页珍藏版)》请在冰豆网上搜索。
trafficproject
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
USEIEEE.STD_LOGIC_ARITH.ALL;
entityTLPis
Port(A,B,C,D,RS:
inSTD_LOGIC;--RSisourrunstop,PauseSwitch
K1,K2,K3:
INSTD_LOGIC;--WhenPedestrianbuttonispressed.transformintoKT
M1,M2,M3:
OUTSTD_LOGIC;--Bluelightsinsidepedestrianbutton
CLOCK:
inSTD_LOGIC;
L1,L2,L3:
OUTSTD_LOGIC_VECTOR(1DOWNTO0);--Pedestrianlights,redandgreen2bit
AL,AT,AR,BL,BT,BR,CT,CR,DT,DR:
outSTD_LOGIC_VECTOR(2DOWNTO0);--Thisisthesetof10trafficlights.3eachset.
SEG:
OUTSTD_LOGIC_VECTOR(6DOWNTO0);--7Segmentdisplay
BU:
OUTSTD_LOGIC;
PIG:
OUTSTD_LOGIC_VECTOR(3DOWNTO0);--Determineswhichdisplayison,MSBis0111,LSBis1110.
BUZOnOFF:
INSTD_LOGIC);--Over-rideswitchforbuzzer
endTLP;
architectureBehavioralofTLPis
COMPONENTClock_ManagerIS
PORT(TT:
INTEGERRANGE0TO30;--Allowustocountbackwardsindisplay,TT=DurationofFlow-T
F:
INTEGERRANGE0TO30;--Integertoderminewhichflowweareinfor7segDisplayraninClock_Manager
CLK:
inSTD_LOGIC;
MSec:
outSTD_LOGIC;
Sec:
outSTD_LOGIC;
BU:
OUTSTD_LOGIC;--DeterminesifBuzzerison,1ison0isoff
SEG:
OUTSTD_LOGIC_VECTOR(6DOWNTO0);--SEGandPIGdefinedthroughclock,whichwilllooktotheeyeasifitis
PIG:
OUTSTD_LOGIC_VECTOR(3DOWNTO0);--changingatthesametime(atfastfrequency).
BUZOnOFF:
INSTD_LOGIC);--Over-rideswitchforbuzzer
ENDCOMPONENT;
SIGNALCLK1,CLK2:
STD_LOGIC;
SIGNALM:
STD_LOGIC_VECTOR(3DOWNTO0);--4Sensors,Switches.
SIGNALK:
STD_LOGIC:
='1';--Wheneachflowfinishweenternextflowgivenk='1'.
SIGNALKT:
STD_LOGIC_VECTOR(2DOWNTO0):
="000";--Pedestrianbutton3bit."000"isOff
SIGNALT,F,TT:
INTEGERRANGE0TO30;--Thisistokeeptrackoftimerforclockedges.(maxis22,withyellowandred).
SIGNALLIGHT:
STD_LOGIC_VECTOR(29DOWNTO0);--TrafficLights(30lights,10setsof3each)
TYPESTATEIS(F1,F2,F3,F4,F5,F6,F7);--7Differentflowstates.
SIGNALSTATE_M:
STATE;
--GROUPCODE
BEGIN
M<=A&B&C&D;--4SensorsA:
Pymble,B:
Waste,C:
Ryde,D:
Macquarie
CLKM:
CLOCK_MANAGER--Clock
PORTMAP(TT,F,CLOCK,CLK1,CLK2,BU,SEG,PIG,BUZonOFF);
traffic:
PROCESS(CLK2)
BEGIN
--ChecksifBuzzeristurnedon(Alextype)
IF(K1='0'ORK2='0'ORK3='0')THEN--WhenpedestrianbuttonispressedNegativelogic
IFK1='0'THEN--Macquarie
KT
(2)<='1';--Firstbit-MSB-inKTisMacquarie
IFKT
(1)='1'THENKT
(1)<='1';ENDIF;--Weusethistoholdthelightsignalonwhenotherpedestrianlightisturnedon.
IFKT(0)='1'THENKT(0)<='1';ENDIF;
ENDIF;
IFK2='0'THEN--Pymble
KT
(1)<='1';--2ndbitinKTisPymble
IFKT
(2)='1'THENKT
(2)<='1';ENDIF;
IFKT(0)='1'THENKT(0)<='1';ENDIF;
ENDIF;
IFK3='0'THEN--Waste
KT(0)<='1';--Lastbit-LSB-inKTisMacquarie
IFKT
(1)='1'THENKT
(1)<='1';ENDIF;
IFKT
(2)='1'THENKT
(2)<='1';ENDIF;
ENDIF;
ELSE--Werequirethiscodetoleavelightsignalonwithouthavingtopressdownonit.
IF(KT
(2)='1'AND((K='0')OR(K='1'AND(STATE_M=F2ORSTATE_M=F3ORSTATE_M=F4ORSTATE_M=F5ORSTATE_M=F7))))
THENKT
(2)<='1';ENDIF;
IF(KT
(1)='1'AND((K='0')OR(K='1'AND(STATE_M=F1ORSTATE_M=F3ORSTATE_M=F4ORSTATE_M=F5ORSTATE_M=F6ORSTATE_M=F7))))
THENKT
(1)<='1';ENDIF;
IF(KT(0)='1'AND((K='0')OR(K='1'AND(STATE_M=F1ORSTATE_M=F3ORSTATE_M=F4ORSTATE_M=F5ORSTATE_M=F6ORSTATE_M=F2))))
THENKT(0)<='1';ENDIF;ENDIF;
IF(RS='1')THEN
IF(ClK2='1'ANDCLK2'event)THEN
T<=T+1;--Keeptrackoftiming.
IFK='1'THEN--Don'tenternextflowwithoutcompletingperviouswhenK='0'.
T<=0;--Whenenterknewflowresettimer.
IF(KT="000")THEN--Nopedestrianbuttonpressedgointonormalflow
--GroupCodeDiscuss:
TimCode
--Thefollowingcodedetermineswhichsensorsequenceison.Thendetermineswhichflowprocesstofollow.
IFM="0000"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="0001"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F2;
WHENF2=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="0100"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F3;
WHENF3=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="1010"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F4;
WHENF4=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="1000"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F5;
WHENF5=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="0010"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F6;
WHENF6=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="0101"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F2;
WHENF2=>STATE_M<=F3;
WHENF3=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="1011"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F2;
WHENF2=>STATE_M<=F4;
WHENF4=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="1001"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F2;
WHENF2=>STATE_M<=F5;
WHENF5=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="0011"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F2;
WHENF2=>STATE_M<=F6;
WHENF6=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="1110"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F3;
WHENF3=>STATE_M<=F4;
WHENF4=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="1100"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F3;
WHENF3=>STATE_M<=F5;
WHENF5=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="0110"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F3;
WHENF3=>STATE_M<=F6;
WHENF6=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="1111"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F2;
WHENF2=>STATE_M<=F3;
WHENF3=>STATE_M<=F4;
WHENF4=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="1101"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F2;
WHENF2=>STATE_M<=F3;
WHENF3=>STATE_M<=F5;
WHENF5=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ELSIFM="0111"THEN
CASESTATE_MIS
WHENF1=>STATE_M<=F2;
WHENF2=>STATE_M<=F3;
WHENF3=>STATE_M<=F6;
WHENF6=>STATE_M<=F1;
WHENOTHERS=>STATE_M<=F1;
ENDCASE;
ENDIF;
ELSIFKT
(2)='1'THEN--Flow6alsoavailablehoweverchooseF1foroptimization,ForMacquarie
STATE_M<=F1;
ELSIFKT
(1)='1'THEN
STATE_M<=F2;--ForPymble
ELSIFKT(0)='1'THEN
STATE_M<=F7;--Forwaste
ENDIF;
ENDIF;
ENDIF;
ENDIF;
--Wenowdefinewhateachflowdoeswhenweenterthatflow.
----------ALEXCODE
IFSTATE_M=F1THEN
F<=1;--Determinetheflowforsegment
TT<=22-T;--TTisrequiredtocountbackwards
IFT<21THEN
LIGHT<="001001100100100100001100100100";
K<='0';
ELSIFT=21THEN
LIGHT<="010010100100100100010100100100";
K<='0';
ELSIFT=22THEN
LIGHT<="100100100100100100100100100100";
K<='1';
KT
(2)<='0';--Turnoffpedlightonceflowisdone
ENDIF;
----------TIMCODE
ELSIFSTATE_M=F2THEN
F<=2;
TT<=9-T;
IFT<7THEN
LIGHT<="100100100100100100100100001001";
K<='0';
ELSIFT=8THEN
LIGHT<="100100100100100100100100010010";
K<='0';
ELSIFT=9THEN
LIGHT<="100100100100100100100100100100";
K<='1';
KT
(1)<='0';--Turnoffpedlightonceflowisdone
ENDIF;
----------NANCODE
ELSIFSTATE_M=F3THEN
TT<=7-T;
F<=3;
IFT<5THEN
LIGHT<="100100100001001001100100100100";
K<='0';
ELSIFT=6THEN
LIGHT<="100100100010010010100100100100";
K<='0';
ELSIFT=7THEN
LIGHT<="100100100100100100100100100100";
K<='1';
ENDIF;
----------LENACODE
ELSIFSTATE_M=F4THEN
TT<=9-T;
F<=4;
IFT<7THEN
LIGHT<="100100001100100100100001100100";
K<='0';
ELSIFT=8THEN
LIGHT<="100100010100100100100010100100";
K<='0';
ELSIFT=9THEN
LIGHT<="100100100100100100100100100100";
K<='1';
ENDIF;
----------COCOCODE
ELSIFSTATE_M=F5THEN
TT<=9-T;
F<=5;
IFT<7THEN
LIGHT<="001001001100100100100100100100";
K<='0';
ELSIFT=8THEN
LIGHT<="001001010100100100100100100100";
K<='0';
ELSIFT=9THEN
LIGHT<="001001100100100100100100100100";
K<='1';
ENDIF;
----------TEAMCODE
ELSIFSTATE_M=F6THEN
TT<=9-T;
F<=6;
IFT<7THEN
LIGHT<="100100100100100100001001100100";
K<='0';
ELSIFT=8THEN
LIGHT<="100100100100100100001010100100";
K<='0';
ELSIFT=9THEN
LIGHT<="100100100100100100001100100100";
K<='1';
ENDIF;
----------TEAMCODE--Thisflowisforpedestriantowalkalong'Waste'
ELSIFSTATE_M=F7THEN
TT<=9-T;
F<=7;
IFT<7THEN
LIGHT<="100001001100100100100100100100";
K<='0';
ELSIFT=8THEN
LIGHT<="100010010100100100100100010100";
K<='0';
ELSIFT=9THEN
LIGHT<="100100100100100100100100100100";
K<='1';
KT(0)<='0';--Turnoffpedlightonceflowisdone
ENDIF;
ENDIF;
ENDPROCESStraffic;
--Seteachsetoflightsusingour30bitLight
----------TEAMCODE
AL<=LIGHT(29)&LIGHT(28)&LIGHT(27);
AT<=LIGHT(26)&LIGHT(2