MCXA CTIMER PWM real time frequency variation question

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

MCXA CTIMER PWM real time frequency variation question

968 Views
Gagan_cepl
Contributor I

Is it possible to vary CTIMER PWM frequency in real time over a wide range, for example from 1 Hz to 4 kHz, while the timer is running?

In our application, when the PWM period is updated continuously during runtime, the following behavior is observed:

For certain period values, the PWM output temporarily stops and no frequency is generated. After further updates, the output resumes normally.

This issue is not seen when the PWM frequency is fixed. It only occurs during live frequency changes.

Is this an expected limitation of CTIMER PWM mode, or is there a recommended method to safely update the PWM frequency in real time across such a wide range without output gaps?

Labels (1)
0 Kudos
Reply
2 Replies

900 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @Gagan_cepl 

There is an SDK example named ctimer_pwm_interrupt_example, where an interrupt callback frequently updates the PWM duty cycle. You can first test this demo on your side. 
 

Alice_Yang_0-1770367263110.pngAlice_Yang_0-1770367263110.png

 

BR

Alice

 

 

0 Kudos
Reply

832 Views
Gagan_cepl
Contributor I

Hello @Alice_Yang,

The example demonstrates how to change the PWM duty cycle, not the frequency. While the PWM varies as expected, my application requires the frequency to be changed rapidly in order to control the stepper motor speed.

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2303428%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EMCXA%20CTIMER%20PWM%20real%20time%20frequency%20variation%20question%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2303428%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EIs%20it%20possible%20to%20vary%20CTIMER%20PWM%20frequency%20in%20real%20time%20over%20a%20wide%20range%2C%20for%20example%20from%201%20Hz%20to%204%20kHz%2C%20while%20the%20timer%20is%20running%3F%3C%2FP%3E%3CP%3EIn%20our%20application%2C%20when%20the%20PWM%20period%20is%20updated%20continuously%20during%20runtime%2C%20the%20following%20behavior%20is%20observed%3A%3C%2FP%3E%3CP%3EFor%20certain%20period%20values%2C%20the%20PWM%20output%20temporarily%20stops%20and%20no%20frequency%20is%20generated.%20After%20further%20updates%2C%20the%20output%20resumes%20normally.%3C%2FP%3E%3CP%3EThis%20issue%20is%20not%20seen%20when%20the%20PWM%20frequency%20is%20fixed.%20It%20only%20occurs%20during%20live%20frequency%20changes.%3C%2FP%3E%3CP%3EIs%20this%20an%20expected%20limitation%20of%20CTIMER%20PWM%20mode%2C%20or%20is%20there%20a%20recommended%20method%20to%20safely%20update%20the%20PWM%20frequency%20in%20real%20time%20across%20such%20a%20wide%20range%20without%20output%20gaps%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2303428%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EClock%7CTimers%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2313510%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20MCXA%20CTIMER%20PWM%20real%20time%20frequency%20variation%20question%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2313510%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F258684%22%20target%3D%22_blank%22%3E%40Gagan_cepl%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3EThere%20is%20an%20SDK%20example%20named%20%3CSTRONG%3Ectimer_pwm_interrupt_example%3C%2FSTRONG%3E%2C%20where%20an%20interrupt%20callback%20frequently%20updates%20the%20PWM%20duty%20cycle.%20You%20can%20first%20test%20this%20demo%20on%20your%20side.%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Alice_Yang_0-1770367263110.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Alice_Yang_0-1770367263110.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Alice_Yang_0-1770367263110.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F375823i9F9D116BF5040A0A%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Alice_Yang_0-1770367263110.png%22%20alt%3D%22Alice_Yang_0-1770367263110.png%22%20%2F%3E%3Cspan%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EAlice_Yang_0-1770367263110.png%3C%2Fspan%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EAlice%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2318460%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20MCXA%20CTIMER%20PWM%20real%20time%20frequency%20variation%20question%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2318460%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F27788%22%20target%3D%22_blank%22%3E%40Alice_Yang%3C%2FA%3E%2C%3C%2FP%3E%3CP%3EThe%20example%20demonstrates%20how%20to%20change%20the%20PWM%20duty%20cycle%2C%20not%20the%20frequency.%20While%20the%20PWM%20varies%20as%20expected%2C%20my%20application%20requires%20the%20frequency%20to%20be%20changed%20rapidly%20in%20order%20to%20control%20the%20stepper%20motor%20speed.%3C%2FP%3E%3C%2FLINGO-BODY%3E