- Joined
- Oct 5, 2007
- Messages
- 6
- Reaction score
- 0
Hello again, I have two questions actually...
1) What is a good way to code a switch debouncer? I'm stuck as far as having a single bouncy switch signal and I have to take care of it inside a CPLD. I tried clocking the input into a signal, and this worked fine, but I have to have the frequency up to 32Hz which eats flip-flops for other things. is there a better way so I can slow down my clock and save space?
2)I've been trying to implement some code that gives me a variable one-shot. So far I have:
where elsewhere in the code i specify how long I want the pulse to last (SETCNT). This works fine if timers are constantly cycling, but I need it to stay low until a state change. I know I'd need to take the cnt := 0 line out of the line where timer goes low...but I'm not sure how I can set it to zero later. The reset is a power-on reset. Any help would be much appreciated
1) What is a good way to code a switch debouncer? I'm stuck as far as having a single bouncy switch signal and I have to take care of it inside a CPLD. I tried clocking the input into a signal, and this worked fine, but I have to have the frequency up to 32Hz which eats flip-flops for other things. is there a better way so I can slow down my clock and save space?
2)I've been trying to implement some code that gives me a variable one-shot. So far I have:
Code:
Process (CLK, reset)
variable CNT: integer range 0 to 319;
begin
if (reset = '0') then --power on reset active = timer inactive
timer <= '1';
CNT := 0;
elsif (rising_edge(CLK)) then
if (CNT = SETCNT - 1) then --count has reach goal
cnt := 0;
timer <= '0';
else
timer <= '1';
cnt := cnt + 1;
end if;
end if;
end process;
where elsewhere in the code i specify how long I want the pulse to last (SETCNT). This works fine if timers are constantly cycling, but I need it to stay low until a state change. I know I'd need to take the cnt := 0 line out of the line where timer goes low...but I'm not sure how I can set it to zero later. The reset is a power-on reset. Any help would be much appreciated