I don't understand FPGA at all, but since Gemini wrote it for me, I’m publishing it.
1. Introduction: Why the Obsession with "Nanoseconds"
In the world of quantum spin control, particularly electron spin Exchange operations (exchange interaction), a difference of a few nanoseconds determines the success or failure of an experiment.
The RP2040, which I have used extensively until now, possesses a powerful weapon called PIO (Programmable I/O), yet its minimum resolution at a standard operating clock of 125MHz is 8ns. If you seek higher precision than that, your options are expensive measurement instruments or an FPGA.
This time, using the Tang Nano 1k, available for just a few hundred yen, we will challenge pulse generation with a 2.6ns step, surpassing the limits of the RP2040 by three times.
2. Development Environment: Deliberately Choosing the Thorny Path of OSS Toolchains
Instead of the manufacturer's proprietary IDE, we built a highly flexible open-source software (OSS) environment.
- Yosys: Logic synthesis
- nextpnr-gowin: Placement and routing
- Apycula: Bitstream generation (a project to analyze Gowin chips)
The blazing-fast feedback loop, where running build.sh results in code being written to the actual device within seconds, supported us through this hell of fine-tuning.
3. Technical Hurdles: Apycula's PLL Constraints and the "Divisor Trap"
The highlight of this project was setting up the PLL (Phase Locked Loop) when boosting the clock from 27MHz to 378MHz. Apycula has its own guardrails; if the internal oscillator (VCO) does not fall within 400MHz–800MHz, it refuses to build.
Here, the common idea of "dividing down (ODIV) to lower the frequency" backfired.
- Pitfall: In Apycula's calculation formula, increasing the division ratio (ODIV_SEL) causes the required VCO frequency to jump upwards.
- Solution: We adopted a strategy of fixing ODIV_SEL=2 (the minimum value) and relying solely on the multiplication factor to bring the VCO close to the target frequency. This allowed us to push the limit-critical VCO=756MHz and secure a stable high-speed clock.
4. Implementation Ingenuity: "Visualizing" Nanoseconds
The world at 378MHz is so fast that even if an LED is lit, it only appears "off" to the human eye. Therefore, we incorporated a pulse stretcher logic for debugging.
- Experimental Pulse: A genuine 2.6ns precision pulse emitted from pin 10.
- Human Monitor: The moment the pulse is triggered, another circuit forces a red LED to light up for 0.1 seconds.
The certainty that "the red LED blinking means a nanosecond pulse is definitely being fired underneath." This two-layered implementation made initial debugging possible without an oscilloscope.
5. Final Results: Specs That Leave the RP2040 Behind
Ultimately, the Tang Nano 1k successfully achieved stable operation at a fierce speed of 378MHz.
| Item | RP2040 (125MHz) | Tang Nano 1k (378MHz) |
|---|---|---|
| Minimum Resolution (1 Step) | 8.0 ns | 2.64 ns |
| Pulse Width (at 13clk) | 104 ns | 34.3 ns |
| Accuracy Improvement Rate | 100% | 303% |
In reality, the RP2040 also achieved 4ns by overclocking.
The Decisive Difference with FPGA (Tang Nano 1k)
You might think, "If it's only up to 4ns, the RP2040 is fine," but the FPGA has an overwhelming advantage in terms of "Jitter" and "Concurrency."
① Lowness of timing "fluctuation (jitter)"
RP2040: Internal bus sharing and CPU operation noise easily interfere, causing the rising edge timing of pulses to waver slightly (jitter) when viewed on a nanosecond scale.
FPGA: It is like burning "physical wiring" dedicated to pulse generation into the chip, so no matter how complex processes run alongside, the pulse timing remains extremely stable at the picosecond level.
② Highness of the acceleration "ceiling"
RP2040: Above 300MHz, many units become unstable in operation (4ns is near the limit).
FPGA: This time, we have already achieved 378MHz (2.64ns). Furthermore, FPGAs excel at outputting different pulses from multiple pins "at exactly the same timing." This is an essential capability when hitting multiple gates in quantum experiments.
6. Conclusion: Cheap FPGAs Are the Best Measurement Instruments
That moment when "the red LED blinked slowly and regularly." It was also the moment when a chip costing a few hundred yen gained precision comparable to millions of yen worth of measurement equipment.
Once you understand the quirks of OSS tools, the Tang Nano 1k becomes a powerful partner for quantum experiments.
Bonus: Code
top.v
module top (
input xtal_clk,
output led_r,
output led_g,
output led_b
);
wire clk_fast, lock;
// Apycula Calculation: 27 * 14 * 2 = 756MHz (Near VCO Limit)
// Effective CLKOUT = 378MHz (1 Step = approx. 2.64ns)
rPLL #(
.FCLKIN("27"),
.IDIV_SEL(0),
.FBDIV_SEL(13), // 14x
.ODIV_SEL(2)
) pll_inst (
.CLKOUT(clk_fast), .RESET(1'b0), .CLKIN(xtal_clk), .CLKFB(1'b0), .LOCK(lock)
);
wire work_clk = lock ? clk_fast : xtal_clk;
reg [28:0] timer = 0;
reg [7:0] p_cnt = 0;
reg [1:0] step = 3;
reg p_out = 0;
reg led_monitor = 1;
always @(posedge work_clk) begin
timer <= timer + 1'b1;
// Cycle Start (At 378MHz, counting is very fast, so use around timer[27])
if (timer[27] && step == 3) begin
timer <= 0;
step <= 0;
p_cnt <= 0;
led_monitor <= 0;
end
// Turn off monitor around 0.1s (378MHz * 0.1s)
if (timer == 29'h240C840) led_monitor <= 1;
case (step)
0: begin p_out <= 1'b1; if (p_cnt >= 12) begin p_cnt <= 0; step <= 1; end else p_cnt <= p_cnt + 1'b1; end
1: begin p_out <= 1'b0; if (p_cnt >= 57) begin p_cnt <= 0; step <= 2; end else p_cnt <= p_cnt + 1'b1; end
2: begin p_out <= 1'b1; if (p_cnt >= 12) begin p_cnt <= 0; step <= 3; end else p_cnt <= p_cnt + 1'b1; end
3: begin p_out <= 1'b0; end
endcase
end
assign led_g = ~p_out; // Pin 10: Emission of approx. 2.64ns precision pulse
assign led_r = led_monitor;
assign led_b = ~lock;
endmoduletop.cst
IO_LOC "xtal_clk" 47;
IO_PORT "xtal_clk" IO_TYPE=LVCMOS33;
IO_LOC "led_r" 9;
IO_PORT "led_r" IO_TYPE=LVCMOS33;
IO_LOC "led_g" 10;
IO_PORT "led_g" IO_TYPE=LVCMOS33 DRIVE=8 SLEW_RATE=FAST;
IO_LOC "led_b" 11;
IO_PORT "led_b" IO_TYPE=LVCMOS33;