Showing posts with label Electronics. Show all posts
Showing posts with label Electronics. Show all posts

Sunday, August 11, 2013

DIGILENT Basys2 Simple Seven Segment Timer project using Verilog

Hello everyone, This a simple timer i designed using the DIGILENT-Basys2. This module start counting the time at the point of reset and keeps on counting.  I used Xilinx ISE design suite 14.5 for generating the bit file. Here is my verilog code and .ucf file.

Verilog Code

module clock1(
input reset,clock,
output [7:0] ss,
output [3:0] anode
    );
   
//timing
reg [25:0] counter;
reg [7:0] temps;
reg [3:0] an;
reg [3:0] d0;
reg [3:0] d1;
reg [3:0] d2;
reg [3:0] d3;
reg [3:0] num;
initial d0=4'b0000;
initial d1=4'b0000;
initial d2=4'b0000;
initial d3=4'b0000;

always@(posedge clock or posedge reset)
begin
   
    if(reset)
    counter<=0;
    else if(counter==50000000) begin
        counter<=0;
        if(d0==9) begin
            d0<=0;
            if(d1==5) begin
                d1<=0;
                if(d2==9) begin d2<=0;
                    if(d3==9) begin d3<=0;d2<=0;d1<=0;d0<=0;end
                    else d3<=d3+1;
                end
                else d2<=d2+1;
                end
            else d1<=d1+1;
           
        end
        else d0<=d0+1;
       
       
    end
    else
    counter<=counter+1;
end

reg [18:0] sync;

always@(posedge clock or posedge reset)
begin
    if(reset)
    sync<=0;
    else
    sync<=sync+1;

   
end

always@(*)
begin
    if(sync[18:17]==2'b00) begin
    an<=4'b1110;num<=d3; end
    else if(sync[18:17]==2'b01) begin
    an<=4'b1101;num<=d2; end
    else if(sync[18:17]==2'b10) begin
    an<=4'b1011;num<=d1; end
    else begin
    an<=4'b0111;num<=d0; end
end


always@(*)
begin
case(num)
4'b0000 : temps=~(8'b00111111);
4'b0001 : temps=~(8'b00000110);
4'b0010 : temps=~(8'b01011011);
4'b0011 : temps=~(8'b01001111);
4'b0100 : temps=~(8'b01100110);
4'b0101 : temps=~(8'b01101101);
4'b0110 : temps=~(8'b01111101);
4'b0111 : temps=~(8'b00000111);
4'b1000 : temps=~(8'b01111111);
4'b1001 : temps=~(8'b01100111);
4'b1010 : temps=~(8'b01110111);
4'b1011 : temps=~(8'b01111100);
4'b1100 : temps=~(8'b00111001);
4'b1101 : temps=~(8'b01011110);
4'b1110 : temps=~(8'b01111001);
4'b1111 : temps=~(8'b01110001);
endcase
end


assign ss=temps;
assign anode=an;

endmodule


.ucf File 

NET "anode[0]" LOC = K14;
NET "anode[1]" LOC = M13;
NET "anode[2]" LOC = J12;
NET "anode[3]" LOC = F12;
NET "ss[0]" LOC = L14;
NET "ss[1]" LOC = H12;
NET "ss[2]" LOC = N14;
NET "ss[3]" LOC = N11;
NET "ss[4]" LOC = P12;
NET "ss[5]" LOC = L13;
NET "ss[6]" LOC = M12;
NET "ss[7]" LOC = N13;

NET "clock" LOC = B8;
NET "reset" LOC = A7;

Saturday, August 10, 2013

Knight Rider Project using DIGILENT Basys2 FPGA


Verilog Code

module kr(
input clock,reset,
output [7:0] A
    );
reg [20:0] count;
reg [7:0] temp;
reg [3:0] c;
reg dir;
initial dir=1'b1;
parameter a=8'b00000001;
parameter b=8'b10000000;
always@(posedge clock)
begin
    count<=count+1;
    if(reset) begin
        count<=0;
        temp<=0;
        temp<=temp+1;
        c<=0;
       
         end
    else if(count==2097151) begin
        if(dir)begin
        c<=c+1;
        temp<=a<<c;
            if(c==7) begin
                dir<=1'b0;
                c<=0; end
        end
       
        else begin
        c<=c+1;
        temp<=b>>c;
            if(c==7) begin
                dir<=1'b1;
                c<=0; end       
        end
        end
       
end
assign A=temp;
     
endmodule


.ucf File      

NET "clock" LOC = B8;
NET "reset" LOC = A7;
NET "A[0]" LOC = M5;
NET "A[1]" LOC = M11;
NET "A[2]" LOC = P7;
NET "A[3]" LOC = P6;
NET "A[4]" LOC = N5;
NET "A[5]" LOC = N4;
NET "A[6]" LOC = P4;
NET "A[7]" LOC = G1;  






Saturday, June 9, 2012

Knight Rider Circuit using PIC16F84A



Hello Friends , This is my very first blog post.


This is a simulation of the knight rider circuit designed using pic16F84A.I used the following C code which was compiled by the mikroC,C compiler for Microchip PIC microcontrollers to generate the .Hex file . I used JDM programmer to write the .Hex file to the microcontroller.


C code

void movedown()
{
     while(PORTB.F7!=1)
     {
                PORTB=PORTB*2;
                delay_ms(100);
     }
}

void moveup()
{
     while(PORTB.F0!=1)
     {
                PORTB=PORTB/2;
                delay_ms(100);
     }
}


void main()
{
     TRISB=0;
     PORTB=0b11111111;
     delay_ms(1000);
     PORTB=1;
     delay_ms(100);
     
     while(1)
     {
              movedown();
              moveup();
     }

}

Schematic of the circuit used