SlideShare a Scribd company logo
1 of 12
FPGA
Creating Counter
             Created by

             Akhmad Hendriawan
             hendri@eepis-its.edu
You are free:
to Share — to copy, distribute and transmit the work
Under the following conditions:
Attribution — You must attribute the work in the manner specified by the author
or licensor (but not in any way that suggests that they endorse you or your use
of the work).
Noncommercial — You may not use this work for commercial purposes.
No Derivative Works — You may not alter, transform, or build upon this work.



                                              Created by

                                              Akhmad Hendriawan
                                              hendri@eepis-its.edu
Design system
Background



●I try implement counter seven segmen with
input clock from switch.

●Because push button is mechanical then I try to
remove bouncing effect with debouncing circuit
Problem and solution

Although I succeed to implement my design and upload to bit stream to
FPGA but there was warning with warning message “ prescaller may have
excessive skew”.
My first prescaller with warning
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

Library UNISIM;
use UNISIM.vcomponents.all;

entity Prescaller is
  Port ( clk_i : in STD_LOGIC;
        psc_out : out STD_LOGIC);
end Prescaller;

architecture Behavioral of Prescaller is
signal clk_r: std_logic_vector(17 downto 0) := (others=>'0');
begin

process (clk_i,clk_r)
begin
  if rising_edge(clk_i) then
            clk_r <= clk_r+1;
          end if;
end process;
psc_out<=clk_r(17);
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;


                                                                                   Prescaller.vhd
Library UNISIM;
use UNISIM.vcomponents.all;

entity Prescaller is
  Port ( clk_i : in STD_LOGIC;
        psc_out : out STD_LOGIC);
end Prescaller;

architecture Behavioral of Prescaller is
signal clk_r: std_logic_vector(17 downto 0) := (others=>'0');
begin

process (clk_i,clk_r)
begin
                                                                Implement clock buffer to output prescaler solve
  if rising_edge(clk_i) then                                    warning error.
            clk_r <= clk_r+1;
          end if;
end process;
  BUFG_inst : BUFG
  port map (
     O => psc_out, -- Clock buffer output
     I => clk_r(17)     -- Clock buffer input
  );

end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity debouncing is
  Port ( clk_i : in STD_LOGIC;
        dbin : in STD_LOGIC;
        dbout : out STD_LOGIC);
end debouncing;


architecture Behavioral of debouncing is
signal Q1, Q2, Q3 : std_logic;             Debouncing.vhd
begin
A: process(clk_i)
begin
  if (clk_i'event and clk_i = '1') then
       Q1 <= dbin;
       Q2 <= Q1;
       Q3 <= Q2;
  end if;
end process;

B: process(clk_i)
begin
  if (clk_i'event and clk_i = '1') then
       dbout <= Q1 and Q2 and (not Q3);
  end if;
end process;

end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;

entity counterBCD is
  Port ( clk_i : in STD_LOGIC;
        bcd_o : out STD_LOGIC_VECTOR (3 downto 0));
end counterBCD;

architecture Behavioral of counterBCD is
signal clk_r: std_logic_vector (3 downto 0) := (others=>'0');   Counter BCD.vhd
begin
process (clk_i)
begin
 if rising_edge(clk_i) then
    if(clk_r < 9) then
      clk_r<= clk_r+1;
           else
            clk_r<= (others => '0');
           end if;
 end if;
end process;
bcd_o <= clk_r;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;


entity decoder is
  Port ( clk : in STD_LOGIC;
        bcd : in STD_LOGIC_VECTOR (3 downto 0);
        segment7 : out STD_LOGIC_VECTOR (6 downto 0));
end decoder;

architecture Behavioral of decoder is

begin
process (clk,bcd)
begin
  if (clk'event and clk='1') then                                                 Decoder.vhd
           case bcd is
                   --common anoda          gfedcba
       when "0000"=> segment7 <="0000001"; -- '0'
       when "0001"=> segment7 <="1001111"; -- '1'
                   when "0010"=> segment7 <="0010010"; -- '2'
                   when "0011"=> segment7 <="0000110"; -- '3'
                   when "0100"=> segment7 <="1001100"; -- '4'
                   when "0101"=> segment7 <="0100100"; -- '5'
                   when "0110"=> segment7 <="0100000"; -- '6'
                   when "0111"=> segment7 <="0001111"; -- '7'
                   when "1000"=> segment7 <="0000000"; -- '8'
                   when "1001"=> segment7 <="0000100"; -- '9'
            --nothing is displayed when a number more than 9 is given as input.
       when others=> segment7 <="1111111";
    end case;
         end if;
end process;

end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;                                      COMPONENT decoder
                                                                  PORT(
entity syscnt is                                                        clk : IN std_logic;
  Port ( clk_i : in STD_LOGIC;                                          bcd : IN std_logic_vector(3 downto 0);
             pb_i : in STD_LOGIC;                                       segment7 : OUT std_logic_vector(6 downto 0)
        counter_out : out STD_LOGIC_VECTOR (6 downto 0)                 );
       );                                                         END COMPONENT;
end syscnt;
                                                           signal psc_cable: std_logic;
architecture Behavioral of syscnt is                            signal db_cable: std_logic;
                                                                signal bcd_o_cable: std_logic_vector(3 downto 0);
       COMPONENT Prescaller
       PORT(                                              begin
             clk_i : IN std_logic;
             psc_out : OUT std_logic                              Inst_Prescaller: Prescaller PORT MAP(
             );                                                          clk_i => clk_i,
       END COMPONENT;                                                    psc_out => psc_cable
                                                                  );
       COMPONENT debouncing
       PORT(                                                      Inst_debouncing: debouncing PORT MAP(
             clk_i : IN std_logic;                                       clk_i => psc_cable,
             dbin : IN std_logic;                                        dbin => pb_i,
             dbout : OUT std_logic                                       dbout => db_cable
             );                                                   );
       END COMPONENT;
                                                                  Inst_counterBCD: counterBCD PORT MAP(
       COMPONENT counterBCD                                              clk_i => db_cable ,
       PORT(                                                             bcd_o => bcd_o_cable
             clk_i : IN std_logic;                                );
             bcd_o : OUT std_logic_vector(3 downto 0)
             );                                                         Inst_decoder: decoder PORT MAP(
       END COMPONENT;                                                   clk => db_cable,
                                                                        bcd => bcd_o_cable,
                                                                        segment7 => counter_out
                                       Syscnt.vhd               );
                                                          end Behavioral;

More Related Content

What's hot

Functions for Nano 5 Card
Functions for Nano 5 CardFunctions for Nano 5 Card
Functions for Nano 5 CardOmar Sanchez
 
VHDL PROGRAMS FEW EXAMPLES
VHDL PROGRAMS FEW EXAMPLESVHDL PROGRAMS FEW EXAMPLES
VHDL PROGRAMS FEW EXAMPLESkarthik kadava
 
Lecture 2 verilog
Lecture 2   verilogLecture 2   verilog
Lecture 2 verilogvenravi10
 
Verilog 語法教學
Verilog 語法教學 Verilog 語法教學
Verilog 語法教學 艾鍗科技
 
Digital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECEDigital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECERamesh Naik Bhukya
 
Digital system design lab manual
Digital system design lab manualDigital system design lab manual
Digital system design lab manualSanthosh Poralu
 
Writing more complex models
Writing more complex modelsWriting more complex models
Writing more complex modelsMohamed Samy
 
Practical file
Practical filePractical file
Practical filerajeevkr35
 
Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Béo Tú
 
Delays in verilog
Delays in verilogDelays in verilog
Delays in verilogJITU MISTRY
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhtsBéo Tú
 
Embedded system design psoc lab report
Embedded system design psoc lab reportEmbedded system design psoc lab report
Embedded system design psoc lab reportRamesh Naik Bhukya
 
Verilog Lecture4 2014
Verilog Lecture4 2014Verilog Lecture4 2014
Verilog Lecture4 2014Béo Tú
 

What's hot (20)

DHow2 - L6 VHDL
DHow2 - L6 VHDLDHow2 - L6 VHDL
DHow2 - L6 VHDL
 
Programs of VHDL
Programs of VHDLPrograms of VHDL
Programs of VHDL
 
Functions for Nano 5 Card
Functions for Nano 5 CardFunctions for Nano 5 Card
Functions for Nano 5 Card
 
VHDL PROGRAMS FEW EXAMPLES
VHDL PROGRAMS FEW EXAMPLESVHDL PROGRAMS FEW EXAMPLES
VHDL PROGRAMS FEW EXAMPLES
 
Lecture 2 verilog
Lecture 2   verilogLecture 2   verilog
Lecture 2 verilog
 
Vhdl lab manual
Vhdl lab manualVhdl lab manual
Vhdl lab manual
 
Verilog 語法教學
Verilog 語法教學 Verilog 語法教學
Verilog 語法教學
 
Session1
Session1Session1
Session1
 
Switch level modeling
Switch level modelingSwitch level modeling
Switch level modeling
 
Digital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECEDigital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECE
 
Digital system design lab manual
Digital system design lab manualDigital system design lab manual
Digital system design lab manual
 
Writing more complex models
Writing more complex modelsWriting more complex models
Writing more complex models
 
Practical file
Practical filePractical file
Practical file
 
Crash course in verilog
Crash course in verilogCrash course in verilog
Crash course in verilog
 
Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014
 
Delays in verilog
Delays in verilogDelays in verilog
Delays in verilog
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhts
 
Embedded system design psoc lab report
Embedded system design psoc lab reportEmbedded system design psoc lab report
Embedded system design psoc lab report
 
Tdm to vo ip 2
Tdm to vo ip 2Tdm to vo ip 2
Tdm to vo ip 2
 
Verilog Lecture4 2014
Verilog Lecture4 2014Verilog Lecture4 2014
Verilog Lecture4 2014
 

Similar to Fpga creating counter with external clock

Pipeline stalling in vhdl
Pipeline stalling in vhdlPipeline stalling in vhdl
Pipeline stalling in vhdlSai Malleswar
 
Write complete VHDL codes for the following schematic. Solution.pdf
Write complete VHDL codes for the following schematic.  Solution.pdfWrite complete VHDL codes for the following schematic.  Solution.pdf
Write complete VHDL codes for the following schematic. Solution.pdfarjuncollection
 
Cocos2d実践編 1.0.0rc
Cocos2d実践編 1.0.0rcCocos2d実践編 1.0.0rc
Cocos2d実践編 1.0.0rcYuichi Higuchi
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Rodrigo Almeida
 
Digital to analog -Sqaure waveform generator in VHDL
Digital to analog -Sqaure waveform generator in VHDLDigital to analog -Sqaure waveform generator in VHDL
Digital to analog -Sqaure waveform generator in VHDLOmkar Rane
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxSANTIAGO PABLO ALBERTO
 
Digital System Design-Synchronous Sequential Circuits
Digital System Design-Synchronous Sequential CircuitsDigital System Design-Synchronous Sequential Circuits
Digital System Design-Synchronous Sequential CircuitsIndira Priyadarshini
 
VHdl lab report
VHdl lab reportVHdl lab report
VHdl lab reportJinesh Kb
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기Ji Hun Kim
 

Similar to Fpga creating counter with external clock (20)

Uart
UartUart
Uart
 
VHDL Programs
VHDL ProgramsVHDL Programs
VHDL Programs
 
vhdll.docx
vhdll.docxvhdll.docx
vhdll.docx
 
Reporte vhdl9
Reporte vhdl9Reporte vhdl9
Reporte vhdl9
 
Pipeline stalling in vhdl
Pipeline stalling in vhdlPipeline stalling in vhdl
Pipeline stalling in vhdl
 
Write complete VHDL codes for the following schematic. Solution.pdf
Write complete VHDL codes for the following schematic.  Solution.pdfWrite complete VHDL codes for the following schematic.  Solution.pdf
Write complete VHDL codes for the following schematic. Solution.pdf
 
گزارش کار
گزارش کارگزارش کار
گزارش کار
 
Cocos2d実践編 1.0.0rc
Cocos2d実践編 1.0.0rcCocos2d実践編 1.0.0rc
Cocos2d実践編 1.0.0rc
 
Vhdl
VhdlVhdl
Vhdl
 
LCD_Example.pptx
LCD_Example.pptxLCD_Example.pptx
LCD_Example.pptx
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015
 
An Example MIPS
An Example  MIPSAn Example  MIPS
An Example MIPS
 
Digital to analog -Sqaure waveform generator in VHDL
Digital to analog -Sqaure waveform generator in VHDLDigital to analog -Sqaure waveform generator in VHDL
Digital to analog -Sqaure waveform generator in VHDL
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
Basic-VHDL-Constructs1.ppt
Basic-VHDL-Constructs1.pptBasic-VHDL-Constructs1.ppt
Basic-VHDL-Constructs1.ppt
 
Digital System Design-Synchronous Sequential Circuits
Digital System Design-Synchronous Sequential CircuitsDigital System Design-Synchronous Sequential Circuits
Digital System Design-Synchronous Sequential Circuits
 
Vhdl programs
Vhdl programsVhdl programs
Vhdl programs
 
Multi qubit entanglement
Multi qubit entanglementMulti qubit entanglement
Multi qubit entanglement
 
VHdl lab report
VHdl lab reportVHdl lab report
VHdl lab report
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기
 

More from Politeknik Elektronika Negeri Surabaya (6)

Memulai AVR WINAVR
Memulai AVR WINAVRMemulai AVR WINAVR
Memulai AVR WINAVR
 
Interfacing to lcd with arduino
Interfacing  to lcd with arduinoInterfacing  to lcd with arduino
Interfacing to lcd with arduino
 
Modul2 setting xctu
Modul2 setting xctuModul2 setting xctu
Modul2 setting xctu
 
My Linux
My LinuxMy Linux
My Linux
 
Embedded lcd
Embedded lcdEmbedded lcd
Embedded lcd
 
winavr tutorial
winavr tutorial winavr tutorial
winavr tutorial
 

Fpga creating counter with external clock

  • 1. FPGA Creating Counter Created by Akhmad Hendriawan hendri@eepis-its.edu
  • 2. You are free: to Share — to copy, distribute and transmit the work Under the following conditions: Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). Noncommercial — You may not use this work for commercial purposes. No Derivative Works — You may not alter, transform, or build upon this work. Created by Akhmad Hendriawan hendri@eepis-its.edu
  • 3.
  • 5. Background ●I try implement counter seven segmen with input clock from switch. ●Because push button is mechanical then I try to remove bouncing effect with debouncing circuit
  • 6. Problem and solution Although I succeed to implement my design and upload to bit stream to FPGA but there was warning with warning message “ prescaller may have excessive skew”.
  • 7. My first prescaller with warning library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; Library UNISIM; use UNISIM.vcomponents.all; entity Prescaller is Port ( clk_i : in STD_LOGIC; psc_out : out STD_LOGIC); end Prescaller; architecture Behavioral of Prescaller is signal clk_r: std_logic_vector(17 downto 0) := (others=>'0'); begin process (clk_i,clk_r) begin if rising_edge(clk_i) then clk_r <= clk_r+1; end if; end process; psc_out<=clk_r(17); end Behavioral;
  • 8. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; Prescaller.vhd Library UNISIM; use UNISIM.vcomponents.all; entity Prescaller is Port ( clk_i : in STD_LOGIC; psc_out : out STD_LOGIC); end Prescaller; architecture Behavioral of Prescaller is signal clk_r: std_logic_vector(17 downto 0) := (others=>'0'); begin process (clk_i,clk_r) begin Implement clock buffer to output prescaler solve if rising_edge(clk_i) then warning error. clk_r <= clk_r+1; end if; end process; BUFG_inst : BUFG port map ( O => psc_out, -- Clock buffer output I => clk_r(17) -- Clock buffer input ); end Behavioral;
  • 9. library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity debouncing is Port ( clk_i : in STD_LOGIC; dbin : in STD_LOGIC; dbout : out STD_LOGIC); end debouncing; architecture Behavioral of debouncing is signal Q1, Q2, Q3 : std_logic; Debouncing.vhd begin A: process(clk_i) begin if (clk_i'event and clk_i = '1') then Q1 <= dbin; Q2 <= Q1; Q3 <= Q2; end if; end process; B: process(clk_i) begin if (clk_i'event and clk_i = '1') then dbout <= Q1 and Q2 and (not Q3); end if; end process; end Behavioral;
  • 10. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_unsigned.ALL; entity counterBCD is Port ( clk_i : in STD_LOGIC; bcd_o : out STD_LOGIC_VECTOR (3 downto 0)); end counterBCD; architecture Behavioral of counterBCD is signal clk_r: std_logic_vector (3 downto 0) := (others=>'0'); Counter BCD.vhd begin process (clk_i) begin if rising_edge(clk_i) then if(clk_r < 9) then clk_r<= clk_r+1; else clk_r<= (others => '0'); end if; end if; end process; bcd_o <= clk_r; end Behavioral;
  • 11. library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity decoder is Port ( clk : in STD_LOGIC; bcd : in STD_LOGIC_VECTOR (3 downto 0); segment7 : out STD_LOGIC_VECTOR (6 downto 0)); end decoder; architecture Behavioral of decoder is begin process (clk,bcd) begin if (clk'event and clk='1') then Decoder.vhd case bcd is --common anoda gfedcba when "0000"=> segment7 <="0000001"; -- '0' when "0001"=> segment7 <="1001111"; -- '1' when "0010"=> segment7 <="0010010"; -- '2' when "0011"=> segment7 <="0000110"; -- '3' when "0100"=> segment7 <="1001100"; -- '4' when "0101"=> segment7 <="0100100"; -- '5' when "0110"=> segment7 <="0100000"; -- '6' when "0111"=> segment7 <="0001111"; -- '7' when "1000"=> segment7 <="0000000"; -- '8' when "1001"=> segment7 <="0000100"; -- '9' --nothing is displayed when a number more than 9 is given as input. when others=> segment7 <="1111111"; end case; end if; end process; end Behavioral;
  • 12. library IEEE; use IEEE.STD_LOGIC_1164.ALL; COMPONENT decoder PORT( entity syscnt is clk : IN std_logic; Port ( clk_i : in STD_LOGIC; bcd : IN std_logic_vector(3 downto 0); pb_i : in STD_LOGIC; segment7 : OUT std_logic_vector(6 downto 0) counter_out : out STD_LOGIC_VECTOR (6 downto 0) ); ); END COMPONENT; end syscnt; signal psc_cable: std_logic; architecture Behavioral of syscnt is signal db_cable: std_logic; signal bcd_o_cable: std_logic_vector(3 downto 0); COMPONENT Prescaller PORT( begin clk_i : IN std_logic; psc_out : OUT std_logic Inst_Prescaller: Prescaller PORT MAP( ); clk_i => clk_i, END COMPONENT; psc_out => psc_cable ); COMPONENT debouncing PORT( Inst_debouncing: debouncing PORT MAP( clk_i : IN std_logic; clk_i => psc_cable, dbin : IN std_logic; dbin => pb_i, dbout : OUT std_logic dbout => db_cable ); ); END COMPONENT; Inst_counterBCD: counterBCD PORT MAP( COMPONENT counterBCD clk_i => db_cable , PORT( bcd_o => bcd_o_cable clk_i : IN std_logic; ); bcd_o : OUT std_logic_vector(3 downto 0) ); Inst_decoder: decoder PORT MAP( END COMPONENT; clk => db_cable, bcd => bcd_o_cable, segment7 => counter_out Syscnt.vhd ); end Behavioral;