Hi Amir
I think that you need to beware that the referenced DAC example looks to use 100% of the processor's power to generate a signal and also has a fixed frequency that can't really be controlled during operation. This may be OK for a school project to get to know the basic DAC's operation but will be (as also discussed at the link a little) of limited use in real developments.
Below is the code that I use, in order to show that it is very simple to control powerful DMA based operation that will allow the output to also continue running when the processor itself is stopped by the debugger, with almost no CPU performance impact. This code will in fact run on ANY Kinetis (K, KL, KV, KM, etc.) part as long as it has a DMA controller in it.
The only thing to be aware of if you use the KL25 is that the mask 2N97F has an errata with its PIT triggered DMA and the generated frequency will in fact be 2x the expected rate, but it otherwise still works....
Regards
Mark
#define LENGTH_OF_SINE_BUFFER 128
static void fnConfigurePIT(void)
{
static unsigned short *ptrSineBuffer = 0;
DAC_SETUP dac_setup;
PIT_SETUP pit_setup;
pit_setup.int_type = PIT_INTERRUPT;
pit_setup.int_priority = PIT0_INTERRUPT_PRIORITY;
pit_setup.count_delay = PIT_US_DELAY(100);
pit_setup.mode = (PIT_PERIODIC);
pit_setup.int_handler = 0;
ptrSineBuffer = uMallocAlign((LENGTH_OF_SINE_BUFFER * sizeof(unsigned short)), (LENGTH_OF_SINE_BUFFER * sizeof(unsigned short)));
{
#define PI (double)3.14159265
#define ANGLE_STEP (double)((double)(2 * PI)/(double)LENGTH_OF_SINE_BUFFER);
int i;
double angle = 0;
for (i = 0; i < LENGTH_OF_SINE_BUFFER; i++) {
ptrSineBuffer[i] = (unsigned short)((sin(angle) * 0x7ff) + (0xfff/2));
angle += ANGLE_STEP;
}
}
pit_setup.ucPIT = 0;
fnConfigureInterrupt((void *)&pit_setup);
dac_setup.int_type = DAC_INTERRUPT;
dac_setup.int_dac_controller = 0;
dac_setup.int_handler = 0;
dac_setup.int_priority = 15;
dac_setup.dac_mode = (DAC_CONFIGURE | DAC_REF_VDDA | DAC_NON_BUFFERED_MODE | DAC_FULL_BUFFER_DMA | DAC_ENABLE | DAC_BUFFER_DMA_START);
dac_setup.ptrDAC_Buffer = ptrSineBuffer;
dac_setup.ulDAC_buffer_length = (LENGTH_OF_SINE_BUFFER * sizeof(unsigned short));
dac_setup.ucDmaChannel = 0;
dac_setup.ucDmaTriggerSource = DMAMUX0_DMA0_CHCFG_SOURCE_PIT0;
dac_setup.dac_mode |= DAC_HW_TRIGGER_MODE;
fnConfigureInterrupt((void *)&dac_setup);
}