SlideShare a Scribd company logo
module lab5(
input logic quadA,
input logic quadB,
output logic [6:0] seven_segment,
output logic [2:0] sel,
output logic [7:0] q_sig,
input logic reset_button,
output reg en2,
output reg en3,
output reg midpin,
output logic pwm_out,
output logic quad_button1,
input logic quad_button2,
input inclk0_sig
);
/////Clocks Generated from PLL
logic c0_sig;
logic c1_sig;
logic c2_sig;
logic [10:0] address_sig;
PLL PLL_inst (
.inclk0 ( inclk0_sig ),
.c0 ( c0_sig ),
//10 KHz Clock
.c1 ( c1_sig ),
// 4 KHz Clock
.c2 ( c2_sig )
// 16.77216 MHz Clock
);
Rom_Sin Rom_Sin_inst (
.address ( address_sig ),
.clock ( clock_sig ),
.q ( q_sig )
);
wire clock_sig = c2_sig;
assign en2 = 1'b0;
assign midpin = 1'b0;
assign pwm_out = 1'b0;
assign quad_button1 = 1'b0;
logic [3:0] muxo;
logic [3:0] present_state;
logic [3:0] next_state;
logic [3:0] hundreds_digit;
logic [3:0] tens_digit;
logic [3:0] thousands_digit;
logic [3:0] ones_digit;
logic [13:0] count;
logic [23:0] Add_out;
logic [23:0] DQ_out;
////Logic needed for quad encoders
logic quadA_steady1;
logic quadB_steady2;
logic quadA_steady1_past;
logic quadB_steady2_past;
wire count_enable = quadA_steady1 ^ quadA_steady1_past ^ quadB_steady2 ^
quadB_steady2_past;
wire count_rotation_direction = quadA_steady1 ^ quadB_steady2_past;
/////////////////////////Debouncer for QuadA///////////////////
logic hold_something1;
logic hold_something_else1;
logic [3:0] Switch_count1;
always_ff@(posedge inclk0_sig)
begin
hold_something1 <= quadA;
hold_something_else1 <= hold_something1;
end
always_ff@(posedge inclk0_sig)
if(quadA_steady1==hold_something_else1)
Switch_count1 <= 0;
else
begin
Switch_count1 <= Switch_count1 + 1; //Incrementing counter1 for
switching
if(Switch_count1 == 9)
quadA_steady1 <= ~quadA_steady1;
end
///////////////////////////////End of Quad A Debouncer//////////
/////////////////////////Debouncer for QuadB/////////////////////
logic hold_something2;
logic hold_something_else2;
logic [3:0] Switch_count2;
always_ff@(posedge inclk0_sig)
begin
hold_something2 <= quadB;
hold_something_else2 <= hold_something2;
end
always_ff@(posedge inclk0_sig)
if(quadB_steady2==hold_something_else2)
Switch_count2 <= 0;
else
begin
Switch_count2 <= Switch_count2 + 1; //Incrementing counter2 for
switching
if(Switch_count2 == 9)
quadB_steady2 <= ~quadB_steady2;
end
////////////////////////End of QuadB Debouncer///////////////////
/////////////////////////Debouncer for quad_button/////////////////////
logic hold_something3;
logic hold_something_else3;
logic [3:0] Switch_count3;
logic quad_button2_steady;
always_ff@(posedge inclk0_sig)
begin
hold_something3 <= quad_button2;
hold_something_else3 <= hold_something3;
end
always_ff@(posedge inclk0_sig)
if(quad_button2_steady==hold_something_else3)
Switch_count3 <= 0;
else
begin
Switch_count3 <= Switch_count3 + 1; //Incrementing counter2 for
switching
if(Switch_count3 == 9)
quad_button2_steady <= ~quad_button2_steady;
end
////////////////////////End of quad_button Debouncer///////////////////
///Making a new clock of 2HZ Frequency using 4 kHz Clock
logic [11:0] number;
logic newclock;
always_ff@(posedge c1_sig) begin
number <= number+1;
if (number< 2000)
newclock <= 1;
else if (number >= 2000 && number < 4000)
newclock <= 0;
else
number <=0;
end
////////////////
//////////////////////////////Mode of Incrementing////
logic [1:0] alpha;
logic [10:0] a_count;
logic tenblock_inc;
logic hundredblock_inc;
logic thousandblock_inc;
//assign alpha = 2'b01;
always_ff@(posedge newclock) begin
if (!quad_button2_steady)
alpha <= alpha+1;
end
always_comb begin
if (alpha ==0)
begin
a_count = 1;
tenblock_inc = 0;
hundredblock_inc = 0;
thousandblock_inc = 0;
end
else if (alpha ==1)
begin
a_count = 10;
tenblock_inc = 1;
hundredblock_inc = 0;
thousandblock_inc = 0;
end
else if (alpha ==2)
begin
a_count = 100;
tenblock_inc = 0;
hundredblock_inc = 1;
thousandblock_inc = 0;
end
else ///// (alpha ==3)
begin
a_count = 1000;
tenblock_inc = 0;
hundredblock_inc = 0;
thousandblock_inc = 1;
end
end
//////////////////////////////////End of Mode Incrementing////////////////////
//////////////////////////////Quad
Encoder//////////////////////////////////////////
always_ff@(posedge inclk0_sig)
begin
quadA_steady1_past <= quadA_steady1;
quadB_steady2_past <= quadB_steady2;
end
always_ff@(posedge inclk0_sig or negedge reset_button)
begin
if (!reset_button)
count <=1000;
else
begin
if(count_enable)//////////////////////////////Either Increment or
decrement count
begin
if(count_rotation_direction)
begin
if (count<9999)
count <=
count+a_count;/////////////////////////Increment Count
else
count <= count;
end
else ////////////////////////////////////////decrement count
begin
if (count>0)
count <= count-a_count;
else
count <= 0;
end
end
end
end
/////////////////////////////Separating
digits/////////////////////////////////////
always_ff@(posedge inclk0_sig or negedge reset_button)
begin
if (!reset_button)
begin
ones_digit <=0;
tens_digit <=0;
hundreds_digit <=0;
thousands_digit <=1;
end
else
begin
if(count_enable)//////////////////////////////Either Increment or
decrement
begin
if(count_rotation_direction)
//Clockwise Rotation
begin
if (ones_digit ==9 && tens_digit ==9 && hundreds_digit ==9 &&
thousands_digit ==9)
begin
ones_digit <=9;
tens_digit <=9;
hundreds_digit <=9;
thousands_digit <=9;
end
else
/////////Increment Digits Normally
begin
if (tenblock_inc == 0 && hundredblock_inc == 0 &&
thousandblock_inc == 0)
begin
if (ones_digit <9)
ones_digit <= ones_digit+1;
else
// Ones digit is 9
begin
ones_digit <= 0;
if (tens_digit <9)
tens_digit <= tens_digit+1;
else
//Tens digit is 9
begin
tens_digit <= 0;
if (hundreds_digit <9)
hundreds_digit <=
hundreds_digit+1;
else
//Hundreds digit is 9
begin
hundreds_digit <= 0;
if (thousands_digit <9)
thousands_digit
<=thousands_digit+1;
else
//Thousands digit is 9
thousands_digit <=0;
//Does'nt even happen
end
end
end
end
/////////////////Increment Digits by tens
else if (tenblock_inc == 1 && hundredblock_inc == 0 &&
thousandblock_inc == 0)
begin
if (tens_digit <9)
tens_digit <= tens_digit+1;
else
//Tens digit is 9
begin
tens_digit <= 0;
if (hundreds_digit <9)
hundreds_digit <= hundreds_digit+1;
else
//Hundreds digit is 9
begin
hundreds_digit <= 0;
if (thousands_digit <9)
thousands_digit
<=thousands_digit+1;
else
//Thousands digit is 9
thousands_digit <=9;
end
end
end
///////////////Increment Digts by Hundreds
else if (tenblock_inc == 0 && hundredblock_inc == 1 &&
thousandblock_inc == 0)
begin
if (hundreds_digit <9)
hundreds_digit <= hundreds_digit+1;
else
//Hundreds digit is 9
begin
hundreds_digit <= 0;
if (thousands_digit <9)
thousands_digit
<=thousands_digit+1;
else
//Thousands digit is 9
thousands_digit <=9;
end
end
///////////////////Increment by thousands
else //if (tenblock_inc == 0 && hundredblock_inc == 0 &&
thousandblock_inc == 1)
begin
if (thousands_digit <9)
thousands_digit <=thousands_digit+1;
else
//Thousands digit is 9
thousands_digit <=9;
end
end
end
/////////////////////////////////////////////////////Anticlockwise
Rotation
else
begin
if (ones_digit ==0 && tens_digit ==0 && hundreds_digit ==0 &&
thousands_digit ==0)
begin
ones_digit <=0;
tens_digit <=0;
hundreds_digit <=0;
thousands_digit <=0;
end
else
begin //////////////////////////Normal Decrement
if (tenblock_inc == 0 && hundredblock_inc == 0 &&
thousandblock_inc == 0)
begin
if (ones_digit >0 && ones_digit <10)
ones_digit <= ones_digit-1;
else
// Ones digit is 0
begin
ones_digit <=9;
if (tens_digit >0 && tens_digit <10)
tens_digit <= tens_digit-1;
else
//Tens digit is 0
begin
tens_digit<= 9;
if (hundreds_digit>0 && hundreds_digit
<10)
hundreds_digit <= hundreds_digit-
1;
else
//Hundreds Digit is 0
begin
hundreds_digit<=9;
if (thousands_digit >0 &&
thousands_digit <10)
thousands_digit <=
thousands_digit-1;
else
//Thousands Digit is 0
thousands_digit <= 9;
end
end
end
end
////////Decrement by tens
else if (tenblock_inc == 1 && hundredblock_inc == 0 &&
thousandblock_inc == 0)
begin
if (tens_digit >0 && tens_digit <10)
tens_digit <= tens_digit-1;
else
//Tens digit is 0
begin
tens_digit<= 9;
if (hundreds_digit>0 && hundreds_digit <10)
hundreds_digit <= hundreds_digit-
1;
else
//Hundreds Digit is 0
begin
hundreds_digit<=9;
if (thousands_digit >0 &&
thousands_digit <10)
thousands_digit <=
thousands_digit-1;
else
//Thousands Digit is 0
thousands_digit <= 0;
end
end
end
///Decrement by Hundred
else if (tenblock_inc == 0 && hundredblock_inc == 1 &&
thousandblock_inc == 0)
begin
if (hundreds_digit>0 && hundreds_digit <10)
hundreds_digit <= hundreds_digit-1;
else
//Hundreds Digit is 0
begin
hundreds_digit<=9;
if (thousands_digit >0 && thousands_digit
<10)
thousands_digit <= thousands_digit-1;
else
//Thousands Digit is 0
thousands_digit <= 0;
end
end
//////Decrement by Thousand
else if (tenblock_inc == 0 && hundredblock_inc == 0 &&
thousandblock_inc == 1)
begin
if (thousands_digit >0 && thousands_digit <10)
thousands_digit <= thousands_digit-1;
else
//Thousands Digit is 0
thousands_digit <= 0;
end
end
end
end
end
end
///////////////// State Machine present state becomes new state every clock
edge//////
always_ff@(posedge c0_sig)
present_state <= next_state;
///Saving the state
//Making it go to the next state. Incrementing present
state/////////////////////
always_comb
begin
unique case (present_state)
4'b0000 : next_state = 4'b0001;
//Ones Digit State
4'b0001 : next_state = 4'b0010;
//Idle State
4'b0010 : next_state = 4'b0011;
//Tens Digit State
4'b0011 : next_state = 4'b0100;
//Idle State
4'b0100 : next_state = 4'b0101;
//Hundreds Digit State
4'b0101 : next_state = 4'b0110;
//Idle State
4'b0110 : next_state = 4'b0111;
//Thousands State
4'b0111 : next_state = 4'b1000;
//Idle State
4'b1000 : next_state = 4'b0000;
//Circles Back
endcase
end
// MUX: Displaying Output of each of three digits; one after the other
always_comb
begin
if (present_state == 0)
begin
muxo = ones_digit;
// mux out is first digit
sel = 3'b000;
en3 = 1'b1;
end
else if (present_state == 1)
//Idle between States
begin
muxo = 9;
// mux out is random
sel = 3'b111;
//Nothing Happens
en3 = 1'b0;
end
else if (present_state == 2)
begin
muxo = tens_digit;
// mux out is tens digit
sel = 3'b001;
if (count < 10)
// Zero Supression for Tens Digit
en3 = 1'b0;
else
en3 = 1'b1;
end
else if (present_state == 3)
//Idle between States
begin
muxo = 9;
// mux out is random
sel = 3'b111;
//Nothing Happens
en3 = 1'b0;
end
else if (present_state == 4)
begin
muxo = hundreds_digit; //
mux out is hundreds digit
sel = 3'b011;
if (count < 100)
// Zero Supression for Hundreds Digit
en3 = 1'b0;
else
en3 = 1'b1;
end
else if (present_state == 5)
//Idle State
begin
muxo = 9;
// mux out is random
sel = 3'b111;
//Nothing Happens
en3 = 1'b0;
end
else if (present_state == 6)
begin
muxo = thousands_digit; //
mux out is thousands digit
sel = 3'b100;
if (count < 1000)
// Zero Supression for Thousands Digit
en3 = 1'b0;
else
en3 = 1'b1;
end
else if (present_state == 7)
//Idle State
begin
muxo = 9;
// mux out is random
sel = 3'b111;
//Nothing Happens
en3 = 1'b0;
end
else
begin
muxo = 9;
//Doesn't Matter
sel = 3'b011;
//Going nowhere
en3 = 1'b0;
//Also Output is disabled
end
end
///////////////////////bcd to seven segment
decoder///////////////////////////////
always_comb begin
casez (muxo) //gfedcba
4'b0000 : seven_segment = 7'b1000000; //seven
segment display of 0
4'b0001 : seven_segment = 7'b1111001; //seven
segment display of 1
4'b0010 : seven_segment = 7'b0100100; //seven
segment display of 2
4'b0011 : seven_segment = 7'b0110000; //seven
segment display of 3
4'b0100 : seven_segment = 7'b0011001; //seven
segment display of 4
4'b0101 : seven_segment = 7'b0010010; //seven
segment display of 5
4'b0110 : seven_segment = 7'b0000010; //seven
segment display of 6
4'b0111 : seven_segment = 7'b1111000; //seven
segment display of 7
4'b1000 : seven_segment = 7'b0000000; //seven
segment display of 8
4'b1001 : seven_segment = 7'b0010000; //seven
segment display of 9
4'b1111 : seven_segment = 7'b0000000; //Doesn't
Matter Not Going to Display
default : seven_segment = 7'b1000000; //seven
segment displaying 0
endcase
end
///////////////////////////////Sine Wave
Generator/////////////////////////////////
///24 bit Adder
always_comb begin
Add_out = count + DQ_out; ////Using Count
Instead of Individual Digits
end
///DQ Flip Flop
always_ff@(posedge c2_sig) begin
DQ_out <= Add_out;
end
////Extracting the higher order bits for address assignment
always_comb begin
address_sig[10:0] = DQ_out[23:13];
end
////////////////////////////End of Sine Generator///////////
///////////////////////////PWM Brightness
Control/////////////////////////////////////
/////////////////////Begining of first counter block_A with 4 MHz clock
always_ff@(posedge c1_sig)
begin
cout_A <= cout_A +4'b0001;
end
////////////////////////////End of first counter blockA with 4MHz Clock
///////////////////////////Second Counter, counts when button is pushed
always_ff @(posedge newclock)
begin
if (push_steady == 0)
cout_B <= cout_B +1;
else
cout_B <= cout_B;
end
///////////////////////////////End of second counter
///////////////////////////////Comparing the two counts
always_comb
begin
if (cout_A >= cout_B)
pwm_out = 1'b1;
else
pwm_out = 1'b0;
end
//////////////////////////////////////End of PWM Brightness
Control////////////////
endmodule

More Related Content

What's hot

Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
nikomatsakis
 
Verilog code
Verilog codeVerilog code
Verilog code
Vijay Kannamalla
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
nikomatsakis
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
勇浩 赖
 
Debugging TV Frame 0x09
Debugging TV Frame 0x09Debugging TV Frame 0x09
Debugging TV Frame 0x09
Dmitry Vostokov
 
Evgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against itEvgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against it
Sergey Platonov
 
Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009
scweng
 
Cilk Plus Parallel Reduction
Cilk Plus Parallel ReductionCilk Plus Parallel Reduction
Cilk Plus Parallel Reduction
Albert DeFusco
 
C++ L07-Struct
C++ L07-StructC++ L07-Struct
C++ L07-Struct
Mohammad Shaker
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
명신 김
 
20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会
Hiroki Mizuno
 
Oops pramming with examples
Oops pramming with examplesOops pramming with examples
Oops pramming with examples
Syed Khaleel
 
Seu primeiro loop com Python AsyncIO - TDC 2016
Seu primeiro loop com Python AsyncIO - TDC 2016Seu primeiro loop com Python AsyncIO - TDC 2016
Seu primeiro loop com Python AsyncIO - TDC 2016
Carlos Maniero
 
Linked list
Linked listLinked list
Linked list
Lovelyn Rose
 
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.
Platonov Sergey
 
Ravada VDI Eslibre
Ravada VDI EslibreRavada VDI Eslibre
Ravada VDI Eslibre
frankiejol
 
Ethereum virtual machine for Developers Part 1
Ethereum virtual machine for Developers Part 1Ethereum virtual machine for Developers Part 1
Ethereum virtual machine for Developers Part 1
ArcBlock
 
Asterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up TelephonyAsterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up Telephony
Andrey Karpov
 
Ugly code
Ugly codeUgly code
Ugly code
Odd-e
 
The Node.js Event Loop: Not So Single Threaded
The Node.js Event Loop: Not So Single ThreadedThe Node.js Event Loop: Not So Single Threaded
The Node.js Event Loop: Not So Single Threaded
Bryan Hughes
 

What's hot (20)

Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
 
Verilog code
Verilog codeVerilog code
Verilog code
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
Debugging TV Frame 0x09
Debugging TV Frame 0x09Debugging TV Frame 0x09
Debugging TV Frame 0x09
 
Evgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against itEvgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against it
 
Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009Perl 5.10 on OSDC.tw 2009
Perl 5.10 on OSDC.tw 2009
 
Cilk Plus Parallel Reduction
Cilk Plus Parallel ReductionCilk Plus Parallel Reduction
Cilk Plus Parallel Reduction
 
C++ L07-Struct
C++ L07-StructC++ L07-Struct
C++ L07-Struct
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会
 
Oops pramming with examples
Oops pramming with examplesOops pramming with examples
Oops pramming with examples
 
Seu primeiro loop com Python AsyncIO - TDC 2016
Seu primeiro loop com Python AsyncIO - TDC 2016Seu primeiro loop com Python AsyncIO - TDC 2016
Seu primeiro loop com Python AsyncIO - TDC 2016
 
Linked list
Linked listLinked list
Linked list
 
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.
 
Ravada VDI Eslibre
Ravada VDI EslibreRavada VDI Eslibre
Ravada VDI Eslibre
 
Ethereum virtual machine for Developers Part 1
Ethereum virtual machine for Developers Part 1Ethereum virtual machine for Developers Part 1
Ethereum virtual machine for Developers Part 1
 
Asterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up TelephonyAsterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up Telephony
 
Ugly code
Ugly codeUgly code
Ugly code
 
The Node.js Event Loop: Not So Single Threaded
The Node.js Event Loop: Not So Single ThreadedThe Node.js Event Loop: Not So Single Threaded
The Node.js Event Loop: Not So Single Threaded
 

Viewers also liked

Design of 17-Bit Audio Band Delta-Sigma Analog to Digital Converter
Design of 17-Bit Audio Band Delta-Sigma Analog to Digital ConverterDesign of 17-Bit Audio Band Delta-Sigma Analog to Digital Converter
Design of 17-Bit Audio Band Delta-Sigma Analog to Digital Converter
Karthik Rathinavel
 
Ece593 project1 chien_chun_yao_and_karthikvel_rathinavel
Ece593 project1 chien_chun_yao_and_karthikvel_rathinavelEce593 project1 chien_chun_yao_and_karthikvel_rathinavel
Ece593 project1 chien_chun_yao_and_karthikvel_rathinavel
Karthik Rathinavel
 
Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...
Karthik Rathinavel
 
Ece 523 project – fully differential two stage telescopic op amp
Ece 523 project – fully differential two stage telescopic op ampEce 523 project – fully differential two stage telescopic op amp
Ece 523 project – fully differential two stage telescopic op amp
Karthik Rathinavel
 
ECE 626 project report Switched Capacitor
ECE 626 project report Switched CapacitorECE 626 project report Switched Capacitor
ECE 626 project report Switched Capacitor
Karthik Rathinavel
 
Two stage folded cascode op amp design in Cadence
Two stage folded cascode op amp design in CadenceTwo stage folded cascode op amp design in Cadence
Two stage folded cascode op amp design in Cadence
Karthik Rathinavel
 

Viewers also liked (6)

Design of 17-Bit Audio Band Delta-Sigma Analog to Digital Converter
Design of 17-Bit Audio Band Delta-Sigma Analog to Digital ConverterDesign of 17-Bit Audio Band Delta-Sigma Analog to Digital Converter
Design of 17-Bit Audio Band Delta-Sigma Analog to Digital Converter
 
Ece593 project1 chien_chun_yao_and_karthikvel_rathinavel
Ece593 project1 chien_chun_yao_and_karthikvel_rathinavelEce593 project1 chien_chun_yao_and_karthikvel_rathinavel
Ece593 project1 chien_chun_yao_and_karthikvel_rathinavel
 
Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...
 
Ece 523 project – fully differential two stage telescopic op amp
Ece 523 project – fully differential two stage telescopic op ampEce 523 project – fully differential two stage telescopic op amp
Ece 523 project – fully differential two stage telescopic op amp
 
ECE 626 project report Switched Capacitor
ECE 626 project report Switched CapacitorECE 626 project report Switched Capacitor
ECE 626 project report Switched Capacitor
 
Two stage folded cascode op amp design in Cadence
Two stage folded cascode op amp design in CadenceTwo stage folded cascode op amp design in Cadence
Two stage folded cascode op amp design in Cadence
 

Similar to Sine Wave Generator with controllable frequency displayed on a seven segment board using FPGA Board

To designing counters using verilog code
To designing counters using verilog codeTo designing counters using verilog code
To designing counters using verilog code
Bharti Airtel Ltd.
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
shreeaadithyaacellso
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
anishgoel
 
Pwm wave
Pwm wave Pwm wave
Pwm wave
Swapnil2515
 
PWM wave generator using microcontroller
 PWM wave generator using microcontroller  PWM wave generator using microcontroller
PWM wave generator using microcontroller
Swapnil2515
 
Mdp plus 2.1
Mdp plus 2.1Mdp plus 2.1
Mdp plus 2.1
boedax
 
Open bot
Open bot Open bot
Open bot
Anshuman Dhar
 
ch5_additional.ppt
ch5_additional.pptch5_additional.ppt
ch5_additional.ppt
LokeshK66
 
Direct analog
Direct analogDirect analog
Direct analog
srikanthsailu
 
Code
CodeCode
OpenBot-Code
OpenBot-CodeOpenBot-Code
OpenBot-Code
Anshuman Dhar
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
The IOT Academy
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
contact32
 
Senior design project code for PPG
Senior design project code for PPGSenior design project code for PPG
Senior design project code for PPG
FrankDin1
 
DomCode 2015 - Abusing phones to make the internet of things
DomCode 2015 - Abusing phones to make the internet of thingsDomCode 2015 - Abusing phones to make the internet of things
DomCode 2015 - Abusing phones to make the internet of things
Jan Jongboom
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
pratikborsadiya
 
Musical Machines and Flapping Phones
Musical Machines and Flapping PhonesMusical Machines and Flapping Phones
Musical Machines and Flapping Phones
Neil Mendoza
 
GreyCount
GreyCountGreyCount
GreyCount
Thomas Knudstrup
 
Verilog_Examples (1).pdf
Verilog_Examples (1).pdfVerilog_Examples (1).pdf
Verilog_Examples (1).pdf
DrViswanathKalannaga1
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
Alex Miller
 

Similar to Sine Wave Generator with controllable frequency displayed on a seven segment board using FPGA Board (20)

To designing counters using verilog code
To designing counters using verilog codeTo designing counters using verilog code
To designing counters using verilog code
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
 
Pwm wave
Pwm wave Pwm wave
Pwm wave
 
PWM wave generator using microcontroller
 PWM wave generator using microcontroller  PWM wave generator using microcontroller
PWM wave generator using microcontroller
 
Mdp plus 2.1
Mdp plus 2.1Mdp plus 2.1
Mdp plus 2.1
 
Open bot
Open bot Open bot
Open bot
 
ch5_additional.ppt
ch5_additional.pptch5_additional.ppt
ch5_additional.ppt
 
Direct analog
Direct analogDirect analog
Direct analog
 
Code
CodeCode
Code
 
OpenBot-Code
OpenBot-CodeOpenBot-Code
OpenBot-Code
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
 
Senior design project code for PPG
Senior design project code for PPGSenior design project code for PPG
Senior design project code for PPG
 
DomCode 2015 - Abusing phones to make the internet of things
DomCode 2015 - Abusing phones to make the internet of thingsDomCode 2015 - Abusing phones to make the internet of things
DomCode 2015 - Abusing phones to make the internet of things
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
 
Musical Machines and Flapping Phones
Musical Machines and Flapping PhonesMusical Machines and Flapping Phones
Musical Machines and Flapping Phones
 
GreyCount
GreyCountGreyCount
GreyCount
 
Verilog_Examples (1).pdf
Verilog_Examples (1).pdfVerilog_Examples (1).pdf
Verilog_Examples (1).pdf
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
 

More from Karthik Rathinavel

Low Noise Amplifier at 2 GHz using the transistor NE85639 in ADS
Low Noise Amplifier at 2 GHz using the transistor NE85639 in ADSLow Noise Amplifier at 2 GHz using the transistor NE85639 in ADS
Low Noise Amplifier at 2 GHz using the transistor NE85639 in ADS
Karthik Rathinavel
 
Ece523 folded cascode design
Ece523 folded cascode designEce523 folded cascode design
Ece523 folded cascode design
Karthik Rathinavel
 
Differntial Input to Single Ended Output, Two stage Op-amp
Differntial Input to Single Ended Output, Two stage Op-ampDifferntial Input to Single Ended Output, Two stage Op-amp
Differntial Input to Single Ended Output, Two stage Op-amp
Karthik Rathinavel
 
Continuous Low Pass Filter Realization using Cascaded stages of Tow-Thomas Bi...
Continuous Low Pass Filter Realization using Cascaded stages of Tow-Thomas Bi...Continuous Low Pass Filter Realization using Cascaded stages of Tow-Thomas Bi...
Continuous Low Pass Filter Realization using Cascaded stages of Tow-Thomas Bi...
Karthik Rathinavel
 
Transmitting Digital Signal through Light Pulses
Transmitting Digital Signal through Light PulsesTransmitting Digital Signal through Light Pulses
Transmitting Digital Signal through Light Pulses
Karthik Rathinavel
 
Project Report
Project Report Project Report
Project Report
Karthik Rathinavel
 
Project presentation
Project presentationProject presentation
Project presentation
Karthik Rathinavel
 

More from Karthik Rathinavel (7)

Low Noise Amplifier at 2 GHz using the transistor NE85639 in ADS
Low Noise Amplifier at 2 GHz using the transistor NE85639 in ADSLow Noise Amplifier at 2 GHz using the transistor NE85639 in ADS
Low Noise Amplifier at 2 GHz using the transistor NE85639 in ADS
 
Ece523 folded cascode design
Ece523 folded cascode designEce523 folded cascode design
Ece523 folded cascode design
 
Differntial Input to Single Ended Output, Two stage Op-amp
Differntial Input to Single Ended Output, Two stage Op-ampDifferntial Input to Single Ended Output, Two stage Op-amp
Differntial Input to Single Ended Output, Two stage Op-amp
 
Continuous Low Pass Filter Realization using Cascaded stages of Tow-Thomas Bi...
Continuous Low Pass Filter Realization using Cascaded stages of Tow-Thomas Bi...Continuous Low Pass Filter Realization using Cascaded stages of Tow-Thomas Bi...
Continuous Low Pass Filter Realization using Cascaded stages of Tow-Thomas Bi...
 
Transmitting Digital Signal through Light Pulses
Transmitting Digital Signal through Light PulsesTransmitting Digital Signal through Light Pulses
Transmitting Digital Signal through Light Pulses
 
Project Report
Project Report Project Report
Project Report
 
Project presentation
Project presentationProject presentation
Project presentation
 

Recently uploaded

integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
gaafergoudaay7aga
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
ramrag33
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
IJECEIAES
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
Madan Karki
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 

Recently uploaded (20)

integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 

Sine Wave Generator with controllable frequency displayed on a seven segment board using FPGA Board

  • 1. module lab5( input logic quadA, input logic quadB, output logic [6:0] seven_segment, output logic [2:0] sel, output logic [7:0] q_sig, input logic reset_button, output reg en2, output reg en3, output reg midpin, output logic pwm_out, output logic quad_button1, input logic quad_button2, input inclk0_sig ); /////Clocks Generated from PLL logic c0_sig; logic c1_sig; logic c2_sig; logic [10:0] address_sig; PLL PLL_inst ( .inclk0 ( inclk0_sig ), .c0 ( c0_sig ), //10 KHz Clock .c1 ( c1_sig ), // 4 KHz Clock .c2 ( c2_sig ) // 16.77216 MHz Clock ); Rom_Sin Rom_Sin_inst ( .address ( address_sig ), .clock ( clock_sig ), .q ( q_sig ) ); wire clock_sig = c2_sig; assign en2 = 1'b0; assign midpin = 1'b0; assign pwm_out = 1'b0; assign quad_button1 = 1'b0; logic [3:0] muxo; logic [3:0] present_state; logic [3:0] next_state; logic [3:0] hundreds_digit; logic [3:0] tens_digit; logic [3:0] thousands_digit; logic [3:0] ones_digit; logic [13:0] count; logic [23:0] Add_out; logic [23:0] DQ_out; ////Logic needed for quad encoders logic quadA_steady1; logic quadB_steady2;
  • 2. logic quadA_steady1_past; logic quadB_steady2_past; wire count_enable = quadA_steady1 ^ quadA_steady1_past ^ quadB_steady2 ^ quadB_steady2_past; wire count_rotation_direction = quadA_steady1 ^ quadB_steady2_past; /////////////////////////Debouncer for QuadA/////////////////// logic hold_something1; logic hold_something_else1; logic [3:0] Switch_count1; always_ff@(posedge inclk0_sig) begin hold_something1 <= quadA; hold_something_else1 <= hold_something1; end always_ff@(posedge inclk0_sig) if(quadA_steady1==hold_something_else1) Switch_count1 <= 0; else begin Switch_count1 <= Switch_count1 + 1; //Incrementing counter1 for switching if(Switch_count1 == 9) quadA_steady1 <= ~quadA_steady1; end ///////////////////////////////End of Quad A Debouncer////////// /////////////////////////Debouncer for QuadB///////////////////// logic hold_something2; logic hold_something_else2; logic [3:0] Switch_count2; always_ff@(posedge inclk0_sig) begin hold_something2 <= quadB; hold_something_else2 <= hold_something2; end always_ff@(posedge inclk0_sig) if(quadB_steady2==hold_something_else2) Switch_count2 <= 0; else begin Switch_count2 <= Switch_count2 + 1; //Incrementing counter2 for switching if(Switch_count2 == 9) quadB_steady2 <= ~quadB_steady2; end ////////////////////////End of QuadB Debouncer/////////////////// /////////////////////////Debouncer for quad_button///////////////////// logic hold_something3; logic hold_something_else3;
  • 3. logic [3:0] Switch_count3; logic quad_button2_steady; always_ff@(posedge inclk0_sig) begin hold_something3 <= quad_button2; hold_something_else3 <= hold_something3; end always_ff@(posedge inclk0_sig) if(quad_button2_steady==hold_something_else3) Switch_count3 <= 0; else begin Switch_count3 <= Switch_count3 + 1; //Incrementing counter2 for switching if(Switch_count3 == 9) quad_button2_steady <= ~quad_button2_steady; end ////////////////////////End of quad_button Debouncer/////////////////// ///Making a new clock of 2HZ Frequency using 4 kHz Clock logic [11:0] number; logic newclock; always_ff@(posedge c1_sig) begin number <= number+1; if (number< 2000) newclock <= 1; else if (number >= 2000 && number < 4000) newclock <= 0; else number <=0; end //////////////// //////////////////////////////Mode of Incrementing//// logic [1:0] alpha; logic [10:0] a_count; logic tenblock_inc; logic hundredblock_inc; logic thousandblock_inc; //assign alpha = 2'b01; always_ff@(posedge newclock) begin if (!quad_button2_steady) alpha <= alpha+1; end always_comb begin if (alpha ==0) begin a_count = 1; tenblock_inc = 0; hundredblock_inc = 0; thousandblock_inc = 0;
  • 4. end else if (alpha ==1) begin a_count = 10; tenblock_inc = 1; hundredblock_inc = 0; thousandblock_inc = 0; end else if (alpha ==2) begin a_count = 100; tenblock_inc = 0; hundredblock_inc = 1; thousandblock_inc = 0; end else ///// (alpha ==3) begin a_count = 1000; tenblock_inc = 0; hundredblock_inc = 0; thousandblock_inc = 1; end end //////////////////////////////////End of Mode Incrementing//////////////////// //////////////////////////////Quad Encoder////////////////////////////////////////// always_ff@(posedge inclk0_sig) begin quadA_steady1_past <= quadA_steady1; quadB_steady2_past <= quadB_steady2; end always_ff@(posedge inclk0_sig or negedge reset_button) begin if (!reset_button) count <=1000; else begin if(count_enable)//////////////////////////////Either Increment or decrement count begin if(count_rotation_direction) begin if (count<9999) count <= count+a_count;/////////////////////////Increment Count else count <= count; end else ////////////////////////////////////////decrement count begin if (count>0) count <= count-a_count; else count <= 0;
  • 5. end end end end /////////////////////////////Separating digits///////////////////////////////////// always_ff@(posedge inclk0_sig or negedge reset_button) begin if (!reset_button) begin ones_digit <=0; tens_digit <=0; hundreds_digit <=0; thousands_digit <=1; end else begin if(count_enable)//////////////////////////////Either Increment or decrement begin if(count_rotation_direction) //Clockwise Rotation begin if (ones_digit ==9 && tens_digit ==9 && hundreds_digit ==9 && thousands_digit ==9) begin ones_digit <=9; tens_digit <=9; hundreds_digit <=9; thousands_digit <=9; end else /////////Increment Digits Normally begin if (tenblock_inc == 0 && hundredblock_inc == 0 && thousandblock_inc == 0) begin if (ones_digit <9) ones_digit <= ones_digit+1; else // Ones digit is 9 begin ones_digit <= 0; if (tens_digit <9) tens_digit <= tens_digit+1; else //Tens digit is 9 begin tens_digit <= 0; if (hundreds_digit <9) hundreds_digit <= hundreds_digit+1; else //Hundreds digit is 9 begin hundreds_digit <= 0; if (thousands_digit <9) thousands_digit
  • 6. <=thousands_digit+1; else //Thousands digit is 9 thousands_digit <=0; //Does'nt even happen end end end end /////////////////Increment Digits by tens else if (tenblock_inc == 1 && hundredblock_inc == 0 && thousandblock_inc == 0) begin if (tens_digit <9) tens_digit <= tens_digit+1; else //Tens digit is 9 begin tens_digit <= 0; if (hundreds_digit <9) hundreds_digit <= hundreds_digit+1; else //Hundreds digit is 9 begin hundreds_digit <= 0; if (thousands_digit <9) thousands_digit <=thousands_digit+1; else //Thousands digit is 9 thousands_digit <=9; end end end ///////////////Increment Digts by Hundreds else if (tenblock_inc == 0 && hundredblock_inc == 1 && thousandblock_inc == 0) begin if (hundreds_digit <9) hundreds_digit <= hundreds_digit+1; else //Hundreds digit is 9 begin hundreds_digit <= 0; if (thousands_digit <9) thousands_digit <=thousands_digit+1; else //Thousands digit is 9 thousands_digit <=9; end end ///////////////////Increment by thousands else //if (tenblock_inc == 0 && hundredblock_inc == 0 && thousandblock_inc == 1) begin if (thousands_digit <9) thousands_digit <=thousands_digit+1; else //Thousands digit is 9
  • 7. thousands_digit <=9; end end end /////////////////////////////////////////////////////Anticlockwise Rotation else begin if (ones_digit ==0 && tens_digit ==0 && hundreds_digit ==0 && thousands_digit ==0) begin ones_digit <=0; tens_digit <=0; hundreds_digit <=0; thousands_digit <=0; end else begin //////////////////////////Normal Decrement if (tenblock_inc == 0 && hundredblock_inc == 0 && thousandblock_inc == 0) begin if (ones_digit >0 && ones_digit <10) ones_digit <= ones_digit-1; else // Ones digit is 0 begin ones_digit <=9; if (tens_digit >0 && tens_digit <10) tens_digit <= tens_digit-1; else //Tens digit is 0 begin tens_digit<= 9; if (hundreds_digit>0 && hundreds_digit <10) hundreds_digit <= hundreds_digit- 1; else //Hundreds Digit is 0 begin hundreds_digit<=9; if (thousands_digit >0 && thousands_digit <10) thousands_digit <= thousands_digit-1; else //Thousands Digit is 0 thousands_digit <= 9; end end end end ////////Decrement by tens else if (tenblock_inc == 1 && hundredblock_inc == 0 && thousandblock_inc == 0) begin
  • 8. if (tens_digit >0 && tens_digit <10) tens_digit <= tens_digit-1; else //Tens digit is 0 begin tens_digit<= 9; if (hundreds_digit>0 && hundreds_digit <10) hundreds_digit <= hundreds_digit- 1; else //Hundreds Digit is 0 begin hundreds_digit<=9; if (thousands_digit >0 && thousands_digit <10) thousands_digit <= thousands_digit-1; else //Thousands Digit is 0 thousands_digit <= 0; end end end ///Decrement by Hundred else if (tenblock_inc == 0 && hundredblock_inc == 1 && thousandblock_inc == 0) begin if (hundreds_digit>0 && hundreds_digit <10) hundreds_digit <= hundreds_digit-1; else //Hundreds Digit is 0 begin hundreds_digit<=9; if (thousands_digit >0 && thousands_digit <10) thousands_digit <= thousands_digit-1; else //Thousands Digit is 0 thousands_digit <= 0; end end //////Decrement by Thousand else if (tenblock_inc == 0 && hundredblock_inc == 0 && thousandblock_inc == 1) begin if (thousands_digit >0 && thousands_digit <10) thousands_digit <= thousands_digit-1; else //Thousands Digit is 0 thousands_digit <= 0; end end end end end
  • 9. end ///////////////// State Machine present state becomes new state every clock edge////// always_ff@(posedge c0_sig) present_state <= next_state; ///Saving the state //Making it go to the next state. Incrementing present state///////////////////// always_comb begin unique case (present_state) 4'b0000 : next_state = 4'b0001; //Ones Digit State 4'b0001 : next_state = 4'b0010; //Idle State 4'b0010 : next_state = 4'b0011; //Tens Digit State 4'b0011 : next_state = 4'b0100; //Idle State 4'b0100 : next_state = 4'b0101; //Hundreds Digit State 4'b0101 : next_state = 4'b0110; //Idle State 4'b0110 : next_state = 4'b0111; //Thousands State 4'b0111 : next_state = 4'b1000; //Idle State 4'b1000 : next_state = 4'b0000; //Circles Back endcase end // MUX: Displaying Output of each of three digits; one after the other always_comb begin if (present_state == 0) begin muxo = ones_digit; // mux out is first digit sel = 3'b000; en3 = 1'b1; end else if (present_state == 1) //Idle between States begin muxo = 9; // mux out is random sel = 3'b111; //Nothing Happens en3 = 1'b0; end else if (present_state == 2) begin muxo = tens_digit;
  • 10. // mux out is tens digit sel = 3'b001; if (count < 10) // Zero Supression for Tens Digit en3 = 1'b0; else en3 = 1'b1; end else if (present_state == 3) //Idle between States begin muxo = 9; // mux out is random sel = 3'b111; //Nothing Happens en3 = 1'b0; end else if (present_state == 4) begin muxo = hundreds_digit; // mux out is hundreds digit sel = 3'b011; if (count < 100) // Zero Supression for Hundreds Digit en3 = 1'b0; else en3 = 1'b1; end else if (present_state == 5) //Idle State begin muxo = 9; // mux out is random sel = 3'b111; //Nothing Happens en3 = 1'b0; end else if (present_state == 6) begin muxo = thousands_digit; // mux out is thousands digit sel = 3'b100; if (count < 1000) // Zero Supression for Thousands Digit en3 = 1'b0; else en3 = 1'b1; end else if (present_state == 7) //Idle State begin muxo = 9; // mux out is random sel = 3'b111; //Nothing Happens en3 = 1'b0;
  • 11. end else begin muxo = 9; //Doesn't Matter sel = 3'b011; //Going nowhere en3 = 1'b0; //Also Output is disabled end end ///////////////////////bcd to seven segment decoder/////////////////////////////// always_comb begin casez (muxo) //gfedcba 4'b0000 : seven_segment = 7'b1000000; //seven segment display of 0 4'b0001 : seven_segment = 7'b1111001; //seven segment display of 1 4'b0010 : seven_segment = 7'b0100100; //seven segment display of 2 4'b0011 : seven_segment = 7'b0110000; //seven segment display of 3 4'b0100 : seven_segment = 7'b0011001; //seven segment display of 4 4'b0101 : seven_segment = 7'b0010010; //seven segment display of 5 4'b0110 : seven_segment = 7'b0000010; //seven segment display of 6 4'b0111 : seven_segment = 7'b1111000; //seven segment display of 7 4'b1000 : seven_segment = 7'b0000000; //seven segment display of 8 4'b1001 : seven_segment = 7'b0010000; //seven segment display of 9 4'b1111 : seven_segment = 7'b0000000; //Doesn't Matter Not Going to Display default : seven_segment = 7'b1000000; //seven segment displaying 0 endcase end ///////////////////////////////Sine Wave Generator///////////////////////////////// ///24 bit Adder always_comb begin Add_out = count + DQ_out; ////Using Count Instead of Individual Digits end ///DQ Flip Flop always_ff@(posedge c2_sig) begin DQ_out <= Add_out; end ////Extracting the higher order bits for address assignment always_comb begin address_sig[10:0] = DQ_out[23:13]; end
  • 12. ////////////////////////////End of Sine Generator/////////// ///////////////////////////PWM Brightness Control///////////////////////////////////// /////////////////////Begining of first counter block_A with 4 MHz clock always_ff@(posedge c1_sig) begin cout_A <= cout_A +4'b0001; end ////////////////////////////End of first counter blockA with 4MHz Clock ///////////////////////////Second Counter, counts when button is pushed always_ff @(posedge newclock) begin if (push_steady == 0) cout_B <= cout_B +1; else cout_B <= cout_B; end ///////////////////////////////End of second counter ///////////////////////////////Comparing the two counts always_comb begin if (cout_A >= cout_B) pwm_out = 1'b1; else pwm_out = 1'b0; end //////////////////////////////////////End of PWM Brightness Control//////////////// endmodule