using DMA function to change the duty cycle of PWM wave

cancel
Showing results for 
Search instead for 
Did you mean: 

using DMA function to change the duty cycle of PWM wave

Jump to solution
324 Views
asd046012
Contributor III

Hello  

    We currently have a SWS project that requires the use of a PWM wave with a variable duty cycle and a constant frequency.

The frequency of the PWM wave is 20KHz. The current requirement is that when the button is detected, the duty cycle of the PWM wave will change from 0 to 100% at a rate of 1% within 5ms. The use of interrupts or tasks cannot meet customer requirements. Therefore, we hope to use the DMA function to automatically transfer the value of the duty cycle to achieve customer requirements.

When using the PWM module provided by the development software S32DS, it is found that the module does not support the DMA function, but we found from the FTM register list (C0SC-C7SC) of the datasheet that the FTM supports the DMA function.

So is our plan feasible? If feasible, is there a similar application case for our reference?

 And I have a question, because after the button is triggered, the duty cycle of the PWM wave must be changed in each cycle, how to ensure that the DMA transfer duty cycle value is triggered in each PWM wave cycle? we should use a timer to trigger the DMA? or use others method?

 

 

0 Kudos
1 Solution
248 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

first check the configured CnV synchronization on FTM module. You can try simple write to CnV value and see if duty is changed at all. If yes, then you can config DMA to do this.

I put some example for PWM duty cycle update using DMA to the community; see https://community.nxp.com/t5/S32K-Knowledge-Base/Example-S32K118-FTM-PWM-DMA-S32DS-2-2/ta-p/1342183

Maybe it could help little bit.

BR, Petr

View solution in original post

0 Kudos
4 Replies
301 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

yes, this can be feasible, however no demo application exists for this, I think; as mentioned in https://community.nxp.com/t5/S32K/How-to-use-FTM-DMA-function/m-p/932590
If DMA is enabled for a channel in CxSC, the channel DMA transfer request is generated if channel flag is set (CHF = 1). In Edge aligned PWM mode the CHF bit is set at the channel (n) match (FTM counter = CnV), that is, at the end of the pulse width. So in each PWM period you can update CnV by DMA. Note at 0% and 100% duty CHF is not set. Also care of CnV register update, see chapter 47.5.12.3 of the RM.
Also you can use channel init or ext trigger as DMA request for first 4 DMA channels, in this case TRGMUX must be set accordingly.  

BR, Petr

0 Kudos
288 Views
asd046012
Contributor III

Hello 

    First I just try to triggle  the DNA once, and try to use DMA  to transfer data to register C6V. make the duty cyclic change from 50% to 25%.the code and config is as below:

     the DMA config as below:

edma.PNG

 

     I enable the DMA function in function FTM_DRV_Init();

enable.PNG

 

  then I initial the dma as below:

           EDMA_DRV_Init(&dmaController1_State, &dmaController1_InitConfig0,
edmaChnStateArray, edmaChnConfigArray, EDMA_CONFIGURED_CHANNELS_COUNT);

     After initialization,I try to triggle the DMA as below:

         triggerSingleBlock(0, ((uint8_t *)(&pwm_dutysignal)),(uint8_t *)(&((FTM1)->CONTROLS[6].CnV)),1);

         

void triggerSingleBlock(uint8_t channel, uint8_t * srcBuff, uint8_t * dstBuff, uint32_t size)
{
     transferComplete = false;

     /* configure eDMA channel for a single block mem-to-mem transfer */
     EDMA_DRV_ConfigSingleBlockTransfer(channel, EDMA_TRANSFER_MEM2PERIPH,                                                                      (uint32_t)srcBuff,(uint32_t)dstBuff, EDMA_TRANSFER_SIZE_32B, size);

     /* trigger a sw DMA request for this channel */
     EDMA_DRV_TriggerSwRequest(channel);

      /* wait for the channel to complete */
      while(!transferComplete)
              __asm("nop");
  }

    the duty cyclic didn't change, so could you give me some advice?

    

 

 

 

 

 

0 Kudos
249 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

first check the configured CnV synchronization on FTM module. You can try simple write to CnV value and see if duty is changed at all. If yes, then you can config DMA to do this.

I put some example for PWM duty cycle update using DMA to the community; see https://community.nxp.com/t5/S32K-Knowledge-Base/Example-S32K118-FTM-PWM-DMA-S32DS-2-2/ta-p/1342183

Maybe it could help little bit.

BR, Petr

View solution in original post

0 Kudos
319 Views
asd046012
Contributor III

Hello  

    our project use the MCU S32K118, Version: 2018.R1, SDK version 2.9.

 

0 Kudos