Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio frequency issue #51

Open
andreondra opened this issue Feb 21, 2025 · 1 comment
Open

Audio frequency issue #51

andreondra opened this issue Feb 21, 2025 · 1 comment

Comments

@andreondra
Copy link

andreondra commented Feb 21, 2025

First of all, thank you for such a great project!

I have a strange issue with the sound output. The image works perfectly without any problems, both in my CPU project and in the hdmi-demo project. I use Nexys Video devboard.

However, in both projects I have an issue with the audio frequency. In both projects a sawtooth waveform with a certain frequency is generated: in my project I tried various freqs, in the hdmi-demo it is 480 Hz if I see correctly. For debugging, I use my HDMI monitor with an audio output (via 3.5mm jack). I measured the frequency of the signal coming from the jack in two ways to mitigate a measurement error:

  • I connected the speakers, recorded the audio and then measured the frequency,
  • I connected the oscilloscope and measured the frequency directly in the instrument.

I found out that in both projects the frequency is always approximately double. See the measurement of the waveform generated by the hdmi-utils demo:
Image.

I also measured the frequency of the generated audio_clk, it seems correct.

Do you have any idea what the issue may be? Is this a known issue, or maybe I do something wrong? If this occurred only in my project I wouldn't be surprised but the same issue is also in the demo project. And my monitor (which I also suspected) is working correctly, because if I connect a computer and generate an arbitrary waveform, the frequency is OK.

Edit: so it seems that modifying the audio_clk generator in the demo like this:

// from this
assign clk_audio = clk_pixel && counter == 11'd1546;
// to this
assign clk_audio = counter == 11'd1546;

Fixes the issue. In the Questa Sim I saw a glitch caused by the clk_pixel &&. So -- in my design a have probably the same issue, will investigate.

@andreondra
Copy link
Author

I just found out that in my project it can be fixed by handling the audio_clk correctly -- not using timer's value directly as a clock, but passing the value to a clock buffer with CE:

  always_ff @( posedge hdmi_clk ) begin : audio_clk_gen_proc
      if (reset || audio_clk_timer == 524) begin
          audio_clk_timer <= 'h0;
      end else begin
          audio_clk_timer <= audio_clk_timer + 1;
      end
  end

  BUFGCE #(
      .CE_TYPE("SYNC"),
      .IS_CE_INVERTED(1'b0),
      .IS_I_INVERTED(1'b0),
      .SIM_DEVICE("VERSAL_PRIME")
  )
  BUFGCE_inst (
      .O(audio_clk),
      .CE(audio_clk_timer == 0),
      .I(hdmi_clk)
  );

The first approach (without buffer) probably introduced glitches which triggered the clock multiple times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant