class::hal::Dac

class hal::Dac
  : public hal::Periph< dac_info_t, dac_attr_t, DacAttributes, 'd'>

DAC (Digital to Analog Converter) Class

The DAC class is used to write data to the digital to analog converter. Here is an example:

#include <sapi/hal.hpp>
#include <sapi/sys.hpp>

int main(int argc, char * argv[]){
   Dac dac(0);
   u32 samples[50];
   dac.init(); //init with default settings

 //here, write meaningful values to samples

   dac.write(0, samples, 50*sizeof(u32)); //This returns when all 50 samples are written

 //if you want to do other things while the sample is written use AIO
   Aio aio(samples, 50*sizeof(u32));

   dac.write(aio);
 //Here you can do other things while the data is written
   while( aio.is_busy() == true ){
      Timer::wait_usec(500); //wait until the write is complete
   }

   dac.close(); //this will power off the DAC if nothing else has it open

   return 0;
}

Summary

Dac(

port_t port
)

u32 get_channel(

u32 loc
) const

int init(

u32 o_flags,
u32 freq,
const dac_pin_assignment_t * pin_assignment
)

int set_attr(

u32 o_flags,
u32 freq,
const dac_pin_assignment_t * pin_assignment
) const

int set_channel(

u32 loc,
u32 value
) const

enum dac_flags

Members

Dac(

port_t port
)


u32 get_channel(

u32 loc
) const

Gets the current value of the DAC channel.

Parameters

  • loc The DAC channel to get

Returns

The current value of the channel or (u32)-1 if ther is an error


int init(

u32 o_flags,
u32 freq,
const dac_pin_assignment_t * pin_assignment
)

Opens the DAC and sets the attributes using specified values.

See set_attr() for parameter descriptions.


int set_attr(

u32 o_flags,
u32 freq,
const dac_pin_assignment_t * pin_assignment
) const

Sets the DAC attributes using specified values.

Parameters

  • o_flags Enabled channels as a bitmask

  • freq DAC output frequency

  • pin_assignment The pins to use (if null, default pins will be used if available)


int set_channel(

u32 loc,
u32 value
) const

Sets the value of the DAC channel.

Parameters

  • value Value to write to the DAC

  • loc The DAC channel

Returns

Zero on success


enum dac_flags
  • SET_CONVERTER Set to configure the converter
  • LEFT_JUSTIFIED Set to left justify the data
  • RIGHT_JUSTIFIED Set to right justify the data

X

Thanks for Coming!

Subscribe to news and updates