KW40Z Connectivity TMR and TPM coexistence issue

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

KW40Z Connectivity TMR and TPM coexistence issue

1,033 Views
lucianfiran
Contributor V

KW40Z_Connectivity_Software_1.0.1 (KSDK_1.3.0); IAR 7.50

 

If TPM is initialized before TPM timers TimerCallback are not triggered any more.

 

ApplMain.c
void main_task(uint32_t param)
TMR_Init();
TPM_PWM_Init();

 

TimersManager.c

void TMR_Init ( void) {
.....
StackTimer_Init(StackTimer_ISR);
    
TMR_Adapter.c
.....                                           
void StackTimer_Init(void (*cb)(void))        

TPM_Type *tpmBaseAddr = g_tpmBase[gStackTimerInstance_c];

CLOCK_SYS_EnableTpmClock(gStackTimerInstance_c);

TPM_HAL_Reset(tpmBaseAddr, gStackTimerInstance_c);
TPM_HAL_SetClockDiv(tpmBaseAddr, kTpmDividedBy128);

 

TPM files

 

void TPM_PWM_Init(void)
{

...

TPM_DRV_Init(BOARD_TPM_INSTANCE_1, &driverInfo_1);

TPM_DRV_SetClock(BOARD_TPM_INSTANCE_1, kTpmClockSourceModuleClk, kTpmDividedBy2);

...

  TPM_DRV_Init(BOARD_TPM_INSTANCE_0, &driverInfo_0);
  TPM_DRV_SetClock(BOARD_TPM_INSTANCE_0, kTpmClockSourceModuleClk, kTpmDividedBy2);

}

 

How can this be solved ?

Labels (1)
Tags (2)
9 Replies

714 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Lucian,

I have checked the reference manual of KW40Z, it has TMP0, TMP1 and TMP2, they are independent modules. Regarding your application, do you use one TPM module as timer to generate interrupt and use another TPM module to generate PWM signals?

Can you post your code and describe your issue in detail so that we can have a review?

I am sorry for the delay.

BR

Xiangjun Rong

0 Kudos

714 Views
lucianfiran
Contributor V

Hello,

TPM is used for PWM control on 5 channels:

  PORT_HAL_SetMuxMode(PORTA, 0u,kPortMuxAlt5); /* TPM1_CH0   */
  PORT_HAL_SetMuxMode(PORTB, 3u, kPortMuxAlt5); /* TPM1_CH1  */
  PORT_HAL_SetMuxMode(PORTB,18u, kPortMuxAlt5); /* TPM0_CH0 */
  PORT_HAL_SetMuxMode(PORTC, 0u, kPortMuxAlt5); /* TPM0_CH1 */
  PORT_HAL_SetMuxMode(PORTC, 1u, kPortMuxAlt5); /* TPM0_CH2 */

My code for control PWM:

https://github.com/firanl/lamp_ot/blob/master/lamp/bluetooth/addons/tpm_pwm_led/tpm_pwm_led_ctrl.c

https://github.com/firanl/lamp_ot/blob/master/lamp/bluetooth/addons/tpm_pwm_led/tpm_pwm_led_ctrl.h

and application

https://github.com/firanl/lamp_ot/blob/master/lamp/bluetooth/otap_client_att/common/app.c

void BleApp_Init(void)
{
     tmrErrCode_t tmrerr = gTmrInvalidId_c;
    /* Initialize application support for drivers */
     
    #if gLED_TPM_PWM_d
      LED_UnInit();
      
      /* init PEM TPM driver */
      TPM_PWM_Init();   
    #endif
      
    appTimerId = TMR_AllocateTimer();
    /* Initialize application specific peripher drivers here. */
    mMeasurementTimerId = TMR_AllocateTimer();
    /* Start 1 second measurements */
    tmrerr = TMR_StartTimer(mMeasurementTimerId, gTmrIntervalTimer_c,TmrSeconds(3), MeasurementTimerCallback, NULL);
}

If TPM PWM enabled the timer MeasurementTimerCallback does not trigger the callback.

Thank you,

Lucian.

0 Kudos

714 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Lucian,

The KW40Z has 3 TPM modules TMP0/TPM1/TPM2, the TPM0 has 4 channels, TPM1 has 2  channels, TPM2 has 2 channels. If you need 5 PWM signals, you can use both TPM0/TPM1 to generate the 5 PWM signals, use TPM2 as timer. Now, you use 3 TPM modules to generate 5 PWM signals, it has issue, assume that you use  TPM2 as both PWM generator and Timer, there is only one counter for TPM2, the TPM2 counter counts tick from 0 to TPM2_MOD register, TPM2_MOD register controls the PWM cycle time, if the required interval of Timer is greater than the TPM2_MOD register, of course, the callback of Timer never happens.

Hope it can help you

BR

xiangjun Rong

714 Views
lucianfiran
Contributor V

Added in  app_preinclude.h :

/* timers */
  /* TMR_Adapter.h */
    /* TPM instance 0,1,2 used to drive timer clock */
    #define gStackTimerInstance_c           2  

And now the callback is triggered, strange that the name is non intuitive should be gStackTimerTPMInstance_c 

Should I modify gStackTimerChannel_c also, I presume this is the TPMCahnnel used ?

TMR_Adapter.h

#ifndef gStackTimerInstance_c
   #define gStackTimerInstance_c  0
#endif

#ifndef gStackTimerChannel_c
   #define gStackTimerChannel_c   0
#endif

#ifndef gLptmrInstance_c
   #define gLptmrInstance_c       0
#endif

#ifndef gTmrRtcInstance_c
   #define gTmrRtcInstance_c      0
#endif

#ifndef gTmrPitInstance_c
   #define gTmrPitInstance_c      0
#endif

#define gStackTimer_IsrPrio_c (0x80)

0 Kudos

714 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Lucian,

I have checked the reference manual of KW30z, it seems that the KW30Z also has 3 TPMs,TMP0/TPM1/TPM2, the TPM0 has 4 channels, TPM1 has 2  channels, TPM2 has 2 channels. As I said above that you can use both TPM0/TPM1 to generate the 5 PWM signals, use TPM2 as timer.

Regarding the blue tooth code, I am not familiar. can you tell me where the file TMR_Adapter.h and app_preinclude.h locate?

BR

Xiangjun Rong

0 Kudos

714 Views
lucianfiran
Contributor V

Hi Rong,

\framework\TimersManager\Source\TMR_Adapter.h

\examples\bluetooth\otap_client_att\frdmkw40z\bare_metal\app_preinclude.h

in code

https://github.com/firanl/lamp_ot/blob/master/lamp/bluetooth/otap_client_att/app_preinclude.h

https://github.com/firanl/lamp_ot/blob/master/framework/TimersManager/Source/TMR_Adapter.h

Best Regards,

Lucian.

0 Kudos

714 Views
lucianfiran
Contributor V

Is strange:

 How do I use 3 TPM ?

  PORT_HAL_SetMuxMode(PORTA, 0u,kPortMuxAlt5); /* TPM1_CH0   */
  PORT_HAL_SetMuxMode(PORTB, 3u, kPortMuxAlt5); /* TPM1_CH1  */


  PORT_HAL_SetMuxMode(PORTB,18u, kPortMuxAlt5); /* TPM0_CH0 */
  PORT_HAL_SetMuxMode(PORTC, 0u, kPortMuxAlt5); /* TPM0_CH1 */
  PORT_HAL_SetMuxMode(PORTC, 1u, kPortMuxAlt5); /* TPM0_CH2 */

I use TPM1 CH0 CH1  and TPM0 CH0, CH1 and CH2  ?

0 Kudos

714 Views
lucianfiran
Contributor V

I'm using MKW30Z.

So this implies a hardware change ? or only software change ?

0 Kudos

714 Views
lucianfiran
Contributor V

TimersManager cannot use PIT or other available timers ?

0 Kudos