M
M.Randelzhofer
Guest
I'm trying to simplify my vhdl code for synchronious edge detection of
signals by using of subprograms. Unfortunately there are no examples on the
web (or difficult to find) how sequential procedures work.
Normally i use a sequential process to built a shift register for edge
detection:
process (clock)
begin
if (clock'event and clock ='1') then
shift(0) <= signal ;
shift(1) <= shift(0) ;
end if ;
rise <= not shift(1) and shift(0) ;
fall <= shift(1) and not shift(0) ;
end process;
Now i would like to use a procedure as a subprogram, to simplify the code
for lots of such situations.
As i understood, functions can not be used for sequential statements, but
procedures.
I tried some code, but it does't work:
procedure edge(
signal clk,din: in STD_LOGIC ;
signal edv: inout STD_LOGIC_VECTOR (1 downto 0)
) is
begin
if Rising_Edge(clk) then
edv(0) <= din ;
edv(1) <= edv(0) ;
end if;
end edge;
function rise(edv: STD_LOGIC_VECTOR (1 downto 0)) return std_logic is
begin
return not edv(1) and edv(0) ;
end rise ;
function fall(edv: STD_LOGIC_VECTOR (1 downto 0)) return std_logic is
begin
return edv(1) and not edv(0) ;
end fall ;
edge(clock,clkdiv(26),ed_cd26);
output <= rise(ed_cd26) ;
Any hints or suggestions for working procedures ?
Thanks in advance
MIKE
signals by using of subprograms. Unfortunately there are no examples on the
web (or difficult to find) how sequential procedures work.
Normally i use a sequential process to built a shift register for edge
detection:
process (clock)
begin
if (clock'event and clock ='1') then
shift(0) <= signal ;
shift(1) <= shift(0) ;
end if ;
rise <= not shift(1) and shift(0) ;
fall <= shift(1) and not shift(0) ;
end process;
Now i would like to use a procedure as a subprogram, to simplify the code
for lots of such situations.
As i understood, functions can not be used for sequential statements, but
procedures.
I tried some code, but it does't work:
procedure edge(
signal clk,din: in STD_LOGIC ;
signal edv: inout STD_LOGIC_VECTOR (1 downto 0)
) is
begin
if Rising_Edge(clk) then
edv(0) <= din ;
edv(1) <= edv(0) ;
end if;
end edge;
function rise(edv: STD_LOGIC_VECTOR (1 downto 0)) return std_logic is
begin
return not edv(1) and edv(0) ;
end rise ;
function fall(edv: STD_LOGIC_VECTOR (1 downto 0)) return std_logic is
begin
return edv(1) and not edv(0) ;
end fall ;
edge(clock,clkdiv(26),ed_cd26);
output <= rise(ed_cd26) ;
Any hints or suggestions for working procedures ?
Thanks in advance
MIKE