Electrical – detect rising edge and falling edge to assing signal to Enable

synchronousvhdl

I'm trying to create a process that detect the first rising edge of PGOOD signal and turn on ENABLE.
Then I need to detect the first falling edge of PGOOD and turn off ENABLE for good.
Here is what I tried but it doesn't work – the ENABLE is always '0'.
what am I missing?

process(PGOOD,CPLD_RESETn)
begin
if (CPLD_RESETn = '0')  then
             off <= '0';
elsif (falling_edge(PGOOD)) then
             off <=  '1';
end if;
end process;


process(PGOOD,CPLD_RESETn)
begin
if (CPLD_RESETn = '0')  then
             firstOn <=  '0';
elsif (rising_edge(PGOOD)) then
             firstOn <=  '1';
end if;
end process;

ENABLE <= firstOn and not(off);

Best Answer

enter image description here

I don't see anything wrong in your code. Your requirement seems to be met when I simulated the code. Enable went high on the first rising edge and went down when it detected the first falling edge afterwards. I think you forced the inputs in a wrong way.