FPGA Center



  * Project Definition

  * ASM Chart&VHDL Code

   * Simulation

ASM CHART

VHDL CODE

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity PeriodMeasurement is
          Port (¬† clk¬†¬†¬†¬†¬†¬† ¬†¬† :¬† in¬†¬†   STD_LOGIC;
                      reset¬†¬†¬†¬† :¬† in¬†¬†¬†  STD_LOGIC;
                      start¬†¬†¬†¬† ¬†¬†:¬† in¬†¬†¬† STD_LOGIC;
                      input¬†¬†¬†¬†¬† :¬† in¬†¬†¬† STD_LOGIC;¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†
                      done¬†¬†¬†¬†¬† :¬†out¬† STD_LOGIC;
                      output¬†¬†¬† :¬†out¬† STD_LOGIC_VECTOR (9 downto 0)¬† );
      end PeriodMeasurement;

architecture Behavioral of PeriodMeasurement is
     type state_type is (IDLE,AMBUSH,MEASURE);
     signal state, state_next: state_type;
     signal N,N_next: STD_LOGIC_VECTOR (9 downto 0);
     signal counter,counter_next : integer :=0;
     signal edge,edge_delay:STD_LOGIC;
     begin
          process(clk,reset)
                begin
                     if reset='1' then
                            state<= IDLE;
                            N<=(others=>'0');
                            counter<=0;¬†
                            edge_delay<='0';
                    elsif¬† clk= '1' and clk'event then
                            state<=state_next;
                            N<=N_next;
                            counter<=counter_next;
                            edge_delay<= input;
                  end if;
           end process;

         edge<= (not edge_delay) and input;

¬†¬†     process(start,state,counter,N,edge,reset)
             begin
                     done<='0';
                     state_next<=state;
                     counter_next<=counter;
                     N_next<=N;
                    case state is
                           when IDLE=>¬†¬†
                                    if start = '1'¬†¬† then¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†
                                          state_next<= ambush;
                                    end if;
¬†¬†¬†¬†¬†¬†                 ¬†¬†  when AMBUSH=>
                                      if edge = '1' then
                                             counter_next<= 0;
                                             N_next<=(others=>'0');
                                             state_next<=measure;
                                      end if;
  ¬†¬†¬†¬†¬†¬†¬†¬†                   when MEASURE=>
                                      if edge = '1' then
                                             done<= '1';
                                             state_next<=IDLE;
                                       else
                                              if counter=49999 then
                                                      counter_next<=0;
                                                      N_next<= N+1;
                                                else
                                                       counter_next<= counter+1;
                                                end if;¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† ¬†¬†¬†¬†¬†¬†¬†¬†¬†
                                     end if;
                       end case;
              end process;

  output<=N;
  end Behavioral;

We can prepare Test Bench and simulate it using ModelSim .

 

project                                                                                                                                  Test_bench

 

Home | Fpga | VHDL | VHDL Dictionary | Digital Design | Simulation | PCB | Examples | Contact Us
Copyright © 2010 - 2013 FPGAcenter. All Rights Reserved.