FTM CnV Update Problem 2

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

FTM CnV Update Problem 2

1,110 Views
Jana_muralidharan
Contributor II

 

Hi, I got another problem, i previously ask and got solve it is the LDOK register that i was wrong

but even after solving that it still not doing what i ask that is to update the CnV and change the Pulse width please help me this is that code i have been working on

 

#include "MKE02Z4.h"

#define FTM_MOD     24      // 25 ticks → 1.25us @ 20MHz
#define TICKS_0      7
#define TICKS_1     14

void FTM_Init(void)
{
    SIM->SCGC |= SIM_SCGC_FTM2_MASK;

    FTM2->MODE = FTM_MODE_WPDIS_MASK | FTM_MODE_FTMEN_MASK;

    FTM2->CNTIN = 0;
    FTM2->CNT   = 0;
    FTM2->MOD   = FTM_MOD;

    FTM2->CONTROLS[0].CnSC =
        FTM_CnSC_MSB_MASK |
        FTM_CnSC_ELSB_MASK;

    FTM2->CONTROLS[0].CnV = TICKS_0;

    /* ENABLE CHANNEL OUTPUT (CRITICAL) */
    FTM2->OUTMASK &= ~(1 << 0);

    /* Initial load */
    *(volatile __UINT32_TYPE__ *)0x4003A098 = 0x0201;

    FTM2->SC = FTM_SC_CLKS(1) | FTM_SC_PS(0);

    *(volatile __UINT32_TYPE__ *)0x4003A064 = 0x00;
}

static inline void wait_ftm_period(void)
{
    while(!(FTM2->SC & FTM_SC_TOF_MASK));
    FTM2->SC &= ~FTM_SC_TOF_MASK;
}

uint32_t word = 0x5555;

int main(void)
{
    FTM_Init();

    while (1)
    {
        for(int i = 0; i < 16; i++)
        {
            if (word & (1UL << i))
                *(volatile __UINT32_TYPE__ *)0x4003A010 = TICKS_1;
            else
            	*(volatile __UINT32_TYPE__ *)0x4003A010 = TICKS_0;

            /* ARM reload for next PWM cycle */
            *(volatile __UINT32_TYPE__ *)0x4003A098 = 0x0201;

            /* WAIT ONE PWM PERIOD */
            wait_ftm_period();
        }
    }
}
0 Kudos
Reply
6 Replies

1,014 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @Jana_muralidharan 

Please use the FTM_UpdatePwmDutycycle() API to update the PWM duty cycle.
For more details, refer to the ftm_simple_pwm demo, where the PWM duty cycle is periodically updated.
 

/*!

* brief Updates the duty cycle of an active PWM signal.

*

* param base FTM peripheral base address

* param chnlNumber The channel/channel pair number. In combined mode, this represents

* the channel pair number

* param currentPwmMode The current PWM mode set during PWM setup

* param dutyCyclePercent New PWM pulse width; The value should be between 0 to 100

* 0=inactive signal(0% duty cycle)...

* 100=active signal (100% duty cycle)

* return kStatus_Success if the PWM update was successful

* kStatus_Error on failure

*/

status_t FTM_UpdatePwmDutycycle(FTM_Type *base,

ftm_chnl_t chnlNumber,

ftm_pwm_mode_t currentPwmMode,

uint8_t dutyCyclePercent)

 

BR
Alice

 

 

0 Kudos
Reply

935 Views
Jana_muralidharan
Contributor II
But can you please tell me, in how much cycle that the PWM updates
0 Kudos
Reply

926 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @Jana_muralidharan 

This depends on your application. You can refer to your requirement design.
Regarding this SDK demo, it uses a timer overflow interrupt to update the PWM duty cycle.
Alice_Yang_0-1766732600601.png

 

BR

Alice

 

0 Kudos
Reply

1,107 Views
Jana_muralidharan
Contributor II

Hey I am the writer of the post And i am working in the WS2812B so i though of using PWM to generate the signal so that why thing thing of changing the Duty cycle so and i want to know Is it possible to do that with this 

 

0 Kudos
Reply

1,064 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi @Jana_muralidharan ]

I'm sorry, I'm a bit confused. Are you asking how to change the duty cycle of the PWM, or are you asking why your duty cycle changed?
 
Thank you.
 
BR
Alice
0 Kudos
Reply

1,020 Views
Jana_muralidharan
Contributor II
Hello @Alice_Yang,
Yeah i am trying to change the PWM duty cycle for every cycle like for 1st period 30% duty cycle then in the 2nd period 70% duty cycle like that

Is there any procedure to change the PWM duty change

It just stuck at the initially set value that the issue here
0 Kudos
Reply