Hi All,
I am using KDS IDE and K22F Kinetis board. I want to implement simple Digital - Analog converter. I am trying using Processor Expert. The configuration done is as shown below.
I add "DAC_LDD" component. Since the MCU supports only 1 DAC, i.e "DAC0_OUT/CMP1_IN3/ADC0_SE23".
I use 12 bit resolution as it supports 12-bit.
No interrupts.
No hardware buffer
No DMA
Enable in init code
Autoinitialisation.
In main loop, I call
for (;;) {
Error = DA1_SetValue(NULL, 4095U); /* Set converter output */
}
Value of Error is 0 which mean setting value was successful. I also see all the registers are set properly. I try to measure value on the DAC_output pin using multimeter. I expect the value to be 3.3V. But I am getting few milli volts which means DAC is not working properly. Can some one please tell me if I am missing something. Thanks a lot in advance.
Also, why would one use DMA with DAC? Using DMA with ADC makes sense. But why with DAC?
Message was edited by: Vishal Girisagar
Solved! Go to Solution.
Hi Vishal,
Please set the voltage reference in the DAC component to "external" from "internal".
I also added in a delay loop (polling) so it doesn't change too fast as I used a Voltmeter to watch the DAC output.
Regards,
David
Hi Vishal,
I haven't had time to dig deeper but first impression is maybe the PORT clock is not enabled, and the PCR register MUX not programmed.
Regards,
David
Hi David,
There is no need to configure PCR register MUX because DAC is default function on this pin. I have attached a pic from data sheet below.
Also Port clock is enabled in the componenet section. Screenshot attached below.
Hello Vishal,
I recommend you refer to the "Typical Usage" of DAC component , there are some demo how to configure the DAC and sample project .
Hope it can help you !
Alice
Hi Alice,
Can you please point me to those? That will be of great help.
Hi Vishal ,
here :
Hi Alice,
I used the exact same code as given in typical application 1st case. I still do not get the DAC output. :smileysad:
I have quick follow up question.
Since DAC is 12 bit resolution, why is the example code setting 32 bit value?
#########################################################################################
Required component setup:
•Interrupt service/event: Disabled
•D/A resolution: 12 bits
•Data mode: unsigned 32 bits, left justified
•Data buffer: Disabled
•Enabled in init. code: yes
•Methods to enable: SetValue
#########################################################################################
#define DATA_LENGTH 10 /* Output data array length */
LDD_DAC_TData OutputData[DATA_LENGTH] = { /* Output data array */
0x0, 0x1C71C71C,
0x38E38E38, 0x55555554,
0x71C71C70, 0x8E38E38C,
0xAAAAAAA8, 0xC71C71C4,
0xE38E38E0, 0xFFFFFFFC
};
LDD_TError Error;
LDD_TDeviceData *MyDacPtr;
void main(void)
{
...
MyDacPtr = DA1_Init(NULL); /* Initialization of DA1 component */
for (;;) {
for (i = 0; i < DATA_LENGTH; i++) {
Error = DA1_SetValue(MyDacPtr, OutputData[i]); /* Set converter output */
}
}
}
Hi Vishal,
Please set the voltage reference in the DAC component to "external" from "internal".
I also added in a delay loop (polling) so it doesn't change too fast as I used a Voltmeter to watch the DAC output.
Regards,
David
Hi David,
Thanks a lot. That works. I really am very thankful to you.
Also a quick follow up question. Since DAC is 12 bit resolution, why is the example code setting 32 bit value?
Hi Vishal,
You are welcome. Glad you are up and running.
I think it is just code re-use and wasn't optimized for this particular DAC.
Regards,
David