Using TPM2 for high speed timer

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

Using TPM2 for high speed timer

Jump to solution
1,292 Views
barbercolman
Contributor III

I have a CM10.1. MQX 3.7 project that I need to a 1MS timer to. From what I can read this is faster than I should be current a MQX ttimer so I attempted to add TMP2 useing processor expert.

This is what was generated from PE


/** ###################################################################
**     THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : TPM3.c
**     Project   : ProcessorExpert
**     Processor : MCF51JM128VLD
**     Component : Init_TPM
**     Version   : Component 01.080, Driver 01.20, CPU db: 3.00.061
**     Compiler  : CodeWarrior ColdFireV1 C Compiler
**     Date/Time : 2011-06-16, 11:57, # CodeGen: 15
**     Abstract  :
**          This file implements the TPM (TPM2) module initialization
**          according to the Peripheral Initialization Component settings,
**          and defines interrupt service routines prototypes.
**     Settings  :
**          Component name                                 : TPM3
**          Device                                         : TPM2
**          Settings                                       :
**            Clock settings                               :
**              Clock source select                        : Bus rate clock
**              Prescaler                                  : 8
**              Modulo counter                             : 524
**              Period                                     : 1.001 ms
**            Channels                                     : 1
**              Channel                                    :
**                Capture/compare device                   : TPM21
**                Settings                                 :
**                  Mode                                   : Pin not used
**                Pin                                      : Not Used
**                Interrupt                                :
**                  Channel Interrupt                      :
**                    Interrupt                            : Vtpm2ch1
**                    Channel Interrupt                    : Enabled
**                    Priority                             : default
**                    ISR name                             : myisr
**          Pins                                           :
**            External clock source                        : Disabled
**          Interrupts                                     :
**            Overflow Interrupt                           :
**              Interrupt                                  : Vtpm2ovf
**              Overflow Interrupt                         : Disabled
**              Priority                                   : default
**              ISR name                                   :
**          Initialization                                 :
**            Call Init method                             : yes
**            Enable module                                : yes
**     Contents  :
**         Init - void TPM3_Init(void);
**
**     Copyright : 1997 - 2010 Freescale Semiconductor, Inc. All Rights Reserved.
**    
**     http      : www.freescale.com
**     mail      : support@freescale.com
** ###################################################################*/
 
   
void TPM_Modbus_Init(void)
{
   
     (void)getReg8(TPM2C1SC);             /* Channel 0 int. flag clearing (first part) */
      /* TPM2C1SC: CH1F=0,CH1IE=1,MS1B=0,MS1A=0,ELS1B=0,ELS1A=0,??=0,??=0 */
      setReg8(TPM2C1SC, 0x40U);            /* Int. flag clearing (2nd part) and channel 0 contr. register setting */
      /* TPM2SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */
      setReg8(TPM2SC, 0x00U);              /* Stop and reset counter */
      setReg16(TPM2MOD, 0x020CU);          /* Period value setting */
      (void)getReg8(TPM2SC);               /* Overflow int. flag clearing (first part) */
      /* TPM2SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=1,PS2=0,PS1=1,PS0=1 */
      setReg8(TPM2SC, 0x0BU);              /* Int. flag clearing (2nd part) and timer control register setting */

}

 

In my MQX programI installed the locat_tick_isr

 

#define MODBUS_TIMER_INTERRUPT_VECTOR (MCF51JM_INT_Vtpm2ch1)

 

         _int_install_isr(MODBUS_TIMER_INTERRUPT_VECTOR, local_tick_isr,  isr_ptr);

         TPM_Modbus_Init();
But the loca_tick_isr never is ran.

 

Any idea what is wrong.

Thanks

 

0 Kudos
1 Solution
776 Views
marek_vinkler
NXP Employee
NXP Employee

Hi,

 

Your example is good but you need to set additional properties in Processor Expert component:

Channel:  Mode = Output compare

Output action = Software compare only

Channel compare value = <same as Modulo counter> = 0x20C

 

Here is your code modified according to the settings mentioned above. You should catch an interrupt now.

 

void TPM_Modbus_Init(void)
{
      (void)getReg8(TPM2C1SC);             /* Channel 0 int. flag clearing (first part) */
      /* TPM2C1SC: CH1F=0,CH1IE=1,MS1B=0,MS1A=1,ELS1B=0,ELS1A=0,??=0,??=0 */
      setReg8(TPM2C1SC, 0x50U);            /* Int. flag clearing (2nd part) and channel 0 contr. register setting */
      setReg16(TPM2C1V, 0x020CU);          /* Compare 0 value setting */
      /* TPM2SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */
      setReg8(TPM2SC, 0x00U);              /* Stop and reset counter */
      setReg16(TPM2MOD, 0x020CU);          /* Period value setting */
      (void)getReg8(TPM2SC);               /* Overflow int. flag clearing (first part) */
      /* TPM2SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=1,PS2=0,PS1=1,PS0=1 */
      setReg8(TPM2SC, 0x0BU);              /* Int. flag clearing (2nd part) and timer control register setting */
}

void local_tick_isr(void *param)
{
    TPM2C1SC_CH1F = 0U;
}

 

Enjoy! :smileyhappy:

 

View solution in original post

0 Kudos
4 Replies
776 Views
marek_vinkler
NXP Employee
NXP Employee

What BSP are you using? There is MCF51JM128VLD MCU in your example. You have probably used the code generated from Processor Expert and you are trying to make the code working in MQX. Am I right? By the way Processor expert is integrated with MQX in 3.7 version but only for Kinetis. Other platforms coming soon.

775 Views
barbercolman
Contributor III

Bingo

I am using bsp_m51jmevb and psp_51jmebv. I am new to freescale and MQX. So I am not sure if this was the best way to add a 1ms timer. I ended up with the PE code in a seperate file this. This eliminated some of the issues with differnet define.

 

 

If there is a better way, please let me know.

0 Kudos
777 Views
marek_vinkler
NXP Employee
NXP Employee

Hi,

 

Your example is good but you need to set additional properties in Processor Expert component:

Channel:  Mode = Output compare

Output action = Software compare only

Channel compare value = <same as Modulo counter> = 0x20C

 

Here is your code modified according to the settings mentioned above. You should catch an interrupt now.

 

void TPM_Modbus_Init(void)
{
      (void)getReg8(TPM2C1SC);             /* Channel 0 int. flag clearing (first part) */
      /* TPM2C1SC: CH1F=0,CH1IE=1,MS1B=0,MS1A=1,ELS1B=0,ELS1A=0,??=0,??=0 */
      setReg8(TPM2C1SC, 0x50U);            /* Int. flag clearing (2nd part) and channel 0 contr. register setting */
      setReg16(TPM2C1V, 0x020CU);          /* Compare 0 value setting */
      /* TPM2SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */
      setReg8(TPM2SC, 0x00U);              /* Stop and reset counter */
      setReg16(TPM2MOD, 0x020CU);          /* Period value setting */
      (void)getReg8(TPM2SC);               /* Overflow int. flag clearing (first part) */
      /* TPM2SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=1,PS2=0,PS1=1,PS0=1 */
      setReg8(TPM2SC, 0x0BU);              /* Int. flag clearing (2nd part) and timer control register setting */
}

void local_tick_isr(void *param)
{
    TPM2C1SC_CH1F = 0U;
}

 

Enjoy! :smileyhappy:

 

0 Kudos
776 Views
barbercolman
Contributor III

Thank you. This heps

0 Kudos