Example S32K144 PDB ADC trigger DMA ISR S32DS

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

Example S32K144 PDB ADC trigger DMA ISR S32DS

Example S32K144 PDB ADC trigger DMA ISR S32DS

********************************************************************************
* Detailed Description:
*
* This example shows how to use the back-to-back mode of the PDB to trigger
* sequence of ADC channels conversion. 4 PDB channel pre-triggers/triggers are
* generated upon single PDB SW trigger. The first trigger is started by the PDB,
* no delay is used. Next 3 triggers start after corresponding acknowledgment is
* received from ADC.
*
* DMA is configured to read the ADC result registers.
* Within DMA major interrupt the new conversion scan is started via PDB SW request.
*
* Converted data is used to change color of the EVB led based on Trimmer position.
*
* ------------------------------------------------------------------------------
* Test HW:         FRDM-S32K144
* MCU:             PS32K144HFVLL 0N77P
* Fsys:            160MHz
* Debugger:        S32DS
* Target:          internal_FLASH
*
********************************************************************************

Labels (1)
Attachments
Comments

Is DMA triggered after each of 4 channels conversion is completed or after all four conversions?

Never mind. I figure it out.

the DMA function does not work corrcetly in my S32 DS enviroment?

Hello  , the sample can not run normal ,after the  DMA0  Clock enabled   it will stop at  :

DefaultISR:
     b DefaultISR

could you give some help for this

I am also same symptom , it was stop at below DMA0 Clock enable line. 

 

PCC->PCCn[PCC_DMA0_INDEX] |= PCC_PCCn_CGC_MASK;          // CGC=1: Clock enabled for DMA0

I had the same problem.

If you use this project then comment the enable clock line of the DMA.

//PCC->PCCn[PCC_DMA0_INDEX] |= PCC_PCCn_CGC_MASK;          // CGC=1: Clock enabled for DMA0

If you make a new project then you will need to enable the clock with a other code line. To enable the DMA clock write:

SIM->PLATCGC |= SIM_PLATCGC_CGCDMA_MASK;                                    //Enable clock DMA

To let the project work do you still need to change the register of the DMAMUX_CHCFG. This needs to be:

DMAMUX->CHCFG[0] |= DMAMUX_CHCFG_SOURCE(42);        // ADC0 COCO is the source of the DMA0 channel

Hello, I am trying to get my ADC results from R[0] assigned to a variable by using DMA. This code is not working for me. 

Can you please tell me where can I find the  list of sources for the DMAMUX_CHCFG? In other words, where did you find the source number is 42?

I found it in the attached file (DMA Interrupt mapping) from the Reference manual.

pastedImage_1.png

Thanks! I want to use this code in a new project. I followed your instructions, but while building the project using this code, I get an error in IRQs_Init() method. Without this, the DMA doesn't work. Basically, I want to read analog signals from 2 different pins and transfer the ADC result to an array/variable via DMA. Is there a fix for this? 

TIA.

In this code is the interrupt line written with FSL_NVIC.

With a new project should it be S32_NVIC.

Then it should work.

Thanks for the help. The code works now, I have 4 ADC channels passing the digital values from ADC result registers to the results array. The values also show up correctly. 

I've run into another issue, I wanted to use the DMA in the first place for a faster rate. But it seems like the graph that I could plot WITHOUT using the DMA was better. 

As you can see from this thread: https://community.nxp.com/thread/497208

Is there some clocking issue or something? Because I didn't change any codes in my ADC or PDB methods, just using DMA to get the results in the results array.

I don't know how the graph looks now. But it could be that you miss a sample because the PDB is restarted after the DMA is done with the data transfer. But i don't know how to fix this, sorry.

The link of the example is broken: Example-S32K144-PDB-ADC_backtoback-DMA-ISR-v1_0-S32DS.zip

%3CLINGO-SUB%20id%3D%22lingo-sub-1103221%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EExample%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103221%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E********************************************************************************%3CBR%20%2F%3E*%20Detailed%20Description%3A%3CBR%20%2F%3E*%3CBR%20%2F%3E*%20This%20example%20shows%20how%20to%20use%20the%20back-to-back%20mode%20of%20the%20PDB%20to%20trigger%3CBR%20%2F%3E*%20sequence%20of%20ADC%20channels%20conversion.%204%20PDB%20channel%20pre-triggers%2Ftriggers%20are%3CBR%20%2F%3E*%20generated%20upon%20single%20PDB%20SW%20trigger.%20The%20first%20trigger%20is%20started%20by%20the%20PDB%2C%3CBR%20%2F%3E*%20no%20delay%20is%20used.%20Next%203%20triggers%20start%20after%20corresponding%20acknowledgment%20is%3CBR%20%2F%3E*%20received%20from%20ADC.%3CBR%20%2F%3E*%3CBR%20%2F%3E*%20DMA%20is%20configured%20to%20read%20the%20ADC%20result%20registers.%3CBR%20%2F%3E*%20Within%20DMA%20major%20interrupt%20the%20new%20conversion%20scan%20is%20started%20via%20PDB%20SW%20request.%3CBR%20%2F%3E*%3CBR%20%2F%3E*%20Converted%20data%20is%20used%20to%20change%20color%20of%20the%20EVB%20led%20based%20on%20Trimmer%20position.%3CBR%20%2F%3E*%3CBR%20%2F%3E*%20------------------------------------------------------------------------------%3CBR%20%2F%3E*%20Test%20HW%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20FRDM-S32K144%3CBR%20%2F%3E*%20MCU%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20PS32K144HFVLL%200N77P%3CBR%20%2F%3E*%20Fsys%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20160MHz%3CBR%20%2F%3E*%20Debugger%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20S32DS%3CBR%20%2F%3E*%20Target%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20internal_FLASH%3CBR%20%2F%3E*%3CBR%20%2F%3E********************************************************************************%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1103221%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EGeneral%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103234%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103234%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThe%20link%20of%20the%20example%20is%20broken%3A%26nbsp%3B%3CSTRONG%20style%3D%22color%3A%20%2351626f%3B%20background-color%3A%20%23ffffff%3B%20border%3A%200px%3B%20font-weight%3A%20bold%3B%22%3E%3CA%20_jive_internal%3D%22true%22%20class%3D%22%22%20data-containerid%3D%2211647%22%20data-containertype%3D%2214%22%20data-content-finding%3D%22Community%22%20data-objectid%3D%22339808%22%20data-objecttype%3D%22102%22%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Fdocs%2FDOC-339808%22%20style%3D%22color%3A%20%233d9ce7%3B%20background-color%3A%20transparent%3B%20border%3A%200px%3B%20font-weight%3A%20inherit%3B%20padding%3A%201px%200px%201px%20calc(12px%20%2B%200.35ex)%3B%22%20target%3D%22_blank%22%3EExample-S32K144-PDB-ADC_backtoback-DMA-ISR-v1_0-S32DS.zip%3C%2FA%3E%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103233%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103233%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20don't%20know%20how%20the%20graph%20looks%20now.%20But%20it%20could%20be%20that%20you%20miss%20a%20sample%20because%20the%20PDB%20is%20restarted%20after%20the%20DMA%20is%20done%20with%20the%20data%20transfer.%20But%20i%20don't%20know%20how%20to%20fix%20this%2C%20sorry.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103232%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103232%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThanks%20for%20the%20help.%20The%20code%20works%20now%2C%20I%20have%204%20ADC%20channels%20passing%20the%20digital%20values%20from%20ADC%20result%20registers%20to%20the%20results%20array.%20The%20values%20also%20show%20up%20correctly.%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20run%20into%20another%20issue%2C%20I%20wanted%20to%20use%20the%20DMA%20in%20the%20first%20place%20for%20a%20faster%20rate.%20But%20it%20seems%20like%20the%20graph%20that%20I%20could%20plot%20WITHOUT%20using%20the%20DMA%20was%20better.%26nbsp%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EAs%20you%20can%20see%20from%20this%20thread%3A%26nbsp%3B%3CA%20_jive_internal%3D%22true%22%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Fthread%2F497208%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.nxp.com%2Fthread%2F497208%3C%2FA%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EIs%20there%20some%20clocking%20issue%20or%20something%3F%20Because%20I%20didn't%20change%20any%20codes%20in%20my%20ADC%20or%20PDB%20methods%2C%20just%20using%20DMA%20to%20get%20the%20results%20in%20the%20results%20array.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103231%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103231%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EIn%20this%20code%20is%20the%20interrupt%20line%20written%20with%20FSL_NVIC.%3C%2FP%3E%3CP%3EWith%20a%20new%20project%20should%20it%20be%20S32_NVIC.%3C%2FP%3E%3CP%3EThen%20it%20should%20work.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103230%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103230%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThanks!%20I%20want%20to%20use%20this%20code%20in%20a%20new%20project.%20I%20followed%20your%20instructions%2C%20but%20while%20building%20the%20project%20using%20this%20code%2C%20I%20get%20an%20error%20in%26nbsp%3BIRQs_Init()%20method.%20Without%20this%2C%20the%20DMA%20doesn't%20work.%20Basically%2C%20I%20want%20to%20read%20analog%20signals%20from%202%20different%20pins%20and%20transfer%20the%20ADC%20result%20to%20an%20array%2Fvariable%20via%20DMA.%20Is%20there%20a%20fix%20for%20this%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3ETIA.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103229%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103229%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20found%20it%20in%20the%20attached%20file%20(DMA%20Interrupt%20mapping)%20from%20the%20Reference%20manual.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_1.png%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22pastedImage_1.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F24080iFD291D236B0BBCF2%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22pastedImage_1.png%22%20alt%3D%22pastedImage_1.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103228%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103228%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%20I%20am%20trying%20to%20get%20my%20ADC%20results%20from%20R%5B0%5D%20assigned%20to%20a%20variable%20by%20using%20DMA.%20This%20code%20is%20not%20working%20for%20me.%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20you%20please%20tell%20me%20where%20can%20I%20find%20the%26nbsp%3B%20list%20of%20sources%20for%20the%26nbsp%3B%3CSPAN%20style%3D%22color%3A%20%2351626f%3B%20background-color%3A%20%23ffffff%3B%22%3EDMAMUX_CHCFG%3F%20In%20other%20words%2C%20where%20did%20you%20find%20the%20source%20number%20is%2042%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103227%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103227%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20had%20the%20same%20problem.%3C%2FP%3E%3CP%3EIf%20you%20use%20this%20project%20then%20comment%20the%20enable%20clock%20line%20of%20the%20DMA.%3C%2FP%3E%3CP%3E%2F%2FPCC-%26gt%3BPCCn%5BPCC_DMA0_INDEX%5D%20%7C%3D%20PCC_PCCn_CGC_MASK%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3CSPAN%3E%20%3C%2FSPAN%3E%2F%2F%20CGC%3D1%3A%20Clock%20enabled%20for%20DMA0%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EIf%20you%20make%20a%20new%20project%20then%20you%20will%20need%20to%20enable%20the%20clock%20with%20a%20other%20code%20line.%20To%20enable%20the%20DMA%20clock%20write%3A%3C%2FP%3E%3CP%3ESIM-%26gt%3BPLATCGC%20%7C%3D%20SIM_PLATCGC_CGCDMA_MASK%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%2F%2FEnable%20clock%20DMA%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3ETo%20let%20the%20project%20work%20do%20you%20still%20need%20to%20change%20the%20register%20of%20the%20DMAMUX_CHCFG.%20This%20needs%20to%20be%3A%3C%2FP%3E%3CP%3EDMAMUX-%26gt%3BCHCFG%5B0%5D%20%7C%3D%20DMAMUX_CHCFG_SOURCE(42)%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2F%20ADC0%20COCO%20is%20the%20source%20of%20the%20DMA0%20channel%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103226%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103226%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20am%20also%20same%20symptom%20%2C%20it%20was%20stop%26nbsp%3Bat%20below%20DMA0%20Clock%20enable%20line.%26nbsp%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EPCC-%26gt%3BPCCn%5BPCC_DMA0_INDEX%5D%20%7C%3D%20PCC_PCCn_CGC_MASK%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3CSPAN%3E%20%3C%2FSPAN%3E%2F%2F%20CGC%3D1%3A%20Clock%20enabled%20for%20DMA0%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103225%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103225%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%20%2C%20the%20sample%20can%20not%20run%20normal%20%2Cafter%20the%20%26nbsp%3B%3CSPAN%3EDMA0%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EClock%20enabled%26nbsp%3B%20%26nbsp%3Bit%20will%20stop%20at%26nbsp%3B%20%3A%3C%2FP%3E%3CP%3EDefaultISR%3A%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bb%20DefaultISR%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3Ecould%20you%20give%20some%20help%20for%20this%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103224%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103224%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3Ethe%20DMA%20function%20does%20not%20work%20corrcetly%20in%20my%20S32%20DS%20enviroment%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103223%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103223%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3ENever%20mind.%20I%20figure%20it%20out.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1103222%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Example%20S32K144%20PDB%20ADC%20trigger%20DMA%20ISR%20S32DS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1103222%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EIs%20DMA%20triggered%20after%20each%20of%204%20channels%20conversion%20is%20completed%20or%20after%20all%20four%20conversions%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
No ratings
Version history
Last update:
‎10-19-2016 04:35 AM
Updated by: