PIT, PDB to trigger DAC

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

PIT, PDB to trigger DAC

Jump to solution
1,614 Views
MikeAdv
Contributor III

I trying to generate a sine wave on the DAC output.  

 

I have the sine wave table stored in the DAC buffer.

 

Everything works, except the DAC updates much faster than I want despite what values I use for PDB0_DACINT0 or PIT_LDVAL0.  It seems to be updating at about 25 MHz.

 

Any suggestions?

 

uint16_t buf[16] ={2047, 2429, 2754, 2970, 3047, 2970, 2754, 2429, 2047, 1664, 1339,1123, 1047, 1123, 1339, 1664}; // Sine wave buffer int i; uint8_t *p; // enable clock to DAC (pg. 289) SIM_SCGC2 |= SIM_SCGC2_DAC0_MASK ;   // enable DAC, use DACREF_2 (wasn't getting output using DACREF_1) DAC0_C0 |= DAC_C0_DACEN_MASK | DAC_C0_DACRFS_MASK; DAC0_C1 |= DAC_C1_DACBFEN_MASK;  p = (uint8_t*)0x400cc000; for(i=0; i < 16; i++) {  *p = (buf[i] & 0xff);  p++;  *p = (buf[i] & 0xf00) >> 8;  p++; }  // Now we need to setup trigger. SIM_SCGC6 |= SIM_SCGC6_PDB_MASK | SIM_SCGC6_PIT_MASK;  // enable clock to PDB and PIT.  // PIT module doc pg 1071  PIT_LDVAL0 = 10000; // don't seem to do what I expect PIT_TCTRL0 |= PIT_TCTRL_TEN_MASK;  // Enable PIT timer PIT_MCR &= ~PIT_MCR_MDIS_MASK; // enable PIT Timer (pg. 1074)  // Now tell PDB to look for PIT0 // PDB Doc on pg. 913  // Select PIT as trigger // PDB0_SC register doc on pg. 920. // Triggers defined on pg. 131   0b0100 is PIT CH 0 PDB0_SC |= PDB_SC_TRGSEL(4) | PDB_SC_PDBEN_MASK;  PDB0_DACINT0 = 0xff; // changing this doesn't change update rate as I would expect PDB0_DACINTC0 |= 1;  // DAC Interval Trigger enable

 

1 Solution
720 Views
MikeAdv
Contributor III

Figured it out.

 

1) I don't really need the PIT.  I can start the PDB using a software trigger.  Once started the DAC interval counter will generate output continually.

2) The problem with my code was that I wasn't "loading" the value I set in PDB0_DACINT0.  After writting to PDB0_DACINT0, it is necessary to set the LDOK bit, then things work as expected!

View solution in original post

3 Replies
721 Views
MikeAdv
Contributor III

Figured it out.

 

1) I don't really need the PIT.  I can start the PDB using a software trigger.  Once started the DAC interval counter will generate output continually.

2) The problem with my code was that I wasn't "loading" the value I set in PDB0_DACINT0.  After writting to PDB0_DACINT0, it is necessary to set the LDOK bit, then things work as expected!

720 Views
julioruzicki
Contributor II

Hi Guys, I trying use the DAC with HW trigger but I couldn't make it works. I'm using kinetis studio v. 3.

Could you give some ideia?

I sending a link to project: gerador.zip - Google Drive

Thanks

0 Kudos
720 Views
mjbcswitzerland
Specialist V

Hi

See chapter 4 of http://www.utasker.com/docs/uTasker/uTaskerADC.pdf for HW triggered DAC (or PWM as alternative DAC) and DMA.

Full solution in uTasker Kinetis project for most Kinetis parts and all popular development environments, including synchronisation to USB audio output.

Regards

Mark

Kinetis for professionals: www.utasker.com

0 Kudos