Duty Cycle Selection in PWM channels

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

Duty Cycle Selection in PWM channels

Jump to solution
1,436 Views
marceli1
Contributor III

Hi,

I need use one timer with four channels operating on the same frequency, however each channels I need set duty cycle independently out of other channels. Is it possible or I need find micro with four timers?

Labels (1)
Tags (2)
0 Kudos
Reply
1 Solution
1,089 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Marceli,

When you create several PWM_LDD with same timer TU1, PWMx_SetDutyMS will only update the duty of selected channelx.

PWMx_SetDutyMS.png

Best Regards,

Robin

 

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

View solution in original post

0 Kudos
Reply
7 Replies
1,089 Views
mjbcswitzerland
Specialist V

Hi

Each timer has a single frequency but each of its channels can generate a different duty cycle at this frequency.
See http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF (chapter 5 and appendix - page 20) for more details.

Regards

Mark

0 Kudos
Reply
1,089 Views
marceli1
Contributor III

Hi Mark,

I am using MKL25Z timer and PE approach. I am able create PWM2 for next channel with the same timer TU1.

 I am not sure when changing duty cycle using:

LDD_TError PWM2_SetDutyMS(LDD_TDeviceData *DeviceDataPtr, uint16_t Time){..}

calling at OnEnd event I will change for only PWM2 set channel.

0 Kudos
Reply
1,090 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Marceli,

When you create several PWM_LDD with same timer TU1, PWMx_SetDutyMS will only update the duty of selected channelx.

PWMx_SetDutyMS.png

Best Regards,

Robin

 

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

0 Kudos
Reply
1,089 Views
marceli1
Contributor III

Hi Robin,

thank you. To avoid output noise I need change duty cycle in the event OnEnd period and this will be separate for each channel done. Problem can be I will get six channels interrupts at the same time on the end of the same period. Will I lost some of interrupts or I need to setup priorities for them and how? 

Kind Regards,

Marceli

0 Kudos
Reply
1,089 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

These six channels share the same overflow interrupt.

Interrupt vector assignments.png

TPMx_STATUS[TOF].png

OnEND.png

Best Regards,

Robin

 

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

1,089 Views
marceli1
Contributor III

Hi Robin,

PE is not allowing me to change initially period timer TU1 while is linked with PWM six channels. It is even Counter restart is in "On-match" mode. Can I make own method to change period for all channels in timer TU1?  

#include "TPM_PDD.h"

LDD_TError TU1_SetPeriodTicks(LDD_TDeviceData *DeviceDataPtr, uint16_t Ticks)
{
  (void)DeviceDataPtr;                 /* Parameter is not used, suppress unused argument warning */
  /* Parameter test - this test can be disabled by setting the "Ignore range checking"
     property to the "yes" value in the "Configuration inspector" */
  if ((Ticks > 65535U) || (Ticks == 1U)) { /* Is the given value out of range? */
    return ERR_PARAM_TICKS;            /* If yes then error */
  }
  TPM_PDD_WriteModuloReg(TPM0_BASE_PTR, (uint16_t)(--Ticks));
  return ERR_OK;                       /* OK */
}

Regards,

Marceli

0 Kudos
Reply
1,089 Views
marceli1
Contributor III

Hi Robin,

Thank you, this explains process order very well. Only need to pass channel's duty cycle value at OnEnd channel event.

Regards,

Marceli

0 Kudos
Reply