DAC BUFFER KL25Z

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

DAC BUFFER KL25Z

Jump to solution
2,387 Views
jorgevazquez
Contributor II

Hello my name is jorge and i cant see where is the buffer dac, i had been reading the MKL25Z128VLK4 datasheet but i cant find how to define the buffer.


some one had use the dac buffer?


thankyou for your help

Labels (1)
1 Solution
1,150 Views
stefandz
Contributor II

I've only ever achieved this using software double-buffers and a timer interrupt to copy values out to the DAC (and swap / refill as appropriate). I would be interested in knowing how to achieve this too! It also seems like this can be DMA controlled if you set it up correctly with interrupts called at buffer end.

Jorge, are you doing this using CodeWarrior and ProcessorExpert? If so, some time spent looking carefully through the options on the DAC module might be well spent - I only gave up because I could do the same thing I needed with my own buffers.

S

View solution in original post

0 Kudos
6 Replies
1,150 Views
angusgalloway-b
NXP Employee
NXP Employee

Jorge,

In response to your original question about using the DAC buffer, here is some code I was able to use to implement a 2 element circular buffer using the PIT as hardware trigger source. Everything is taken care of in the initialization. An application of this would be to generate a square wave with an amplitude less than VDD without having to use the core.

As is, the code will generate a square wave on PTE30 of the freedom board, with period 200us (assuming 24MHz bus).

void init_DAC()

{  

    /* Enable device clock gate */

    SIM_SCGC6 |= SIM_SCGC6_DAC0_MASK;    

   

    /* DACRFS = 0, DAC selects DACREF_1 VREFH

       DACRFS = 1, DAC selects DACREF_2 VDDA */

    DAC0_C0 |= DAC_C0_DACRFS_MASK;

   

    /* PORTE_PCR30: ISF=0,MUX=0 */

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

   

    /* Enable low-power mode */

    DAC0_C0 |= DAC_C0_LPEN_MASK;

   

    /* 

    DATA[7:0] corresponds to DACx_DATnL

    DATA[11:8] corresponds to DACx_DATnH */

       

    DAC0_DAT0L = 0x00;

    DAC0_DAT0H |= 0x0;

    DAC0_DAT1L = 0xFF;

    DAC0_DAT1H |= 0xF;

     

    /* Hardward trigger sel */

    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;

}

void init_PIT()

    //Enable periodic interrupt timer

    SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;

   

    //MDIS in PIT_MCR needs to be = 0

    PIT_MCR = 0x00;

 

    //LDVAL trigger = (period / clock period) -1 */

    //Set a timer start value (200us)

    PIT_LDVAL0 |= 0x000012BF; 

      

    //Starts timer

    PIT_TCTRL0 |= PIT_TCTRL_TEN_MASK;   

}

0 Kudos
1,151 Views
stefandz
Contributor II

I've only ever achieved this using software double-buffers and a timer interrupt to copy values out to the DAC (and swap / refill as appropriate). I would be interested in knowing how to achieve this too! It also seems like this can be DMA controlled if you set it up correctly with interrupts called at buffer end.

Jorge, are you doing this using CodeWarrior and ProcessorExpert? If so, some time spent looking carefully through the options on the DAC module might be well spent - I only gave up because I could do the same thing I needed with my own buffers.

S

0 Kudos
1,150 Views
jorgevazquez
Contributor II

Hello Stefan, i wanted to do by myself without using processor expert , now i think i will use it, thank you for your answer

Do you how many cycles does the result pass to the out pin after the trigger was done? or how fast can i rechange the data of the dac? Thank you.

0 Kudos
1,150 Views
stefandz
Contributor II

As I promised, a .zip of the project using the timer interrupt to drive the DAC. It's a mess, poorly structured and full of comments which are now redundant. As I said it's based on code from Julio E. Fajardo - the bulk of the credit goes to him. I have no idea how quickly you can get data out - there should be bandwidth specs in the KL25Z reference manual. I am using it for 22.05 kHz audio so it's not a big issue for me - sure you can play around a bit and find the limits yourself :smileyhappy:

Enjoy! And if you end up doing anything interesting with this it would be great to know.

1,150 Views
stefandz
Contributor II

I'm starting to like Processor Expert more and more (and I'm really a fan of straightforward text editors...). There's a chap called Erich Styger who runs MCU on Eclipse | Everything on CodeWarrior, Microcontrollers and Eclipse and is often on these forums too. His site is an excellent resource and has a DAC example DAC Example with the Freedom Board | MCU on Eclipse from Julio E. Fajardo.

I did have an example I evolved from this somewhere which used a Timer Interrupt - will see if I can dig it out for you.

Stefan

1,150 Views
jorgevazquez
Contributor II

Thank you Stefan, i´m checking the forum

0 Kudos