Skip to content

File syn_dds.c

FileList > dsp > syn_dds.c

Go to the source code of this file

Direct Digital Synthesis (DDS) Waveform Synthesizer implementation.

  • #include "syn_dds.h"
  • #include "../util/syn_random.h"
  • #include <string.h>

Public Functions

Type Name
SYN_Status syn_dds_fill_q16 (SYN_DDS * dds, q16_t * buf, size_t count)
Fill a Q16.16 buffer with consecutive DDS samples.
SYN_Status syn_dds_fill_u16 (SYN_DDS * dds, uint16_t * buf, size_t count, uint16_t dac_center, uint16_t dac_span)
Fill a unsigned 16-bit integer buffer for DAC DMA output.
SYN_Status syn_dds_init (SYN_DDS * dds, SYN_DDS_Waveform type, uint32_t freq_hz, uint32_t sample_rate_hz)
Initialize a DDS Generator instance.
SYN_Status syn_dds_set_duty (SYN_DDS * dds, float duty_pct)
Set PWM duty cycle (for SYN_DDS_SQUARE mode).
SYN_Status syn_dds_set_freq (SYN_DDS * dds, uint32_t freq_hz, uint32_t sample_rate_hz)
Set the output frequency of the DDS generator.
SYN_Status syn_dds_set_gain (SYN_DDS * dds, q16_t amplitude, q16_t offset)
Set the peak amplitude and DC offset.
q16_t syn_dds_step (SYN_DDS * dds)
Compute and advance the DDS generator by one sample step.

Public Functions Documentation

function syn_dds_fill_q16

Fill a Q16.16 buffer with consecutive DDS samples.

SYN_Status syn_dds_fill_q16 (
    SYN_DDS * dds,
    q16_t * buf,
    size_t count
) 

Parameters:

  • dds Pointer to DDS instance.
  • buf Output Q16.16 buffer.
  • count Number of samples to generate.

Returns:

SYN_OK on success.


function syn_dds_fill_u16

Fill a unsigned 16-bit integer buffer for DAC DMA output.

SYN_Status syn_dds_fill_u16 (
    SYN_DDS * dds,
    uint16_t * buf,
    size_t count,
    uint16_t dac_center,
    uint16_t dac_span
) 

Parameters:

  • dds Pointer to DDS instance.
  • buf Output 16-bit DAC buffer.
  • count Number of samples.
  • dac_center Center DAC value (e.g. 2048 for 12-bit DAC).
  • dac_span Maximum peak-to-peak DAC range (e.g. 2047).

Returns:

SYN_OK on success.


function syn_dds_init

Initialize a DDS Generator instance.

SYN_Status syn_dds_init (
    SYN_DDS * dds,
    SYN_DDS_Waveform type,
    uint32_t freq_hz,
    uint32_t sample_rate_hz
) 

Parameters:

  • dds Pointer to DDS instance.
  • type Waveform type.
  • freq_hz Target output frequency in Hz.
  • sample_rate_hz Sample rate in Hz.

Returns:

SYN_OK on success, or SYN_INVALID_PARAM.


function syn_dds_set_duty

Set PWM duty cycle (for SYN_DDS_SQUARE mode).

SYN_Status syn_dds_set_duty (
    SYN_DDS * dds,
    float duty_pct
) 

Parameters:

  • dds Pointer to DDS instance.
  • duty_pct Duty cycle percentage (0.0 to 100.0%).

Returns:

SYN_OK on success.


function syn_dds_set_freq

Set the output frequency of the DDS generator.

SYN_Status syn_dds_set_freq (
    SYN_DDS * dds,
    uint32_t freq_hz,
    uint32_t sample_rate_hz
) 

Parameters:

  • dds Pointer to DDS instance.
  • freq_hz Output frequency in Hz.
  • sample_rate_hz Sample rate in Hz.

Returns:

SYN_OK on success.


function syn_dds_set_gain

Set the peak amplitude and DC offset.

SYN_Status syn_dds_set_gain (
    SYN_DDS * dds,
    q16_t amplitude,
    q16_t offset
) 

Parameters:

  • dds Pointer to DDS instance.
  • amplitude Q16.16 peak amplitude.
  • offset Q16.16 DC offset.

Returns:

SYN_OK on success.


function syn_dds_step

Compute and advance the DDS generator by one sample step.

q16_t syn_dds_step (
    SYN_DDS * dds
) 

Parameters:

  • dds Pointer to DDS instance.

Returns:

Generated sample in Q16.16 fixed-point format.



The documentation for this class was generated from the following file src/syntropic/dsp/syn_dds.c