Getting started with Atmel SAM4S-EK2

DAC

In this project, we'll use the DAC(Digital to Analog Convertor) to produce an analog signal on a pin. The pin can be configured in conf_dacc_sinewave_example.h.

There is an array containing 100 points of a sinewave sample. The frequency is set to 1000 in

g_ul_frequency = DEFAULT_FREQUENCY;

and amplitude to

g_l_amplitude = MAX_AMPLITUDE / 2;

Since in every second, there are "g_ul_frequency" sine waves and each having 100 sample point, there are a total of "g_ul_frequency 100" samples. Hence the SysTick_Config() has to be called every g_ul_frequency 100 per second. This is done by SysTick_Config().

SysTick_Config(sysclk_get_cpu_hz() / (g_ul_frequency * SAMPLES));

In this function, the DAC function is used.

dacc_write_conversion_data(DACC_BASE, dac_val);

The value of dac_val is

wave_to_dacc(gc_us_sine_data[g_ul_index_sample],
                     g_l_amplitude,
                     MAX_DIGITAL * 2, MAX_AMPLITUDE);

where wave_to_dacc is

(((int)(wave) * (amplitude) / (max_digital)) + (max_amplitude / 2))

max_amplitude is used so that while changing the amplitude, the value still remains non-negative. max_digital is The maximal sine wave sample data in the array.

Click here for project code