DAC software trigger not working

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

DAC software trigger not working

Jump to solution
1,713 Views
kerivolans
Contributor II

I am using the KL25Z development board. I'm trying to put data into the next space in the buffer, then am incrementing the buffer pointer to trigger the conversion.

Only DAC0_DAT0H and DAC0_DAT0L have an impact on the output wave. The software trigger is clearly not causing the buffer to increment, and it seems that the buffer is not being enabled.

When hardware trigger is set up instead (and PIT is set up) it works as expected. I would prefer to be able to use software trigger.

#include "MKL25Z4.h"

#include "start.c"

int main(){

  SIM_SCGC5   |= SIM_SCGC5_PORTE_MASK;

  SIM_SCGC6 |= SIM_SCGC6_DAC0_MASK; 

  PORTE_PCR30 &= (uint32_t)~(uint32_t)((PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x07)));

  MCG_C1 |= (1<<2);       

  MCG_C4 |= (1<<7);

  MCG_C4 |= (1<<5);               

  SIM_COPC = 0x00; //Disables the watchdog timer.  

 

  //DAC0_C0 = 1<<5;

  //DAC0_C1 = 1;

  //DAC0_C2 = 1;

  //DAC0_C0 = 1<<7;

    

     DAC0_C0 |= DAC_C0_DACTRGSEL_MASK;

  

    /* Normal buffer mode */

    DAC0_C1 &= ~DAC_C1_DACBFMD_MASK;

  

    /* Enables buffer read ptr */

    DAC0_C1 |= DAC_C1_DACBFEN_MASK;

  

    /* Selects the upper limit of the DAC buffer */

    DAC0_C2 |= DAC_C2_DACBFUP_MASK;

  

    /* Lastly, turn on the DAC */

    DAC0_C0 |= DAC_C0_DACEN_MASK;

          int sequence[38] = {1 ,2 ,2 ,2 ,3 ,4 ,5 ,6 ,7 ,9 ,12 ,15 ,18 ,23 ,28 ,36 ,44 ,56 ,69 ,87 ,108 ,136 ,169 ,212 ,265 ,331 ,414 ,517 ,646 ,808 ,1010 ,1262 ,1578 ,1972 ,2465 ,3081 ,3852 ,4815};

while(1){

  for (int x = 0; x < 38; x +=2){

int temp_low = sequence[x];

int temp_high = temp_low >>8;

    DAC0_DAT1H =   temp_high;   

    DAC0_DAT1L =   temp_low;

    DAC0_C0 |= 8; //increment buffer pointer

   

     temp_low = sequence[x+1];

  temp_high =  temp_low >>8;

    DAC0_DAT0H =   temp_high;   

    DAC0_DAT0L =  temp_low;

    DAC0_C0 |= 8; /increment buffer pointer

}

  return 0;

  }

0 Kudos
Reply
1 Solution
1,363 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Volans,

In software triggering mode, after you write the DAC0_DAT0H/DAC0_DAT0L, you should set the DACSWTRG bit to launch the conversion.

Pls use the follo0wing code:

while(1)

{

    DAC0_DAT0H =   temp_high;   

    DAC0_DAT0L =  temp_low;

DAC0_C0|=0x10; //setting the DACSWTRG bit to launch the DAC conversion immediately

}

Pls have a try.

BR

XiangJun Rong

View solution in original post

0 Kudos
Reply
2 Replies
1,364 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Volans,

In software triggering mode, after you write the DAC0_DAT0H/DAC0_DAT0L, you should set the DACSWTRG bit to launch the conversion.

Pls use the follo0wing code:

while(1)

{

    DAC0_DAT0H =   temp_high;   

    DAC0_DAT0L =  temp_low;

DAC0_C0|=0x10; //setting the DACSWTRG bit to launch the DAC conversion immediately

}

Pls have a try.

BR

XiangJun Rong

0 Kudos
Reply
1,363 Views
kerivolans
Contributor II

That's embarrassing. Thanks a lot!

0 Kudos
Reply