Will counters stay in sync at rollover?
Basher
Posts: 25
I've got a cog generating VGA video at 312 scan lines per frame (for PAL video through a ad273)
I want a second cog to be able to tell which scan line the video cog is producing at any point.
My idea for doing this is to set up both counters of the second cog.
counter a would add one count every time the hsync pin goes low
counter b would add 312 to its count every time the vsync pin goes low
then I read both counters subtract b from a and be left with the scan line the video cog is presently on.
Frame 0 : counterA = 5 counterB = 0 result scanline = 5
Frame 1 : counterA = 317 counterB = 312 result scanline = 5
etc
I'd have to make sure the vsync doesn't change inbetween reading the two counters but other than that the result of a SUB counterA,counterB instruction should, as far as I can see, be the scan line that the video cog is presently on.
What I can't work out is what will happen when one or both of the counters fill up and rollover.
What I want and hope will happen is that the numbers will stay in sync and the sub instruction will continue to produce the scan line number.
But I've got a funny feeling that something odd might happen, either a tempory glitch or a new sequence will start.
Can anybody tell me if this will work and if not why not and possibly point me towards a better solution.
Thanks
I want a second cog to be able to tell which scan line the video cog is producing at any point.
My idea for doing this is to set up both counters of the second cog.
counter a would add one count every time the hsync pin goes low
counter b would add 312 to its count every time the vsync pin goes low
then I read both counters subtract b from a and be left with the scan line the video cog is presently on.
Frame 0 : counterA = 5 counterB = 0 result scanline = 5
Frame 1 : counterA = 317 counterB = 312 result scanline = 5
etc
I'd have to make sure the vsync doesn't change inbetween reading the two counters but other than that the result of a SUB counterA,counterB instruction should, as far as I can see, be the scan line that the video cog is presently on.
What I can't work out is what will happen when one or both of the counters fill up and rollover.
What I want and hope will happen is that the numbers will stay in sync and the sub instruction will continue to produce the scan line number.
But I've got a funny feeling that something odd might happen, either a tempory glitch or a new sequence will start.
Can anybody tell me if this will work and if not why not and possibly point me towards a better solution.
Thanks
Comments
-Phil
There are some games and demos for the spectrum that count z80 machine cycles to workout where the scanline has reached to produce multicolour effects by changing a colour attribute byte just ahead of the scan. I'm trying to get my interface to respond more accuratly to these programs.
If I can get the counter idea working the next step would be to increase the resolution even further to divide the scanlines up into the equivilent of the z80 t-states.
Can you use only the counters of the second cog? A software solution with PASM code seems easier and more reliable, if you use anyway a second cog.
Andy
Perhaps putting those signals through a 74HC14 schmitt-trigger inverter might be a useful precaution....
Can't really see 1980's hardware being able to generate a fast enough edge (besides doesn't there have to be
a level-shifter anyway - if that has schmidt-trigger inputs all should be well).
Why not throw in an AY-3-8910 in a cog for the full "spectrum 128" sound experience?
/Johannes