Tuesday, 31 March 2015

D FLIPFLOP



Behavioral :

module Dfp(d,clk,q,q1 );
input d,clk;
output reg q,q1;
always@(clk or d) begin
if (d<=1'b0) begin
q=1'b0;q1=1'b1;
end
else if (d<=1'b1) begin
q=1'b1;q1 =1'b0;
end
end
endmodule

Here i considered reset as q=0 (low)
                                        q1=1 (high)

&
Set  as q=1
          q1=0.

RTL schematic :

Test bench wave form :


<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-66283941-1', 'auto');
  ga('send', 'pageview');

</script>

Tuesday, 6 January 2015

Verilog code for 3x8 decoder using enable

behavioral :

module dec_3x8(a,b,c,en,d
    );
input a,b,c,en;
output reg [0:7] d;
reg a0,b0,c0;
always @(a or b or c or en) begin
a0=~a;
b0=~b;
c0=~c;
d[0]=a0&b0&c0&en;
d[1]=a0&b0&c&en;
d[2]=a0&b&c0&en;
d[3]=a0&b&c&en;
d[4]=a&b0&c0&en;
d[5]=a&b0&c&en;
d[6]=a&b&c0&en;
d[7]=a&b&c&en;
end

endmodule

SCHEMATIC: 
FIGURE:


TIMING SCALE:


<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-66283941-1', 'auto');
  ga('send', 'pageview');

</script>

verilog code for 8x1 mux

Behavioral code:

module mx8x1(a1,b1,c1,e0,e1,e2,e3,e4,e5,e6,e7,out
    );
input a1,b1,c1,e0,e1,e2,e3,e4,e5,e6,e7;
output reg out;
reg a0,b0,c0,d0,d1,d2,d3,d4,d5,d6,d7;
always @(a1 or b1 or c1) begin
a0=~a1;
b0=~b1;
c0=~c1;
d0=e0&a0&b0&c0;
d1=e1&a0&b0&c1;
d2=e2&a0&b1&c0;
d3=e3&a0&b1&c1;
d4=e4&a1&b0&c0;
d5=e5&a1&b1&c1;
d6=e6&a1&b1&c0;
d7=e7&a1&b1&c1;
out=d0||d2||d3||d4||d5||d6||d7;
end

endmodule

Monday, 10 March 2014

verilog code for 1 bit full adder

BEHAVIORAL:

module flad(
    input a,
    input b,
    input Cin,
    output reg sum,
    output reg Cout
    );
reg s1,s2,s3;
always@(a or b or Cin) begin
s1=a^b;
s2=a&b;
s3=s1&Cin;
Cout=s3||s2;
sum=s1^Cin;
end

endmodule


Tuesday, 4 March 2014

Verilog code for halfadder


module half(
    input a,
    input b,
    output sum,
    output Cout
    );
reg sum,Cout;
always @(a or b) begin
sum=a^b;
Cout=a&b;
end;
endmodule

schematic:



Wednesday, 12 February 2014

verilog hdl code for 4x2 parity encoder

module par(d1,d2,d3,y1,y2);
input d1,d2,d3;
output y1,y2;
reg y1,y2;
reg s1;
always @(d1 or d2 or d3) begin
s1=~d2;
y1=d1||d2;
y2=d3||(s1&d1);
end
endmodule

Tuesday, 11 February 2014

1x4 demultiplexer

BEHAVIORAL:

module dem(Din,s1,s2,y);
input Din,s1,s2;
output[3:0] y;
reg s3,s4;
reg[3:0] y;
always@(Din) begin
s3=~s1;
s4=~s2;
y[0]=Din&s3&s4;
y[1]=Din&s3&s2;
y[2]=Din&s1&s4;
y[3]=Din&s1&s2;
end
endmodule