wiki:QuadPulser

Control electronics for G-2 Quadrupole pulser

2018 (Final?) Implementation

==New free run mode VHDL code ==

  • still needs to make some changes to the code below
-----------------------------------------------------------------------
-- Generate a pulse train with programmable spacing and count
--
-- Port details:
-- clk         100 MHz system clock
-- rst_n       active low asynchronous reset
-- MP_PERIOD   pulse period (spacing) in clk cycles
-- MP_COUNT    number of pulses (0-31 programmed generates 1-32 pulses)
-- trig_in     input trigger to start a sequence
-- trig_out    pulse output (1 clock wide)
--
-- all signals synchronous to clk except rst_n
------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity mp_top is
  port (
    clk       : in  std_logic;                      -- 100MHz system clock
    rst_n     : in  std_logic;                      -- active low reset
    MP_PERIOD : in  std_logic_vector(20 downto 0);  -- pulse period
    MP_COUNT  : in  std_logic_vector(4 downto 0);   -- pulse count-1
    trig_in   : in  std_logic;                      -- trigger input
    trig_out  : out std_logic);                     -- pulse_output

end entity mp_top;

architecture module of mp_top is
    signal pulse_period : std_logic_vector(20 downto 0);
    signal pulse_count  : std_logic_vector(4 downto 0);
    signal trig_0 : std_logic; -- trig_0 and trig_1 are used to detect trig_in
    signal trig_1 : std_logic;
    signal active : std_logic; -- goes high when trig_in is detected and stay high until pulse_count = MP_COUNT
 
begin
    process(clk,rst_n) is begin
        -- if rst_n is high. reset everything                                                                                                                                                                                            
        if rst_n = '1' then                                                                                                                                                                                                                
            trig_out <= '0';                                                                                                                                                                                                              
            pulse_period <=  (0 => '1', others => '0');                                                                                                                                                                                    
            pulse_count <= (others => '0');                                                                                                                                                                                                
            trig_0 <= '0';                                                                                                                                                                                                                 
            trig_1 <= '0';                                                                                                                                                                                                                 
            active <= '0';                                                                                                                                                                                                                 
            trig_out <='0';                                                                                                                                                                                                                
                                                                                                                                                                                                                                           
        elsif clk'event and clk = '1' then                                                                                                                                                                                                
            trig_0 <= trig_in; --detect trig_in                                                                                                                                                                                           
            trig_1 <= trig_0;                                                                                                                                                                                                              
            trig_out <= '0';                                                                                                                                                                                                               
            if (trig_0 = '1' and trig_1 = '0') then                                                                                                                                                                                        
                active <= '1'; -- start generating the pulse                                                                                                                                                                               
            end if;                                                                                                                                                                                                                        
                                                                                                                                                                                                                                           
            if active = '1' and pulse_count /= MP_COUNT then                                                                                                                                                                               
                if MP_PERIOD = pulse_period then                                                                                                                                                                                           
                    pulse_period <=  (0 => '1', others => '0');                                                                                                                                                                            
                    pulse_count <= std_logic_vector( unsigned(pulse_count) + 1 );                                                                                                                                                         
                    trig_out <= '1';                                                                                                                                                                                                      
                else                                                                                                                                                                                                                       
                    pulse_period <= std_logic_vector( unsigned(pulse_period) + 1 );                                                                                                                                                        
                end if;                                                                                                                                                                                                                    
            end if;                                                                                                                                                                                                                       
                                                                                                                                                                                                                                           
            if pulse_count = MP_COUNT then                                                                                                                                                                                                
                trig_out <='0';                                                                                                                                                                                                            
                pulse_count <= (others => '0');                                                                                                                                                                                            
                active <= '0';                                                                                                                                                                                                             
            end if;                                                                                                                                                                                                                      
        end if;  
    end process;
end module;

Power Supply Notes

Last modified 5 weeks ago Last modified on Nov 13, 2018, 12:56:30 PM