litex/milkymist/dvisampler/resdetection.py

50 lines
1.2 KiB
Python
Raw Normal View History

2013-03-23 19:45:29 -04:00
from migen.fhdl.structure import *
from migen.fhdl.module import Module
from migen.genlib.cdc import MultiReg
from migen.bank.description import *
2013-03-30 12:28:15 -04:00
class ResolutionDetection(Module, AutoCSR):
def __init__(self, nbits=11):
2013-03-23 19:45:29 -04:00
self.vsync = Signal()
self.de = Signal()
2013-03-30 12:28:15 -04:00
self._hres = CSRStatus(nbits)
self._vres = CSRStatus(nbits)
2013-03-23 19:45:29 -04:00
###
# Detect DE transitions
de_r = Signal()
pn_de = Signal()
self.sync.pix += de_r.eq(self.de)
self.comb += pn_de.eq(~self.de & de_r)
2013-03-23 19:45:29 -04:00
# HRES
2013-03-23 19:45:29 -04:00
hcounter = Signal(nbits)
self.sync.pix += If(self.de,
2013-03-23 19:45:29 -04:00
hcounter.eq(hcounter + 1)
).Else(
hcounter.eq(0)
2013-03-23 19:45:29 -04:00
)
hcounter_st = Signal(nbits)
self.sync.pix += If(pn_de, hcounter_st.eq(hcounter))
2013-03-30 12:28:15 -04:00
self.specials += MultiReg(hcounter_st, self._hres.status)
2013-03-23 19:45:29 -04:00
# VRES
vsync_r = Signal()
p_vsync = Signal()
self.sync.pix += vsync_r.eq(self.vsync),
self.comb += p_vsync.eq(self.vsync & ~vsync_r)
2013-03-23 19:45:29 -04:00
vcounter = Signal(nbits)
self.sync.pix += If(p_vsync,
vcounter.eq(0)
).Elif(pn_de,
vcounter.eq(vcounter + 1)
2013-03-23 19:45:29 -04:00
)
vcounter_st = Signal(nbits)
self.sync.pix += If(p_vsync, vcounter_st.eq(vcounter))
self.specials += MultiReg(vcounter_st, self._vres.status)