Altera_Forum
Honored Contributor
11 years agoPush-button counter
hi again
this has got me stumped, yet I think it should be so easy ! I'm trying to display a horizontal bar in VGA (which I can do) and then have the bar rotate by 1 degree every time I push a button. I've created a sine and cosine array of values from 0 to 90 degrees for this, and I want to step through these arrays with an integer 'k' every time I press the button (active high). Following is the code I'm using to increment k :- entity bar_gen is port ( vidon : in std_logic ; -- vidon=1 when hc and vc are in the visible display area, else =0. pbut : in std_logic:='0'; -- push button to rotate bar by 1 degree for every button push. Connected to Button input in top-level entity by pbut<=Button. hc : in unsigned (9 downto 0); -- hc , horizontal pixel count from vga_640x480 generator vc : in unsigned (9 downto 0); -- vc , vertical " " " rgb : out unsigned(2 downto 0) -- holds 3 colours, rgb(2)=red, rgb(1)=green, rgb(0)=blue ); end bar_gen; process(vidon,hc,vc,pbut) if vidon = '1' then -- cursor is in the visible area of the display if pbut='1' then -- pushbutton not pushed k:=k+1; end if; ...... use the value of k to select an element from the array and draw new line. end process; This produced 'inferred latch' warnings for 'k'. Reading up on this on the internet, I thought I understood that this was caused by the code requiring a latch to hold the new value of 'k' , which is not recommended ! The solution seems to be to introduce a previous value for k also, which I call prevk, also an integer. I've tried dozens of permutations of the following, but I still get the same 'inferred latch' warnings. This is what I thought should work, but doesn't. What am I missing ? process(vidon,hc,vc,pbut) if vidon = '1' then if pbut='0' then k:=prevk; else k:=prevk + 1; end if; prevk:=k; ...... draw new line, etc. end process; Note that I don't have a clock source for this entity. Thanks in advance for any help.