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();
}
}
}