Need help with MK12Dn512 DAC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help with MK12Dn512 DAC

Jump to solution
635 Views
DeepakKukreja
Contributor III

Hi,

I am using the MK12DN512VLK5 device in my design. I am using the MCUXpresso IDE along with the MCUXpresso SDK.

My application requires configurable analog output voltage for which I am using the 12-bit DAC0 module on this microcontroller. I have followed all the steps mentioned in the DAC example that were provided for the Towerboard TWRK21d50m that uses the MK21DN512 part. I am aware that this is a different part but I have just referred to the example code to get an idea of how to use the MCUXpress SDK API for DAC peripheral.

The issue is that the Pin22, DAC0 out is fixed at 1.5V, the Vref is the Vreference source 2, which is the VDDA pin 17. I checked the voltage level available at this pin, it is 3.3V.

I am not using the 16 word buffer, just want a single value to be converted to an analog voltage level.

The DAC peripheral initialization code is as below:

 

void dac_init( uint16_t voltageLevel )
{
    uint32_t        index;
    dac_config_t    dacConfigStruct;


    dac_buffer_config_t dacBufferConfig;


    /**
     * Initialize the DAC with the following settings
     *  DAC enabled
     *  Dac reference 2 selected to select Vdda as the voltage reference
     *  Software triggering selected
     *  High power mode
     *  None of the buffer interrupts enabled
     *
     *  DMA disabled
     *  DAC buffer disabled
     */
    DAC_GetDefaultConfig(&dacConfigStruct);
    dacConfigStruct.enableLowPowerMode      = false;     // High power mode
    // Select Vdda as the voltage reference source
    dacConfigStruct.referenceVoltageSource  = kDAC_ReferenceVoltageSourceVref2;
    DAC_Init(DAC0, &dacConfigStruct);

    DAC_GetDefaultBufferConfig(&dacBufferConfig);
    dacBufferConfig.triggerMode = kDAC_BufferTriggerBySoftwareMode;
    DAC_SetBufferConfig(DAC0, &dacBufferConfig);

    /**
     *  Disable the DAC buffer, we want the DAC to convert only the value in the data register 0.
     *  This function call shall set DAC0_C1.DACBFEN to 0
     */
    DAC_EnableBuffer(DAC0, false);

    /// Set the first channel value to the DAC
    DAC_SetBufferValue(DAC0, 0, voltageLevel);

}

 

What could be going wrong?

I also have a few questions:

Is pin mux setting required for the pin 22?
I a in doubt because, Pin 22 is not mapped to any port pin. Also the reference manual mentions that it supports only one ALT mode which is also the default mode, i.e. DAC0/CMP/ADC_SE. So according to this description I understand that pin muxing cannot be done as there is no Pin Control register specific to Pin 22, Yet the chip configuration section mentions that the DAC signals need signal multiplexing to be set(in the second image)

Pin Mux.pngChip Config.png

 

Another query is that Pin 22 is labelled for DAC, Comparator as well as ADC, so what configuration is needed to tell the chip that pin 22 is to be connected to the DAC output? I am also using the ADC module in my application, could there be a chance of conflict happening there?

0 Kudos
1 Solution
628 Views
DeepakKukreja
Contributor III

The issue is solved, putting the solution just in case someone else needs a solution. I had left out calling the DAC_Enable(DAC0, true); at the end of the initialization. I was assuming that the DAC_Init() function calls this internally, but saw that is commented and left for the user to call the enable function.

View solution in original post

1 Reply
629 Views
DeepakKukreja
Contributor III

The issue is solved, putting the solution just in case someone else needs a solution. I had left out calling the DAC_Enable(DAC0, true); at the end of the initialization. I was assuming that the DAC_Init() function calls this internally, but saw that is commented and left for the user to call the enable function.