PIT Channel 0 and Channel 1 does not work simultaneously.

cancel
Showing results for 
Search instead for 
Did you mean: 

PIT Channel 0 and Channel 1 does not work simultaneously.

Jump to solution
498 Views
vishaldahiwal
Contributor II

Hi,

I am using I.MXRT1064.

I have configured the PIT channel 0 for 25ms and Channel 1 for 1ms. Both in interrupt mode.

But interrupt triggers only for 25ms but not for 1ms.

Following are the screenshots of configuration.

pastedImage_1.png

pastedImage_3.png

The interrupt routine is written as below,

pastedImage_4.png

Please let me know if anything is missing here.

Regards,

Vishal

Labels (1)
Tags (1)
1 Solution
254 Views
vishaldahiwal
Contributor II

Hi Victor,

The issue is resolved by manually deactivating the chain mode for Channel 1. Thank you very much.

This is required only when I am using channel 1. For Channel 2, this change is not required and everything works with auto-generated code.

Thanks both of you (Mark and Victor) for looking in to this issue and providing valuable inputs.

Regards,

Vishal

View solution in original post

0 Kudos
9 Replies
254 Views
vishaldahiwal
Contributor II

Hi Mark,

Following are the autogenerated code files.

1. peripherals.c

/***********************************************************************************************************************
 * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file
 * will be overwritten if the respective MCUXpresso Config Tools is used to update this file.
 **********************************************************************************************************************/

/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
!!GlobalInfo
product: Peripherals v7.0
processor: MIMXRT1064xxxxA
package_id: MIMXRT1064DVL6A
mcu_data: ksdk2_0
processor_version: 7.0.1
board: MIMXRT1064-EVK
functionalGroups:
- name: BOARD_InitPeripherals
  UUID: baf1d3cb-dc69-4730-83e8-c8fc29113df1
  called_from_default_init: true
  selectedCore: core0
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/

/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
component:
- type: 'system'
- type_id: 'system_54b53072540eeeb8f8e9343e71f28176'
- global_system_definitions: []
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/

/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
component:
- type: 'msg'
- type_id: 'msg_6e2baaf3b97dbeef01c0043275f9a0e7'
- global_messages: []
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */

/***********************************************************************************************************************
 * Included files
 **********************************************************************************************************************/
#include "peripherals.h"

/***********************************************************************************************************************
 * BOARD_InitPeripherals functional group
 **********************************************************************************************************************/
/***********************************************************************************************************************
 * LPSPI1 initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'LPSPI1'
- type: 'lpspi'
- mode: 'polling'
- custom_name_enabled: 'true'
- type_id: 'lpspi_6e21a1e0a09f0a012d683c4f91752db8'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'LPSPI1'
- config_sets:
  - main:
    - mode: 'kLPSPI_Master'
    - clockSource: 'LpspiClock'
    - clockSourceFreq: 'BOARD_BootClockRUN'
    - master:
      - baudRate: '2150000'
      - bitsPerFrame: '8'
      - cpol: 'kLPSPI_ClockPolarityActiveHigh'
      - cpha: 'kLPSPI_ClockPhaseSecondEdge'
      - direction: 'kLPSPI_MsbFirst'
      - pcsToSckDelayInNanoSec: '1066'
      - lastSckToPcsDelayInNanoSec: '1066'
      - betweenTransferDelayInNanoSec: '1066'
      - whichPcs: 'kLPSPI_Pcs0'
      - pcsActiveHighOrLow: 'kLPSPI_PcsActiveLow'
      - pinCfg: 'kLPSPI_SdiInSdoOut'
      - dataOutConfig: 'kLpspiDataOutRetained'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
const lpspi_master_config_t LPSPI1_config = {
  .baudRate = 2150000,
  .bitsPerFrame = 8,
  .cpol = kLPSPI_ClockPolarityActiveHigh,
  .cpha = kLPSPI_ClockPhaseSecondEdge,
  .direction = kLPSPI_MsbFirst,
  .pcsToSckDelayInNanoSec = 1066,
  .lastSckToPcsDelayInNanoSec = 1066,
  .betweenTransferDelayInNanoSec = 1066,
  .whichPcs = kLPSPI_Pcs0,
  .pcsActiveHighOrLow = kLPSPI_PcsActiveLow,
  .pinCfg = kLPSPI_SdiInSdoOut,
  .dataOutConfig = kLpspiDataOutRetained
};

void LPSPI1_init(void) {
  LPSPI_MasterInit(LPSPI1_PERIPHERAL, &LPSPI1_config, LPSPI1_CLOCK_FREQ);
}

/***********************************************************************************************************************
 * LPUART2 initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'LPUART2'
- type: 'lpuart'
- mode: 'interrupts'
- custom_name_enabled: 'false'
- type_id: 'lpuart_54a65a580e3462acdbacefd5299e0cac'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'LPUART2'
- config_sets:
  - lpuartConfig_t:
    - lpuartConfig:
      - clockSource: 'LpuartClock'
      - lpuartSrcClkFreq: 'BOARD_BootClockRUN'
      - baudRate_Bps: '115200'
      - parityMode: 'kLPUART_ParityEven'
      - dataBitsCount: 'kLPUART_EightDataBits'
      - isMsb: 'false'
      - stopBitCount: 'kLPUART_OneStopBit'
      - txFifoWatermark: '0'
      - rxFifoWatermark: '1'
      - enableRxRTS: 'false'
      - enableTxCTS: 'false'
      - txCtsSource: 'kLPUART_CtsSourcePin'
      - txCtsConfig: 'kLPUART_CtsSampleAtStart'
      - rxIdleType: 'kLPUART_IdleTypeStartBit'
      - rxIdleConfig: 'kLPUART_IdleCharacter1'
      - enableTx: 'false'
      - enableRx: 'false'
  - interruptsCfg:
    - interrupts: 'kLPUART_RxDataRegFullInterruptEnable'
    - interrupt_vectors:
      - enable_rx_tx_irq: 'true'
      - interrupt_rx_tx:
        - IRQn: 'LPUART2_IRQn'
        - enable_priority: 'false'
        - priority: '0'
        - enable_custom_name: 'true'
        - handler_custom_name: 'Mins_IRQHandler'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
const lpuart_config_t LPUART2_config = {
  .baudRate_Bps = 115200,
  .parityMode = kLPUART_ParityEven,
  .dataBitsCount = kLPUART_EightDataBits,
  .isMsb = false,
  .stopBitCount = kLPUART_OneStopBit,
  .txFifoWatermark = 0,
  .rxFifoWatermark = 1,
  .enableRxRTS = false,
  .enableTxCTS = false,
  .txCtsSource = kLPUART_CtsSourcePin,
  .txCtsConfig = kLPUART_CtsSampleAtStart,
  .rxIdleType = kLPUART_IdleTypeStartBit,
  .rxIdleConfig = kLPUART_IdleCharacter1,
  .enableTx = false,
  .enableRx = false
};

void LPUART2_init(void) {
  LPUART_Init(LPUART2_PERIPHERAL, &LPUART2_config, LPUART2_CLOCK_SOURCE);
  LPUART_EnableInterrupts(LPUART2_PERIPHERAL, kLPUART_RxDataRegFullInterruptEnable);
  /* Enable interrupt LPUART2_IRQn request in the NVIC */
  EnableIRQ(LPUART2_SERIAL_RX_TX_IRQN);
}

/***********************************************************************************************************************
 * PIT initialization code
 **********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'PIT'
- type: 'pit'
- mode: 'LPTMR_GENERAL'
- custom_name_enabled: 'false'
- type_id: 'pit_a4782ba5223c8a2527ba91aeb2bc4159'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'PIT'
- config_sets:
  - fsl_pit:
    - enableRunInDebug: 'false'
    - enableSharedInterrupt: 'true'
    - sharedInterrupt:
      - IRQn: 'PIT_IRQn'
      - enable_priority: 'false'
      - priority: '0'
      - enable_custom_name: 'false'
    - timingConfig:
      - clockSource: 'BusInterfaceClock'
      - clockSourceFreq: 'BOARD_BootClockRUN'
    - channels:
      - 0:
        - channel_id: 'CHANNEL_0'
        - channelNumber: '0'
        - enableChain: 'false'
        - timerPeriod: '25ms'
        - startTimer: 'true'
        - enableInterrupt: 'true'
      - 1:
        - channel_id: 'CHANNEL_1'
        - channelNumber: '1'
        - enableChain: 'false'
        - timerPeriod: '1ms'
        - startTimer: 'true'
        - enableInterrupt: 'true'
 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
const pit_config_t PIT_config = {
  .enableRunInDebug = false
};

void PIT_init(void) {
  /* Initialize the PIT. */
  PIT_Init(PIT_PERIPHERAL, &PIT_config);
  /* Set channel 0 period to 25 ms (1875000 ticks). */
  PIT_SetTimerPeriod(PIT_PERIPHERAL, PIT_CHANNEL_0, PIT_CHANNEL_0_TICKS);
  /* Set channel 1 period to 1 ms (75000 ticks). */
  PIT_SetTimerPeriod(PIT_PERIPHERAL, PIT_CHANNEL_1, PIT_CHANNEL_1_TICKS);
  /* Enable interrupts from channel 0. */
  PIT_EnableInterrupts(PIT_PERIPHERAL, PIT_CHANNEL_0, kPIT_TimerInterruptEnable);
  /* Enable interrupts from channel 1. */
  PIT_EnableInterrupts(PIT_PERIPHERAL, PIT_CHANNEL_1, kPIT_TimerInterruptEnable);
  /* Enable interrupt PIT_IRQN request in the NVIC */
  EnableIRQ(PIT_IRQN);
  /* Start channel 0. */
  PIT_StartTimer(PIT_PERIPHERAL, PIT_CHANNEL_0);
  /* Start channel 1. */
  PIT_StartTimer(PIT_PERIPHERAL, PIT_CHANNEL_1);
}

/***********************************************************************************************************************
 * Initialization functions
 **********************************************************************************************************************/
void BOARD_InitPeripherals(void)
{
  /* Initialize components */
  LPSPI1_init();
  LPUART2_init();
  PIT_init();
}

/***********************************************************************************************************************
 * BOARD_InitBootPeripherals function
 **********************************************************************************************************************/
void BOARD_InitBootPeripherals(void)
{
  BOARD_InitPeripherals();
}

2. peripherals.h

/***********************************************************************************************************************
 * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file
 * will be overwritten if the respective MCUXpresso Config Tools is used to update this file.
 **********************************************************************************************************************/

#ifndef _PERIPHERALS_H_
#define _PERIPHERALS_H_

/***********************************************************************************************************************
 * Included files
 **********************************************************************************************************************/
#include "fsl_common.h"
#include "fsl_clock.h"
#include "fsl_lpspi.h"
#include "fsl_lpuart.h"
#include "fsl_pit.h"

#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */

/***********************************************************************************************************************
 * Definitions
 **********************************************************************************************************************/
/* Definitions for BOARD_InitPeripherals functional group */
/* BOARD_InitPeripherals defines for LPSPI1 */
/* Definition of peripheral ID */
#define LPSPI1_PERIPHERAL LPSPI1
/* Definition of clock source */
#define LPSPI1_CLOCK_FREQ 105600000UL
/* Definition of peripheral ID */
#define LPUART2_PERIPHERAL LPUART2
/* Definition of the clock source frequency */
#define LPUART2_CLOCK_SOURCE 80000000UL
/* LPUART2 interrupt vector ID (number). */
#define LPUART2_SERIAL_RX_TX_IRQN LPUART2_IRQn
/* LPUART2 interrupt handler identifier. */
#define Mins_IRQHandler LPUART2_IRQHandler
/* BOARD_InitPeripherals defines for PIT */
/* Definition of peripheral ID. */
#define PIT_PERIPHERAL PIT
/* Definition of clock source frequency. */
#define PIT_CLK_FREQ 75000000UL
/* Definition of ticks count for channel 0 - deprecated. */
#define PIT_0_TICKS 1874999U
/* Definition of ticks count for channel 1 - deprecated. */
#define PIT_1_TICKS 74999U
/* PIT interrupt vector ID (number) - deprecated. */
#define PIT_0_IRQN PIT_IRQn
/* PIT interrupt handler identifier - deprecated. */
#define PIT_0_IRQHANDLER PIT0_IRQHandler
/* PIT interrupt vector ID (number) - deprecated. */
#define PIT_1_IRQN PIT_IRQn
/* PIT interrupt handler identifier - deprecated. */
#define PIT_1_IRQHANDLER PIT1_IRQHandler
/* Definition of channel number for channel 0. */
#define PIT_CHANNEL_0 kPIT_Chnl_0
/* Definition of channel number for channel 1. */
#define PIT_CHANNEL_1 kPIT_Chnl_1
/* Definition of ticks count for channel 0. */
#define PIT_CHANNEL_0_TICKS 1874999U
/* Definition of ticks count for channel 1. */
#define PIT_CHANNEL_1_TICKS 74999U
/* PIT interrupt vector ID (number). */
#define PIT_IRQN PIT_IRQn
/* PIT interrupt handler identifier. */
#define PIT_IRQHANDLER PIT_IRQHandler

/***********************************************************************************************************************
 * Global variables
 **********************************************************************************************************************/
extern const lpspi_master_config_t LPSPI1_config;
extern const lpuart_config_t LPUART2_config;
extern const pit_config_t PIT_config;

/***********************************************************************************************************************
 * Initialization functions
 **********************************************************************************************************************/
void BOARD_InitPeripherals(void);

/***********************************************************************************************************************
 * BOARD_InitBootPeripherals function
 **********************************************************************************************************************/
void BOARD_InitBootPeripherals(void);

#if defined(__cplusplus)
}
#endif

#endif /* _PERIPHERALS_H_ */

Please let me know if you need any more information.

Thanks.

Regards,

Vishal

0 Kudos
254 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Vishal, 

This behavior is due to the ERRATA ERR050130. As a workaround, I would suggest you use Channel 2 instead of Channel 1 of the PIT. 

Link to the ERRATA. 


Have a great day,
Victor

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
254 Views
mjbcswitzerland
Specialist V

Victor

The errata is only relevant when the PIT channels are chained, which they are not in this case.

Also, I have no problem when I test on various i.MX RT devices (using channels 0 and 1) - I suspect that the poster is making an error with the evaluation of the operation rather than the PIT operation itself being defective.

Regards

Mark

[uTasker project developer for Kinetis and i.MX RT]

0 Kudos
254 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello, 

I made some tests on my side with the Evaluation Board. It seems that the Chain mode is activated by default on Channel 1 of the PIT. vishaldahiwal@gmail.com, If you want to use Channel 1, as a workaround, you will need to deactivate the chain mode manually before initializing the channel. For example, before calling the function   PIT_StartTimer(PIT_PERIPHERAL, PIT_CHANNEL_1); You will need to deactivate the chain mode, this can be done with the following instruction: PIT->CHANNEL[1].TCTRL &= ~PIT_TCTRL_CHN_MASK;


Have a great day,
Victor

255 Views
vishaldahiwal
Contributor II

Hi Victor,

The issue is resolved by manually deactivating the chain mode for Channel 1. Thank you very much.

This is required only when I am using channel 1. For Channel 2, this change is not required and everything works with auto-generated code.

Thanks both of you (Mark and Victor) for looking in to this issue and providing valuable inputs.

Regards,

Vishal

View solution in original post

0 Kudos
254 Views
mjbcswitzerland
Specialist V

Vishal

I see no problem with the code.

Import the SDK PIT example for your board and make this change for channel 1, which worked when I tried it.

volatile bool pitIsrFlag = false;
volatile bool pitIsrFlag1 = false;

/*******************************************************************************
 * Code
 ******************************************************************************/
void PIT_LED_HANDLER(void)
{
    /* Clear interrupt flag.*/
    if (PIT_GetStatusFlags(PIT, kPIT_Chnl_0)) {
    PIT_ClearStatusFlags(PIT, kPIT_Chnl_0, kPIT_TimerFlag);
    pitIsrFlag = true;
    }
    if (PIT_GetStatusFlags(PIT, kPIT_Chnl_1)) {
    PIT_ClearStatusFlags(PIT, kPIT_Chnl_1, kPIT_TimerFlag);
    pitIsrFlag1 = true;
    }
    /* Added for, and affects, all PIT handlers. For CPU clock which is much larger than the IP bus clock,
     * CPU can run out of the interrupt handler before the interrupt flag being cleared, resulting in the
     * CPU's entering the handler again and again. Adding DSB can prevent the issue from happening.
     */
    __DSB();
}

    /* Set timer period for channel 0 */
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, USEC_TO_COUNT(1000000U, PIT_SOURCE_CLOCK));
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_1, USEC_TO_COUNT(2000000U, PIT_SOURCE_CLOCK));

    /* Enable timer interrupts for channel 0 */
    PIT_EnableInterrupts(PIT, kPIT_Chnl_0, kPIT_TimerInterruptEnable);
    PIT_EnableInterrupts(PIT, kPIT_Chnl_1, kPIT_TimerInterruptEnable);

    /* Enable at the NVIC */
    EnableIRQ(PIT_IRQ_ID);

    /* Start channel 0 */
    PRINTF("\r\nStarting channel No.0 1...");
    PIT_StartTimer(PIT, kPIT_Chnl_0);
    PIT_StartTimer(PIT, kPIT_Chnl_1);

    while (true)
    {
        /* Check whether occur interupt and toggle LED */
        /* Check whether occur interupt and toggle LED */
        if (true == pitIsrFlag)
        {
            PRINTF("\r\n Channel No.0 interrupt is occurred !");
            LED_TOGGLE();
            pitIsrFlag = false;
        }
        if (true == pitIsrFlag1)
        {
            PRINTF("\r\n Channel No.1 interrupt is occurred !");
            LED_TOGGLE();
            pitIsrFlag1 = false;
        }
    }

Regards

Mark

[uTasker project developer for Kinetis and i.MX RT]

0 Kudos
254 Views
mjbcswitzerland
Specialist V

Hi Vishal

Your interrupt handler is correct so it is probably an issue with the PIT configuration.


I just tested the following code that operated correctly (channel 0 interrupts ever 500us and channel 1 interrupts every 20ms)

iMXRT_PIT_CTL *ptrCtl = (iMXRT_PIT_CTL *)PIT_CTL_ADD;        // channel 0
POWER_UP_ATOMIC(1, PIT_CLOCKS);                              // ensure the PIT module is powered up
PIT_MCR = 0;                                                 // ensure the PIT module is clocked
fnEnterInterrupt(irq_PIT_ID, PIT_settings->int_priority, _PIT_Interrupt); // ensure that the handler for the PIT module is entered
ptrCtl->PIT_LDVAL = 0x29d9;                                  // first channel's interrupt rate (500us)
WRITE_ONE_TO_CLEAR(ptrCtl->PIT_TFLG, PIT_TFLG_TIF);          // clear possible pending interrupt
ptrCtl->PIT_TCTRL = (PIT_TCTRL_TEN | PIT_TCTRL_TIE);         // start PIT with interrupt enabled
ptrCtl++;                                                    // move to channel 1
ptrCtl->PIT_LDVAL = 0x68a0f;                                 // second channel's interrupt rate (20ms)
WRITE_ONE_TO_CLEAR(ptrCtl->PIT_TFLG, PIT_TFLG_TIF);          // clear possible pending interrupt
ptrCtl->PIT_TCTRL = (PIT_TCTRL_TEN | PIT_TCTRL_TIE);         // start PIT with interrupt enabled

Code extrapolated from uTasker solution.

Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]

0 Kudos
254 Views
vishaldahiwal
Contributor II

Hi Mark,

The configuration seems similar. I tried it but did not work. As I am using the MCUXpresso, the code is auto generated.

I observed that the TFLG is not set for Channel 1. It sets for Channel 0.

The below code always returns 0 for channel 1.

pastedImage_1.png

Regards,

Vishal

0 Kudos
254 Views
mjbcswitzerland
Specialist V

Hi Vishal

Can you show the generated code? [all of it]

Regards

Mark

[uTasker project developer for Kinetis and i.MX RT]

0 Kudos