Using PDB to issue single-shot DAC update

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

Using PDB to issue single-shot DAC update

1,252 Views
aberger
Contributor V

I would like to use the PDB to trigger DAC updates, but don't think I properly understand the operation of the PDB.

Details of my application:

I am trying to implement a Direct Digital Synthesis (DDS) algorithm using the Programmable Interrupt Timer (PIT). Therefore, each time the PIT issues an interrupt, I increment the phase of an accumulator, which I use with a sinusoidal LUT to set the the next element of the DAC buffer. I would then like to trigger the DAC to update (via PDB) with the recently stored value in the buffer. I therefore issue a software trigger to the PDB, and expect that some delay later (determined by the PDB DAC Interval Value), the DAC outputs the new value. 

   

g_DACBuffIdx = 1;
while (1) {
if(PIT_ISR_Flag) {    // 1. increment the phase       g_phase += g_FTW; // a 32-bit phase accumulator, where the Frequency Tuning Word (FTW)                          // is determined at the top of the program by the user-input sine freq    // 2. calculate sine LUT index based on MSB of g_phase       g_sineIdx = (uint16_t)((g_phase & 0xFFF00000)>>20U); // get the 12 MSB from g_phase                                                             // to use with a 4096-element sine LUT    // 3. Set the DAC to the new value       DAC_SetBufferValue(DAC_BASEADDR, g_DACBuffIdx, sinLUT[g_sineIdx]);    // 4. increment the DAC buffer index       g_DACBuffIdx++;       g_DACBuffIdx %= 16; // reset each time I reach the end of the DAC buffer    // 5. Trigger the PDB       PDB_DoSoftwareTrigger(PDB_BASEADDR);    // 6. reset the PIT interrupt flag       PIT_ISR_Flag = false; } }

If I simply set up the DAC to trigger by software instead of by hardware (i.e. the PDB), and replace the PDB trigger with DAC_DoSoftwareTrigger(DAC_BASEADDR); the above code works fine. What am I not understanding about the operation of the PDB.

I have the PDB set to one-shot mode (continuous mode disabled). Nevertheless, it appears that the DAC updates more than once per while loop iteration. Why would this be? Is there a diagram to of PDB events to understand how it triggers DAC updates?

Note: I am using a K64F on the TWR-K64F120M dev board.

Tags (3)
0 Kudos
5 Replies

781 Views
johntse
Contributor II

dear Robin,

i also tried to use the PDB bypass feature to do instant on demand one shot trigger but it also did not work

0 Kudos

781 Views
johntse
Contributor II

dear robin

i am trying to use the software trigger function of the PDB to do on demand one shot conversion of the channel B adc0 and adc1

so an exact example would be very helpful.

0 Kudos

1,022 Views
mjbcswitzerland
Specialist V


Hi Andy

Do you really need the PDB trigger delay since you can directly use the PIT to load the DAC based on interrupt transfer? This allows the content of the lookup table to be copied to the the DAC without any CPU intervention. The waveform output is defined by the LUT contents and its periodic frequency by the PIT rate. This also allows it to continue running when the processor is held in a break-point.

See chapter 4 of http://www.utasker.com/docs/uTasker/uTaskerADC.pdf
I have attached a binary for the FRDM-K64F that generates a free-running sine wave (10kHz samples and about 88Hz full-scale output) on DAC0 output (J4-11) as reference.
The code is available also in the uTasker open source project and enabled with the defines and will work on any Kinetis part with DMA and DAC:
TEST_DMA_DAC and GENERATE_SINE in the file ADC_Timers.h

The document also explains PIT triggering restrictions.

By setting the PIT in single-shot, rather than free-running mode, it can also be used to perform a single sample update after a defined delay.


Regards

Mark

Kinetis: http://www.utasker.com/kinetis.html
Kinetis K64:
- http://www.utasker.com/kinetis/FRDM-K64F.html
- http://www.utasker.com/kinetis/TWR-K64F120M.html
- http://www.utasker.com/kinetis/TEENSY_3.5.html
- http://www.utasker.com/kinetis/Hexiwear-K64F.html
ADC/DAC: http://www.utasker.com/docs/uTasker/uTaskerADC.pdf


Free Open Source solution: https://github.com/uTasker/uTasker-Kinetis
Working project in 15 minutes video: https://youtu.be/K8ScSgpgQ6M

Professional Kinetis support, one-on-one training and complete fast-track project solutions: http://www.utasker.com/support.html

0 Kudos

1,022 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Andy,

Please check if the dac continuous_pdb_edma example in SDK_2.3.0_TWR-K64F120M meet your needs.
That example can be found in SDK_2.3.0_TWR-K64F120M folder(For example: C:\SDK_2.3.0_TWR-K64F120M\boards\twrk64f120m\driver_examples\dac\continuous_pdb_edma)
You can download SDK_2.3.0_TWR-K64F120M package refer Generating a downloadable MCUXpresso SDK v.2 package.

dac continuous_pdb_edma.jpg

Best Regards,

Robin

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

783 Views
johntse
Contributor II

Dear Robin

i dont understand the PDB enough to write code to trigger ADCx channel B to do ADC conversions

i look at all the examples but cannot understand how to setup the PDB to do the triggering

for example: how do i set up the PDB to do on-demand one-shot ADC conversion of channel B

the following inputs 

ADC1_SE7b

ADC1_SE5b

ADC1_SE4b

ADC0_SE4b

i am using K64 144pin cpu, Channel A ADC0 and ADC1 has no problem and they can use software trigger directly

but All channel Bs can only use Hardware triggering via PDB but i am unable to understand enough to make it work.

in the manual, there seems to be no direct reference to how the PDB triggers the ADCs and trying some examples on the internet does not work, the COCO is not set at all no matter what i config

to keep it simple, no interrupt or DMA, just a single one shot and i cannot do it.

 

0 Kudos