Skip to content

File syn_dac.h

FileList > drivers > syn_dac.h

Go to the source code of this file

DAC (Digital-to-Analog Converter) driver. More...

  • #include "../common/syn_defs.h"
  • #include "../port/syn_port_dac.h"
  • #include <stdint.h>

Classes

Type Name
struct SYN_DAC
DAC channel handle. Caller allocates; zero heap.

Public Functions

Type Name
SYN_Status syn_dac_init (SYN_DAC * dac, uint8_t channel)
Initialize a DAC channel.
uint16_t syn_dac_max_raw (const SYN_DAC * dac)
Return the maximum raw value for this DAC (2^resolution - 1).
SYN_Status syn_dac_write_mv (const SYN_DAC * dac, uint16_t mv)
Write a millivolt target to the DAC.
SYN_Status syn_dac_write_percent (const SYN_DAC * dac, uint8_t percent)
Write a percentage of full scale to the DAC.
SYN_Status syn_dac_write_raw (const SYN_DAC * dac, uint16_t raw)
Write a raw count value to the DAC.

Detailed Description

Thin wrapper over syn_port_dac.h, mirroring the pattern of syn_adc.h. Provides raw-count, millivolt, and percent write helpers.

Usage:

SYN_DAC dac;
syn_dac_init(&dac, 0);           // channel 0
syn_dac_write_mv(&dac, 1650);    // 1.65 V (half of 3.3 V ref)

Public Functions Documentation

function syn_dac_init

Initialize a DAC channel.

SYN_Status syn_dac_init (
    SYN_DAC * dac,
    uint8_t channel
) 

Parameters:

  • dac Handle to initialize. Must not be NULL.
  • channel Platform DAC channel index.

Returns:

SYN_OK on success, SYN_ERROR on hardware failure.


function syn_dac_max_raw

Return the maximum raw value for this DAC (2^resolution - 1).

uint16_t syn_dac_max_raw (
    const SYN_DAC * dac
) 

Parameters:

  • dac Initialized DAC handle (channel field used to query port).

Returns:

Maximum raw count (e.g. 4095 for 12-bit).


function syn_dac_write_mv

Write a millivolt target to the DAC.

SYN_Status syn_dac_write_mv (
    const SYN_DAC * dac,
    uint16_t mv
) 

Clamps to the reference voltage automatically.

Parameters:

  • dac Initialized DAC handle.
  • mv Desired output voltage in millivolts.

Returns:

SYN_OK on success.


function syn_dac_write_percent

Write a percentage of full scale to the DAC.

SYN_Status syn_dac_write_percent (
    const SYN_DAC * dac,
    uint8_t percent
) 

Parameters:

  • dac Initialized DAC handle.
  • percent 0 = 0 V, 100 = full reference voltage. Values > 100 are clamped to 100.

Returns:

SYN_OK on success.


function syn_dac_write_raw

Write a raw count value to the DAC.

SYN_Status syn_dac_write_raw (
    const SYN_DAC * dac,
    uint16_t raw
) 

Parameters:

  • dac Initialized DAC handle.
  • raw Value in range [0, syn_dac_max_raw(dac)].

Returns:

SYN_OK on success.



The documentation for this class was generated from the following file src/syntropic/drivers/syn_dac.h