I could use some help with my first-ever VHDL project...
Trying to create a "retro video upscaler", to convert a composite signal from my 1973 PONG board to XGA output (with added simulated scan lines and a bit of blur). I have built an analog splitter to separate the sync and intensity signals, and can successfully read the resulting two 1-bit signals into the FPGA, a Xilinx Spartan 3A, and echo them back via two outputs.
But I have not managed to create a simple digital integrator, to identify the (longer) vertical sync pulses. My integration counter does not behave as expected. Here is a stripped-down version, which does not compare the integrator to a threshold yet, but simply checks whether is has decayed back to zero or is non-zero, and outputs that status via an FPGA output:
entity SyncSplit is
Port (
clk: in STD_LOGIC;
csync: in STD_LOGIC;
vsync: out STD_LOGIC
);
end SyncSplit;
architecture Behavioral of SyncSplit is
begin
process is
variable isync: natural := 0; -- integrated sync signal
begin
-- The process is carried out for every positive edge of the clock
wait until clk = '1';
-- integrate vertical sync signal
if csync='0' then
if isync>0 then isync := isync-1; end if; -- decay
else
isync := isync+1; -- increase
end if;
-- test: indicate on output whether intregrator is zero
if (isync = 0) then vsync <= '0';
else vsync <= '1';
end if;
end process;
end Behavioral;
"csync" is the composite sync input, active high. I.e. it is mostly zero, with short high phases for the line syncs, and a longer high phase for the vertical sync (interrupted by short inverted line sync).
The integrator value "isync" should rise during the active high period of the csync input, the decay again after csync goes back to low. I.e. it should remain non-zero for twice the "csync = high" phase, the stay at zero for the rest of the scan line. The "vsync" output should echo this behaviour.
Indeed, when I look at the "vsync" output with a scope, it shows short bursts (a few scan lines) where is behaves as expected. But then it goes back to high (suggesting isync > 0) and stays there, often for several full composite frames. The duration of both, the "works as expected" and the "stays high" phases, seem random. I have attached a scope screenshot, although I don't think it tells much more -- channel 1 is the "csync" input, channel 2 the "vsync" output.
I must be overlooking something fundamental here. Isn't variable declared in a process guaranteed to be persistent? Am I doing something stupid in the VHDL code?
Many thanks for any pointers you might have!
EDIT: For quick future reference, the solution to my conundrum is in post #15 by hamster_nz below. Thanks to hamster_nz and all other posters for helpful hints!