IMXRT1024 PIT GetCurrentTimerCount

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

IMXRT1024 PIT GetCurrentTimerCount

Jump to solution
1,930 Views
Lukas_Frank
Senior Contributor I

Hi all,

 

I just want to try use Periodic Interrupt Timer in my board. I was only changed/added below lines in default SDK example(pit).

 

volatile uint32_t globalCounter = 0; //new line for test
void PIT_LED_HANDLER(void)
{
    /* Clear interrupt flag.*/
    PIT_ClearStatusFlags(DEMO_PIT_BASEADDR, DEMO_PIT_CHANNEL, kPIT_TimerFlag);
    pitIsrFlag = true;
    globalCounter++; //new line for test
    __DSB();
}
...
..
.    
/* Start channel 0 */
PRINTF("\r\nStarting channel No.0 ...");
PIT_StartTimer(DEMO_PIT_BASEADDR, DEMO_PIT_CHANNEL);

uint64_t startVal = PIT_GetCurrentTimerCount(DEMO_PIT_BASEADDR, DEMO_PIT_CHANNEL);
while (true)                                                                              
{                                                                                         
    /* Check whether occur interupt and toggle LED */                                     
    if (true == pitIsrFlag && globalCounter < 6)                                          
    {                                                                                     
        PRINTF("\r\n Channel No.0 interrupt is occurred !");                              
        LED_TOGGLE();                                                                     
        pitIsrFlag = false;                                                               
    }                                                                                     
    if(globalCounter >= 6)//new lines below                                                         
    {                                                                                     
    	uint64_t endVal = PIT_GetCurrentTimerCount(DEMO_PIT_BASEADDR, DEMO_PIT_CHANNEL);  
    	uint64_t resultVal = endVal - startVal;                                           
    	uint64_t usecVal = COUNT_TO_USEC(resultVal, PIT_SOURCE_CLOCK);                    
    }                                                                                     
}                                                                                         
                                                                                          

 

 

I am just waiting for usecVal will be equal to the 5 sec so about 5000000 mikrosecond. I am just trying to use ticks for chronometer usage in my project. But in this code neither usecVal is equal 5sec or resultVal is equal to tick corresponding 5sec after run the project. What is wrong with that? All codes belowed in attachment.

 

Thanks and Regards. 

Labels (1)
0 Kudos
Reply
1 Solution
1,903 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi @Lukas_Frank ;

PIT_GetCurrentTimerCount is used to read current timer counting value.

COUNT_TO_USEC is used to convert a raw count alue to microsecond.

Please see below line for the usage.

 

uint32_t usecVal = COUNT_TO_USEC((uint64_t)PIT_GetCurrentTimerCount(DEMO_PIT_BASEADDR, DEMO_PIT_CHANNEL), PIT_SOURCE_CLOCK);
PRINTF("\r\n useVal is %d",usecVal);

 

danielchen_0-1632712735758.png

Regards

Daniel

View solution in original post

2 Replies
1,904 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi @Lukas_Frank ;

PIT_GetCurrentTimerCount is used to read current timer counting value.

COUNT_TO_USEC is used to convert a raw count alue to microsecond.

Please see below line for the usage.

 

uint32_t usecVal = COUNT_TO_USEC((uint64_t)PIT_GetCurrentTimerCount(DEMO_PIT_BASEADDR, DEMO_PIT_CHANNEL), PIT_SOURCE_CLOCK);
PRINTF("\r\n useVal is %d",usecVal);

 

danielchen_0-1632712735758.png

Regards

Daniel

1,893 Views
Lukas_Frank
Senior Contributor I

Hi Dear @danielchen , 

Appreciate for your supports.

Best Regards.

0 Kudos
Reply