So I spent all evening yesterday and a chunk of this morning tracking down an anomaly...
It's this FPGA thing, again. Got a fair bunch of dedicated logic, for the real real-time functions (time scales down to 3.33ns), plus a supervisory MCU (AVR architecture), all synthesized in the FPGA.
There's a mildly contorted area of the dedicated logic that generates four status bits, indicating that various timing constraints have been violated. Those bits inhibit certain outputs, and are also readable by the MCU, in a special-purpose status register.
Well, yesterday I made the MCU-readable versions of those bits latching, with auto-clear after an MCU read of the register. This involved some rather untidy clock-domain crossings, and resulted in a pair of reported timing violations, which I examined closely and decided it was safe to ignore.
In general terms, the MCU generates a "clear" pulse lasting one bus cycle (50ns) after reading the register. The high-speed subsystem generates a "clear now" pulse lasting one internal clock cycle (3.33ns) based on a synchronized version of the MCU's clear pulse going from LOW to HIGH. For each bit, I have something like:
if (status) begin mcu_status <= 1; end else if (clear_now) begin mcu_status <= 0; end
And yet: from the MCU's perspective, none of the status bits ever go HIGH. They're stuck LOW, permanently. (Initially, this made sense, as I'd used the MCU's read, directly, as the CLEAR signal, but I soon fixed that.)
This morning, I routed first the CLEAR signal, then CLEAR and three of the four status bits, to FPGA pins connected to test points. And ya know what?
Right. The status bit got set when it should, and cleared on CLEAR, and the MCU could suddenly see it.
I'd demonstrated to the logic that it was in fact correct, and now it was working.
For my next amazing illusion, I removed those signals from the test points, put it back exactly the way it had been yesterday evening (modulo some new comments), and... you guessed it. Works like a charm.
I hate anthropomorphic firmware, that doubts itself and needs to have its correctness demonstrated to it before it'll work.
In other news: As I was typing this, a message arrived from OSH Park. The boards I ordered last Thursday just shipped. That company is looking less like a hobby resource and more like a serious-work resource all the time.