Core Module contains two analog outputs: DAC0 and DAC1. These are real analog outputs, not just PWM outputs.

Example

Both channels can run completely separately with different samplerate. First you need to prepare the output buffer. In this example there's a sine wave lookup table. The sampling is set on BC_DAC_SAMPLE_RATE_16K. This together generates on DAC0 ouput 125 Hz sine-wave.

#include <application.h>

const uint8_t sine_wave[] = {
  0x80, 0x86, 0x8C, 0x93,
  0x99, 0x9F, 0xA5, 0xAB,
  0xB1, 0xB6, 0xBC, 0xC1,
  0xC7, 0xCC, 0xD1, 0xD5,
  0xDA, 0xDE, 0xE2, 0xE6,
  0xEA, 0xED, 0xF0, 0xF3,
  0xF5, 0xF8, 0xFA, 0xFB,
  0xFD, 0xFE, 0xFE, 0xFF,
  0xFF, 0xFF, 0xFE, 0xFE,
  0xFD, 0xFB, 0xFA, 0xF8,
  0xF5, 0xF3, 0xF0, 0xED,
  0xEA, 0xE6, 0xE2, 0xDE,
  0xDA, 0xD5, 0xD1, 0xCC,
  0xC7, 0xC1, 0xBC, 0xB6,
  0xB1, 0xAB, 0xA5, 0x9F,
  0x99, 0x93, 0x8C, 0x86,
  0x80, 0x7A, 0x74, 0x6D,
  0x67, 0x61, 0x5B, 0x55,
  0x4F, 0x4A, 0x44, 0x3F,
  0x39, 0x34, 0x2F, 0x2B,
  0x26, 0x22, 0x1E, 0x1A,
  0x16, 0x13, 0x10, 0x0D,
  0x0B, 0x08, 0x06, 0x05,
  0x03, 0x02, 0x02, 0x01,
  0x01, 0x01, 0x02, 0x02,
  0x03, 0x05, 0x06, 0x08,
  0x0B, 0x0D, 0x10, 0x13,
  0x16, 0x1A, 0x1E, 0x22,
  0x26, 0x2B, 0x2F, 0x34,
  0x39, 0x3F, 0x44, 0x4A,
  0x4F, 0x55, 0x5B, 0x61,
  0x67, 0x6D, 0x74, 0x7A
};

void application_init(void)
{
    bc_dac_init(BC_DAC_DAC0);

    bc_dac_config_t dac_config;

    dac_config.buffer = (uint8_t*)sine_wave;
    dac_config.length = sizeof(sine_wave);
    dac_config.data_size = BC_DAC_DATA_SIZE_8;
    dac_config.mode = BC_DAC_MODE_CIRCULAR;
    dac_config.sample_rate = BC_DAC_SAMPLE_RATE_16K;

    bc_dac_async_config(BC_DAC_DAC0, &dac_config);

    bc_dac_async_run(BC_DAC_DAC0);
}

Chapters in this document:
Edit this page

We will inspire you!

You will get regularly our Clownsletter with real projects from other Makers. Do not miss it!

By sign up you will know how even you can inspire others and get €100 discount coupon!