From 82def6b535234f89b1ebc87752ee0ca6ccc25779 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 12 Jul 2018 17:05:18 +0800 Subject: [PATCH] grabber: add frequency counter Cameras are a bit obscure about what they output, this can help with troubleshooting. --- artiq/firmware/libboard_artiq/grabber.rs | 10 ++++++++- artiq/gateware/grabber/core.py | 28 ++++++++++++++++++++++++ artiq/gateware/rtio/phy/grabber.py | 6 ++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/artiq/firmware/libboard_artiq/grabber.rs b/artiq/firmware/libboard_artiq/grabber.rs index 7df41d3cc..272b44447 100644 --- a/artiq/firmware/libboard_artiq/grabber.rs +++ b/artiq/firmware/libboard_artiq/grabber.rs @@ -76,6 +76,13 @@ fn get_last_pixels(g: usize) -> (u16, u16) { (csr::GRABBER[g].last_y_read)()) } } +fn get_video_clock(g: usize) -> u32 { + let freq_count = unsafe { + (csr::GRABBER[g].freq_count_read)() + } as u32; + 2*freq_count*(csr::CONFIG_CLOCK_FREQUENCY/1000000)/255 +} + pub fn tick() { for g in 0..csr::GRABBER.len() { if unsafe { GRABBER_STATE[g] != State::Down } { @@ -86,8 +93,9 @@ pub fn tick() { } if unsafe { GRABBER_STATE[g] == State::WaitResolution } { let (last_x, last_y) = get_last_pixels(g); - info!("grabber{} detected frame size: {}x{}", + info!("grabber{} frame size: {}x{}", g, last_x + 1, last_y + 1); + info!("grabber{} video clock: {}MHz", g, get_video_clock(g)); unsafe { GRABBER_STATE[g] = State::Up; } } } else { diff --git a/artiq/gateware/grabber/core.py b/artiq/gateware/grabber/core.py index 03c185859..477f11796 100644 --- a/artiq/gateware/grabber/core.py +++ b/artiq/gateware/grabber/core.py @@ -3,6 +3,34 @@ from migen.genlib.cdc import MultiReg from misoc.interconnect.csr import * +class FrequencyCounter(Module, AutoCSR): + def __init__(self, width=8): + self.freq_count = CSRStatus(width) + + # # # + + toggle = Signal(reset_less=True) + toggle_sys = Signal() + toggle.attr.add("no_retiming") + self.sync.cl += toggle.eq(~toggle) + self.specials += MultiReg(toggle, toggle_sys) + + timer = Signal(width+1) + tick = Signal(reset=1) + count = Signal(width) + toggle_sys_r = Signal() + self.sync += [ + Cat(timer, tick).eq(timer + 1), + toggle_sys_r.eq(toggle_sys), + If(tick, + self.freq_count.status.eq(count), + count.eq(0) + ).Else( + If(toggle_sys & ~toggle_sys_r, count.eq(count + 1)) + ) + ] + + bitseq = [ # 0 1 2 3 4 5 6 6, 5, 4, 3, 2, 1, 27, diff --git a/artiq/gateware/rtio/phy/grabber.py b/artiq/gateware/rtio/phy/grabber.py index 5639cfaae..a6c891e50 100644 --- a/artiq/gateware/rtio/phy/grabber.py +++ b/artiq/gateware/rtio/phy/grabber.py @@ -12,8 +12,12 @@ class Grabber(Module): rtlink.IInterface(10)) self.submodules.deserializer = deserializer_7series.Deserializer(pins) + self.submodules.frequency_counter = FrequencyCounter() self.submodules.parser = Parser() self.comb += self.parser.cl.eq(self.deserializer.q) def get_csrs(self): - return self.deserializer.get_csrs() + self.parser.get_csrs() + return ( + self.deserializer.get_csrs() + + self.frequency_counter.get_csrs() + + self.parser.get_csrs())