FC321_GetTimeUS function always returns zero

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

FC321_GetTimeUS function always returns zero

Jump to solution
5,381 Views

Hi there!

I'm using the Kinetis MKE02Z16VFM4, and I’m trying to use a free count (32 b) generated by Processor Expert. But I’m not getting the value. In my code I have:

                uint16_t t0 = 0;                 //definition

                //… some code...

                FC321_GetTimeMS( &t0 );

                //t0 always zero :$

                                                             //…

I put a break point in the line with the function “FC321_GetTimeMS”, and run step by step in CodeWarrior… the function always return “no error”, but my variable (t0) never changes.

Obs.1: In the Clock settings, I’m using Internal oscillator.

Obs.2: Please find attached the screenshot of the SysTick free count (Processor Expert) attached.

 

Do you have any idea of what I’m missing?

Labels (1)
0 Kudos
Reply
1 Solution
5,273 Views

Thank you for your reply!

Have you checked the “.zip” file that I attached at about a week ago?

I was checking it again, and I found an error in the settings of the microcontroller in the process expert. After I changed it the timer worked normal.

Thanks for the support.

View solution in original post

0 Kudos
Reply
8 Replies
5,376 Views
bobpaddock
Senior Contributor III

Putting 32 bit result into 16 bit variable?

Is the clock source enabled?

Interrupt priority levels are always best to be avoided.

Run everything at the same level unless some extrema reason not to do so.

 

 

 

 

0 Kudos
Reply
5,366 Views

Hi, thank you for your reply!

Yeah, the function is for a 16 bit variable as you can see in the automatically generated function:

 

/*

** ===================================================================

**     Method      :  FC321_GetTimeMS (component FreeCntr32)

**     Description :

**         Returns the time (as a 16-bit unsigned integer) in milliseconds

**         since the last resetting after the last reset.

**     Parameters  :

**         NAME            - DESCRIPTION

**       * Time            - A pointer to the returned 16-bit value

**                           in milliseconds

**     Returns     :

**         ---             - Error code, possible codes:

**                           ERR_OK - OK

**                           ERR_SPEED - This device does not work in

**                           the active speed mode

**                           ERR_OVERFLOW - Software counter overflow

**                           ERR_MATH - Overflow during evaluation

** ===================================================================

*/

#define FC321_GetTimeMS(Time) (RealTimeLdd1_GetTimeMS(RealTimeLdd1_DeviceData, (uint16_t *)Time))

 

Yes, the Clock is enable, but it is not possible to disable the Interrupt service in the options (for this FreeCntr32).

0 Kudos
Reply
5,361 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi

Have you test the Typical Usage of FreeCntr32?

void main(void)
{
  unsigned int i, time;
  float one_loop_us;
  
  FC321_Reset(); /* reset the counter */
  
  for (i = 0; i < 60000; ++i); /* for-cycle */
  
  /* get measured time of whole for-cycle */
  if(FC321_GetTimeUS(&time) == ERR_OK) {
  
    /* average time of one loop */
    one_loop_us = time / 60000.0; 
  }  
}


Typical Usage FreeCntr32.png

I don't have the FRDM-KE02Z40M board, so I can't debug it. If still not work, have you try to select other timer?(for example: PIT or FTM)

Best Regards,
Robin
-------------------------------------------------------------------------------
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
Reply
5,356 Views

Hi! Thank you for your reply!

I tested the Typical Usage, but I get the same problem as before… the variables “time” and “one_loop_us” are always zero. I also tried with PIT and FTM, but the problem remains.

I’m using the internal oscillator is it fine to use it when using the FreeCntr32?

0 Kudos
Reply
5,286 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Sorry for my delay!

Please check the Error code of FC321_GetTimeUS
LDD_TError Error;
Error = FC321_GetTimeUS(&time);

FC321_GetTimeUS Error code.png

About the time=0, it seems that the delay is too large, you can try to make it smaller:

for (i = 0; i < 30000; ++i); /* for-cycle */
0 Kudos
Reply
5,274 Views

Thank you for your reply!

Have you checked the “.zip” file that I attached at about a week ago?

I was checking it again, and I found an error in the settings of the microcontroller in the process expert. After I changed it the timer worked normal.

Thanks for the support.

0 Kudos
Reply
5,341 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

It works on FRDM-KL25Z board. Maybe you can compare the register of Systick.

FC321_GetTimeUS.png

0 Kudos
Reply
5,328 Views

Hi! Thank you for your reply!

 

I created a new project using only the FreeCntr32. I ran the code and the “SYST_CVR” register is ticking down… but “time” and “one_loop_us” variables are always zero AFTER the “FC321_GetTimeUS” calling. It is also zero even if I use the function “FC321_GetTimeMS”, as showed in the attached screenshot.

(Obs. 1: If I do not initialize the “time” and “one_loop_us”, sometimes I get some random weird number as in your screenshot.)

(Obs. 2: The GetCounterValue function, in the TU1:TimerUnit_LDD, in the Referenced_Components is working).

 

I attached the .zip of the project… I think it is some silly think that I may be missing

 

could you please take a look at it?

0 Kudos
Reply