-- Tyler Lutz; July 26, 2011; -- Height of Pulse Peak calculator; --Input->digital signal from ASIC, time from onboard clock; --Output->height in volts of peak (optionally also time of peak); ------------------------------------------------------------------------- --((o))--((o))--((o))--((o))--((o))--((o))--((o))--((o))--((o))--((o))-- ------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; entity fitting_etc_peak is port( pulse: in std_logic_vector (0 to 11); --assumed that ASIC readout is in parallel(?), and if not it is easy to parallelize serial input clk: in std_logic; OPEAK: out std_logic_vector (0 to 11); --Dedicated output for peak of pulse end fitting_etc_peak; -- ==I==I==I==I==I==I==I==I==I==I==I== -- architecture Herjolfssen7 of fitting_etc_peak is begin process(clk) variable accsec: integer :=0; --"seconds" or any other arbitrary time unit, to be adjusted based on the frequency of clock used. type gaul is array(natural range <>) of integer; --define unconstrained array type variable pulsebit: gaul (0 to 11); --pulse is converted later to an integer for calculation purposes; this is an intermediate step variable multithreshold: gaul (0 to 2); --stores our three constant threshold values for the multithresh mode variable pulsar: integer:=0; -- intergized value of incoming pulse constant savescope: integer:=100; --scope size of CFD delay memory and base line averager (here, last 1000 data points) variable pulsarsave: gaul (0 to savescope+4); --allows us to delay the pulse (the 10^10 is totally arbitrary) variable letop: integer:=0; variable peak: integer:=0; -- height of the peak variable peaktime: integer:=0; --time at which peak occurs -- ==I==I==I==I==I==I==I==I==I==I==I== -- begin if clk'event and clk='1' then --program loops at clock rising edge letop:=(letop+1)mod 50;--1000000; if letop=0 then accsec:=(accsec+1) mod 2**12; --our stopwatch --our oscilloscope data is converted to decimal stored in 'pulsar': for j in 0 to 11 loop -- intigerizing the input pulse; logic vector to binary array to integer(pulsar) if pulse(j)='0' then pulsebit(j):=1; --binary array elsif pulse(j)='1' then pulsebit(j):=0; end if; if j=0 then pulsar:=pulsebit(0); --a clever way to reinitialize the summand 'pulsar' else pulsar:= pulsar+(pulsebit(j))*(2**(j)); --actual binary to integer conversion end if; end loop; multithreshold(0):=14; --specify desired threshold values for multithreshold claculations multithreshold(1):=15; multithreshold(2):=17; if (pulsar>))]|[((<< (([|])) >>))]|[((<< (([|]) >>))]|[((<< (([|])) >>))]|[((<< (([|])) >>))]|[((<< (([|])) >>))]|[((<<-- if pulsar>=multithreshold(0) then --PEAK FINDER if pulsar>=peak then --find largest pulsar peak:=pulsar; --and store it in "peak" peaktime:=accsec; end if; end if; if pulsar=multithreshold(0) and peak/=0 then --when pulse goes below 1st threshold for y in 7 downto 0 loop --readout in parallel if peak>=(2**y) then OPEAK(y)<='1'; peak:=peak-2**y; --automatically reinitializes 'peak' to zero!!! else OPEAK(y)<='0'; if y=0 then peak:=0; end if; end if; end loop; end if; -- >>--0--O--o--+--o--O--0--<< >>--0--O--o--+--o--O--0--<< >>--0--O--o--+--o--O--0--<< >>--0--O--o--+--o--O--0--<< -- end if; end if; end process; end Herjolfssen7;