B+AC=o B(A+D) B(A+D)=1 图1-5-2状态转换图 将表1-5-2中Q、Q2"的“1”项按最小项之和的形式写出,并化简即得状态方程为 Q2=g2"EQ"+(Q"+E)Q2 Q=g"2"B(A+C)+Q"Q2"+B(A+D) 所以,两JK触发器的驱动方程为 J1=Q2"B(A+C),K1=Q2+B(A+D) E0,, K=0+E 45S、25S、5S定时器CP脉冲驱动方程为 CP5=[Q2Q(4+B)+Q2QE]CP脉冲 CP2=[Q2Q1B+②2QE]CP脉冲 P=[Q1⊕Q2]CP脉冲 则主控电路和各定时电路如图1-5-3所示。 120
S0 S1 S2 S3 B + AC = 1 E = 0 E = 1 B(A + D) =1 B(A + D) = 0 E = 0 E = 1 B + AC = 0 图 1-5-2 状态转换图 将表 1-5-2 中Q2 n+1、 Q1 n+1的“1”项按最小项之和的形式写出,并化简即得状态方程为 n n n n n Q Q2 EQ1 Q1 E Q2 1 2 = + ( + ) + ( ) [ ( )] 1 2 1 2 1 Q1 Q Q B A C Q Q B A D n n n n n = + + + + + 所以,两 JK 触发器的驱动方程为 ( ) J1 Q2 B A C n = + , ( ) K1 Q2 B A D n = + + n J 2 = EQ1 , K Q E n 2 = 1 + 45S、25S、5S 定时器 CP 脉冲驱动方程为 CP45 = [Q2Q1 (A + B) + Q2Q1E]CP脉冲 CP25 = [Q2Q1B + Q2Q1E]CP脉冲 CP5 = [Q1 ⊕ Q2 ]CP脉冲 则主控电路和各定时电路如图 1-5-3 所示。 120
P5 25 45秒计时 25秒计时 5秒计时 CP CP Q1 Q2 C1 C1 IK 1K CP 图1-5-3交通灯控制器主控电路 图1-5-3中,各计数器驱动脉冲如图1-5-4所示。 设主干道红、黄、绿三色灯为R1、Y1、G1,支干道红、黄、绿三色灯为R2、Y2、G2, 信号灯显示的真值表如表1-4-5所列 121
图 1-5-3 交通灯控制器主控电路 图 1-5-3 中,各计数器驱动脉冲如图 1-5-4 所示。 设主干道红、黄、绿三色灯为R1、Y1、G1,支干道红、黄、绿三色灯为R2、Y2、G2, 信号灯显示的真值表如表 1-4-5 所列。 121
≥ B & & CP CP Q2 C1 1K 1K 图1-5-4计数器驱动脉冲电路图 表1-5-3译码驱动电路真值表 Q2 QIR 0000 100 0 1000 00 001 010 所以,表达式为 R1=Q2,R2=Q2 Y=0122, Y,=2103 G,=2102 022 译码驱动电路如图1-5-5所示
图 1-5-4 计数器驱动脉冲电路图 表 1-5-3 译码驱动电路真值表 Q2 Q1 R1 Y1 G1 R2 Y2 G2 0 0 1 1 0 0 0 1 0 1 0 0 0 0 0 1 1 1 1 0 1 0 0 0 0 1 1 0 0 0 1 0 所以,表达式为 R1 = Q2, R2 = Q2 Y1 = Q1Q2 ,Y2 = Q1Q2 G1 = Q1Q2 ,G2 = Q2Q1 译码驱动电路如图 1-5-5 所示。 122
1] C1 C1 1K K2 1K 图1-5-5交通灯译码驱动电路 此例也可以完全由 Verilog hdl文件完成,参考代码为 traffic(clk, enb, ared, agreen, ayellow, bred, bgreen, byellow, acounth, acount, bcounth, bcountl) output[ 3: 0] acounth, acount, bcounth, bcountl output ared, agreen, ayellow, bred, bgreen, byellow: bellow: reg3: 0] acounth, acount, bcounth, bcountl iffacounth, acount==o bcounth, bcountl==0) case((ared, agreen, ayellow, bred, breen, byellow)) 6 b010100: begin(ared, agreen, ayellow, bred, green, bellow)<=6'b001100; acount=5; acount h=0 bcountl=5: bcounth=0: end 6b00l100:if (enb )begin(ared, agreen, ayellow, bred, bgreen, byellow)<=6'b100010; acount=0; acount=3; bcoun tI=5 bcounth=2: end begin (ared, agreen, ayellow, bred, green, byellow)<=6 b010100 acount=5; acounth=4; bcountl=0 bcounth=5: end 6'b100010: begin(ared, agreen, ayellow, bred, bgreen, bellow <=6'b100001; acount=5; acount 123
图 1-5-5 交通灯译码驱动电路 此例也可以完全由 Verilog HDL 文件完成,参考代码为: module traffic(clk,enb,ared,agreen,ayellow,bred,bgreen,byellow,acounth,acountl,bcounth,bcountl); output[3:0] acounth,acountl,bcounth,bcountl; output ared,agreen,ayellow,bred,bgreen,byellow; input clk,enb; reg ared,agreen,ayellow,bred,bgreen,byellow; reg[3:0] acounth,acountl,bcounth,bcountl; always@(posedge clk) begin if({acounth,acountl}==0||{bcounth,bcountl}==0) // case({ared,agreen,ayellow,bred,bgreen,byellow}) 6'b010100:begin{ared,agreen,ayellow,bred,bgreen,byellow}<=6'b001100;acountl=5;acount h=0;bcountl=5;bcounth=0; end 6'b001100:if (enb)begin{ared,agreen,ayellow,bred,bgreen,byellow}<=6'b100010;acountl=0;acounth=3;bcoun tl=5;bcounth=2;end else begin{ared,agreen,ayellow,bred,bgreen,byellow}<=6'b010100;acountl=5;acounth=4;bcountl=0; bcounth=5; end 6'b100010:begin{ared,agreen,ayellow,bred,bgreen,byellow}<=6'b100001;acountl=5;acount 123
h=0 bcountl=5: bcounth=0: end 6'b100001: begin(ared, agreen, ayellow, bred, green, bellow)<=6'b010100 acount=5 acount=4 bcountl=0: bcounth=5: end default: begin(ared, agreen, ayellow, bred, breen, bellow)<=6 b010100; acount=5 4 bcountl=0: bcounth=5: end encase begin if(acount==0) acount=acounth-1 acount=4'b100 Acorn bcounthbcounth-1 bcountl=4'b1001 ocountlbcountl-1 endmodule 顶层gdf文件如图1-5-6所示,其中sel为扫描显示模块,电路下载后,硬件系统示意 图如图1-5-7所示。 支千道 主千道 绿黄红绿黄红 ○○○○○ Ms4 Ms3 Ms2 Ms1 1 FPGA/CPLD 主干道计时支千道计时 黑1Z clk A B K1|E2 图1-5-7具有三种信号灯的交通灯控制器硬件系统示意图 124
h=0;bcountl=5;bcounth=0;end 6'b100001:begin{ared,agreen,ayellow,bred,bgreen,byellow}<=6'b010100; acountl=5;acounth=4;bcountl=0;bcounth=5; end default:begin{ared,agreen,ayellow,bred,bgreen,byellow}<=6'b010100;acountl=5;acounth= 4;bcountl=0;bcounth=5; end endcase // else begin if(acountl==0) begin acounth=acounth-1; acountl=4'b1001; end else acountl=acountl-1; if(bcountl==0) begin bcounth=bcounth-1; bcountl=4'b1001; end else bcountl=bcountl-1; end end endmodule 顶层 gdf 文件如图 1-5-6 所示,其中 sel 为扫描显示模块,电路下载后,硬件系统示意 图如图 1-5-7 所示。 124 图 1-5 6 具有三种信号灯的交通灯控制器顶层 gdf 文件图 图 1-5-7 具有三种信号灯的交通灯控制器硬件系统示意图