Interfacimg Programs-1
Interfacimg Programs-1
module upordown_counter(
Clk,
reset,
UpOrDown,
Count
);
input Clk, reset, UpOrDown;
output [3 : 0] Count;
reg [3 : 0] Count = 0;
endmodule
BDC DOUNTER:
assign bcd_out=temp;
always@(posedge clk)
begin if(rst)
begin temp<=4'b0000;
end
else
begin
temp<=temp+1'b1;
if(temp==4'b1001)
temp<=4'b0000;
end
end
endmodule
DEMONSTRATION EXPERIMENTS:
UCF FILE
NET "clk" LOC = p56;
NET "dir[0]" LOC = p124;
NET "dir[1]" LOC= p123;
NET "d_out[0]" LOC = p29;
NET "d_out[1]" LOC = p30;
NET "d_out[2]" LOC = p32;
NET "d_out[3]" LOC = p33;
Result: A Stepper Motor is interfaced to the FPGA Kit and the changes in speed and direction is
observed accordingly.
LED BLINKING:
module blink_LED (
input clk, // Clock input
output reg led // Output for the LED
);
endmodule
UCF:
NET "led" LOC = P98;
NET "clk" LOC = P56;
ADDITIONAL PROGRAMS:
Aim: Interface a DC motor to FPGA and write Verilog code to change its speed and direction.
Design Code:
module DC_MOTOR(clk,dir,speed,P_DCMEN,P_DCM);
input clk,dir;
input [1:0]speed;
output reg P_DCMEN;
output reg [1:0] P_DCM ;
reg [32:0] clk_div = 33'd0;
always@(posedge clk)
clk_div = clk_div + 1;
always@(clk_div)
begin
if (speed == 2'b00) P_DCMEN = clk_div[2];
if (speed == 2'b01) P_DCMEN = clk_div[4];
if (speed == 2'b10) P_DCMEN = clk_div[8];
if (speed == 2'b11) P_DCMEN = clk_div[16];
end
always@(clk_div)
begin
if (dir == 0)
P_DCM = 2'b01;
else
P_DCM = 2'b10;
end
endmodule
UCF:
NET "P_DCM[0]" LOC = P82;
NET "P_DCM[1]" LOC = P83;
NET "P_DCMEN" LOC = P84;
NET "dir" LOC = P121 ;
NET "speed(0)" LOC = P123;
NET "speed(1)" LOC =P124;
NET "clk" LOC = P56;
Result: A DC Motor is interfaced to the FPGA Kit and the changes in speed and direction is observed
accordingly.
ADDITIONAL EXPERIMENTS:
module D_FF(q,d,clk,reset);
output q;
input clk,reset,d;
reg q;
always@(posedge reset or negedge clk)
begin
if(reset)
q =1'b0;
else
q =d;
end
endmodule
TEST BENCH CODE:
module tb;
// Inputs
reg clk;
reg reset;
// Outputs
wire [3:0] q;
// Instantiate the Unit Under Test (UUT)
cnrt uut (.clk(clk), .reset(reset), .q(q));
initial begin
// Initialize Inputs
clk = 1'b1;
forever #5 clk =~clk;
end
initial
begin
reset = 1'b1;
#15 reset = 1'b0;
#180 reset = 1'b1;
#10 reset = 1'b0;
end
endmodule
EXPECTED WAVEFORM:
OUTPUT WAVEFORM
Output Waveform: