SlideShare uma empresa Scribd logo
1 de 12
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

Mais conteúdo relacionado

Mais procurados

Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02nikomatsakis
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorialnikomatsakis
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?勇浩 赖
 
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 itSergey 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 2009scweng
 
Cilk Plus Parallel Reduction
Cilk Plus Parallel ReductionCilk Plus Parallel Reduction
Cilk Plus Parallel ReductionAlbert DeFusco
 
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 examplesSyed 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 2016Carlos Maniero
 
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Platonov Sergey
 
Ravada VDI Eslibre
Ravada VDI EslibreRavada VDI Eslibre
Ravada VDI Eslibrefrankiejol
 
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 1ArcBlock
 
Asterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up TelephonyAsterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up TelephonyAndrey Karpov
 
Ugly code
Ugly codeUgly code
Ugly codeOdd-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 ThreadedBryan Hughes
 

Mais procurados (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
 

Destaque

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 ConverterKarthik 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_rathinavelKarthik 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 ampKarthik Rathinavel
 
ECE 626 project report Switched Capacitor
ECE 626 project report Switched CapacitorECE 626 project report Switched Capacitor
ECE 626 project report Switched CapacitorKarthik 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 CadenceKarthik Rathinavel
 

Destaque (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
 

Semelhante a 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 codeBharti 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.pdfshreeaadithyaacellso
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureanishgoel
 
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.1boedax
 
ch5_additional.ppt
ch5_additional.pptch5_additional.ppt
ch5_additional.pptLokeshK66
 
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 programmingThe IOT Academy
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfcontact32
 
Senior design project code for PPG
Senior design project code for PPGSenior design project code for PPG
Senior design project code for PPGFrankDin1
 
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 thingsJan Jongboom
 
Musical Machines and Flapping Phones
Musical Machines and Flapping PhonesMusical Machines and Flapping Phones
Musical Machines and Flapping PhonesNeil Mendoza
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor ConcurrencyAlex Miller
 

Semelhante a 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 generator using microcontroller
 PWM wave generator using microcontroller  PWM wave generator using microcontroller
PWM wave generator using microcontroller
 
Pwm wave
Pwm wave Pwm wave
Pwm wave
 
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
 

Mais de 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 ADSKarthik 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-ampKarthik 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 PulsesKarthik Rathinavel
 

Mais de 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
 

Último

Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfrs7054576148
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 

Último (20)

Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 

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