ftm_hal_set.... dont works for me

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

ftm_hal_set.... dont works for me

Jump to solution
1,053 Views
alexeyusoltsev
Contributor IV

HI!

I've got a problem with KSDK and FTM_HAL.

I want to set PWM with KSDK but fails to do it. After that I've added fsl_ftm driver and succeed to run 1 channel. The problem is I can't execute ftm_hal_set commands.

For example(simpliest main) :

 

  /* Write your code here */

  /* For example: for(;;) { } */

  FTM_HAL_SetWriteProtectionCmd(FTM0_BASE_PTR,false);

 

//  FTM0_MODE &=  ~FTM_MODE_FTMEN_MASK;//unable mod update

 

  FTM0_MOD=1000;

  FTM_HAL_SetMod(FTM0_BASE_PTR,1050);

 

  FTM_HAL_SetChnCountVal(FTM0_BASE_PTR,CHAN3_IDX,600);

  uint16_t cnt=FTM_HAL_GetChnCountVal(FTM0_BASE_PTR,CHAN3_IDX);

  while(1)

  {

  }

 

Without  FTM0_MODE &=  ~FTM_MODE_FTMEN_MASK (commented in the code)  FTM_HAL_SetMod(FTM0_BASE_PTR,1050) and FTM0_MOD=1000 do nothing since write to it is protected. But why FTM_HAL_SetWriteProtectionCmd(FTM0_BASE_PTR,false) do nothing?

Also FTM_HAL_SetChnCountVal(FTM0_BASE_PTR,CHAN3_IDX,600) dont changes CHnV: cnt!=600(according to FTM_HAL_GetChnCountVal(FTM0_BASE_PTR,CHAN3_IDX) and the info on my oscilloscope).

 

Are there any examples of usage of bare FTM_HAL without driver? Controller is mkv10z32.

 

Best regards,

Alexey,

Labels (1)
1 Solution
843 Views
alexeyusoltsev
Contributor IV

  Ok, I've played a little bit more with PWMs. And have found a solution.

http://cache.freescale.com/files/32bit/doc/app_note/AN5142.pdf -is a very helpful doc. I wish that APNOTE to be in HAL-language but registers-one. There is a chapter called "Updating the FTM registers" that contains our answer.

In 2 words:

CnV, CNINTV and MOD has a buffer. When you changes it's value while PWM is in working state it don't updates it but write values to corresponding buffer. And can update original values by trigger synchronously. There are software and hardware triggers. In my case I need to update PWM parameters in the program body-so it it software trigger. FTM_HAL_SetSyncMode(FTM0,kFtmUseSoftwareTrig) do that.

After setting up new parameters need to execute register update: FTM_HAL_SetSoftwareTriggerCmd(FTM0,true);

That is it.

     And in the 2 post above XiangJun Rong suggest a nice solution to update PWM parameters in the interrupts.

I hope that thread will be helpful for someone else.

View solution in original post

3 Replies
843 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Alexey,

I see that you would like to change the duty cycle or the cycle time while the FTM is running, in the case, I suggest you update the FTM_CnV register in PWM reload interrupt or in a PIT interrupt instead of in the while(1) {}.

If you want to update the CnV, you have to set SYNCENx bit in the FTMx_COMBINE register and use LOOK bit to load the new value to the CnV register.

for example, you can use the code in an ISR.

FTM_HAL_SetDualChnPwmSyncCmd(FTM0_BASE_PTR, x, TRUE);  //set the SYNCENx bit

vois isr(void)

{

FTM_HAL_SetChnCountVal(FTM0_BASE_PTR,CHAN3_IDX,600)

FTM_HAL_SetPwmLoadCmd(FTM0_BASE_PTR,TRUE);

}

Hope it can help you

BR

XiangJun Rong

843 Views
alexeyusoltsev
Contributor IV

Hi XiangJun Rong,

Many thanks for fast answer. It was very helpfull for me. I've read reference manual and pointed out that after i write a value in the buffer register i need to make a SYNC command to update the registers: MOD,CnV and CNINV.

In my project I need to update PWM frequency after getting comand trhough UART - so i need to update it not in an interrupt.

After that i picked up the code from here: Need help setting up PWM on FTM2_CH0 for output to PortB, bit 18.  to start my pwm. And it worked.

After that i add some strings of code:

FTM_HAL_SetPwmLoadChnSelCmd(FTM0,CHAN3_IDX,true);

FTM_HAL_SetPwmSyncMode(FTM0_BASE_PTR,true);

FTM_HAL_SetChnCountVal(FTM0_BASE_PTR,CHAN3_IDX,300);
FTM_HAL_SetMod(FTM0, 400);

FTM_HAL_SetCounterInitVal(FTM0, 0);

And that did nothing since no sync cmd. But after adds a FTM_HAL_SetPwmLoadCmd(FTM0_BASE_PTR,true) line PWM stacked at high position and dont reacts.

The full startup code(be4 while(1) that is added just to not faul in the default interrupt) is in attach. There is no PIN start up since I tuned it in PIN_MUX component pte 29 and 30 are CH2 and CH3 of FTM0.

I bet i can stop PWM and update registers but it is not the case of the project.

Thnx again for your help!

0 Kudos
Reply
844 Views
alexeyusoltsev
Contributor IV

  Ok, I've played a little bit more with PWMs. And have found a solution.

http://cache.freescale.com/files/32bit/doc/app_note/AN5142.pdf -is a very helpful doc. I wish that APNOTE to be in HAL-language but registers-one. There is a chapter called "Updating the FTM registers" that contains our answer.

In 2 words:

CnV, CNINTV and MOD has a buffer. When you changes it's value while PWM is in working state it don't updates it but write values to corresponding buffer. And can update original values by trigger synchronously. There are software and hardware triggers. In my case I need to update PWM parameters in the program body-so it it software trigger. FTM_HAL_SetSyncMode(FTM0,kFtmUseSoftwareTrig) do that.

After setting up new parameters need to execute register update: FTM_HAL_SetSoftwareTriggerCmd(FTM0,true);

That is it.

     And in the 2 post above XiangJun Rong suggest a nice solution to update PWM parameters in the interrupts.

I hope that thread will be helpful for someone else.