Altera_Forum
Honored Contributor
16 years agoFlipflop clock domain crossing
Hi,
I'm still fairly new to hardware design, so please bear with me. I'm designing a double-scanlinebuffer for my sprite renderer. While the VGA controller (at 25.175MHz) is displaying the pixel data from scanlinebuffer[0], a faster clock (100MHz) is filling scanlinebuffer[1] with new pixeldata. At some point, when the vga controller has completed a line, it will switch and display the pixel data from scanlinebuffer[1], and the faster clock will start filling scanlinebuffer[0], and after another line is displayed, this whole process will repeat. Now, this process has a problem: the scanlinebuffer needs to be cleared when the fast clock begins to fill it. Clearing the scanlinebuffer will take alot of cycles, which is not acceptable. My idea then was to use a line mask buffer, which has an single bit entry for each pixel: 1 means the pixel has been set in the scanlinebuffer, 0 means the displayed pixel should be the background color. This line mask buffer is also double buffered, and is implemented using 2x 20x32bit flipflops. In this way, I can clear all 20 flipflops in a single clock cycle. What I am uncertain about, is the fact that this double-linemask buffer will be clocked with the fast clock, while its data will be read by vga clock. Note though, that because of the double buffering scheme, when the vga clock is reading linemaskbuffer[0], the fast clock will not be changing this buffer, but only linemaskbuffer[1]. The question I have is, will this way cause problems? Are there any dangers I need to be aware of? And, as a purely theoretical last question, since I am using dual-clock RAM for the scanlinebuffer (read-clk is the vga clock, write-clk is the fast 100MHz clk), would it be possible to make this single-clock RAM, and switch clocks during the double buffer switch? Thanks in advance