2146547_en-US

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

2146547_en-US

2146547_en-US

S32K144/146 FTM Counter random randomly updated

Hello

I‘m programming my S32k146/144 board with FTM function and I found a ridiculous issue. I used a data array to record the free running FTM chanle counter. The data stream indicated that the counter occasionally updates to a random number instead of following its normal cyclic way. I tested all FTM chanles with almost the same code on both S32K144 and S32K146,the error perfectly repeated. Beacause the testing code is very simple, I am quite confused. I post the code and result here. Is there anyone could tell me what happed.

void IOC_Init(void)
{
/* Configure clock to FTM0 module and Enable */
PCC->PCCn[PCC_FTM0_INDEX] |= PCC_PCCn_PCS(1) | PCC_PCCn_CGC_MASK;
/* Enable registers updating from write buffers, Enable FTM0,2 Module  */
FTM0->MODE |= FTM_MODE_WPDIS_MASK;
FTM0->MODE |= FTM_MODE_FTMEN_MASK;
/* Clear SC Register,close clock,Set FScaler to 4,Filter 2 */
FTM0->SC = FTM_SC_PS(2);
/* Clear main counter */
FTM0->CNTIN = 0;
FTM0->MOD = 0xFFFF;
 
/* Clock selection and enable*/
FTM0->SC |= FTM_SC_CLKS(3);
}
 
#include "main.h"
 
unsigned int IOC_CH0[256],j=0;
 
void Delay(unsigned int count)
{
unsigned int i;
for (i=0;i
}
 
 
int main(void)
{
/* Initialization: */
 
WDOG_disable(); /* Disable WDOG */
SOSC_init_16MHz();     /* Initialize system oscillator for 16 MHz xtal */
SPLL_init_160MHz();    /* Initialize SPLL to 160 MHz with 8 MHz SOSC */
NormalRUNmode_80MHz(); /* Init clocks: 80 MHz sysclk & core, 40 MHz bus, 20 MHz flash */
 
IOC_CH0[0] = 0;
IOC_Init();
 
/* Infinite for: */
for (;;)/* Loop: if a msg is received, transmit a msg */
{
if (j>255){j = 0;}
IOC_CH0[j] = FTM0->CNT;
Delay(0x1FF);
j++;
}
}FTM_error.PNG


Re: S32K144/146 FTM Counter random randomly updated

Thanks Robin

I have checked my code and confirmed your conclusion. I was not sure about setting FTM IRQs and capturing  wave singnal correctly . So I launched this test .But I didn't notice the updating sittuation of the recording array and made a mistake. Now I can continue working with my signal capturing happily.

Thank your very much.

Sincerely

Re: S32K144/146 FTM Counter random randomly updated

I clicked Resume and then Suspend during debug.

I observed the continuity of the values in the IOC_CH0[] array. I only saw a large difference between IOC_CH0[j] and IOC_CH0[j+1].

This is expected, as FTM0->CNT is only updated to IOC_CH0[j], and the value in IOC_CH0[j+1] has not yet been updated.

Re: S32K144/146 FTM Counter random randomly updated

Thank you Robin

I tried your advice this morning. It is a pitty that the problem remains. I used a LED Toggling schem to indicating the problem and let the code run independently. (Only power connected to the testing board.)The LED blinked randomly.

Here I post my whole project. Please check it. Thank you very much.

Best Regards

Re: S32K144/146 FTM Counter random randomly updated

Hi

It looks like you're observing the data array during debug.
Does this happen when the program is run without debugging? By comparing the difference between the arrays, if the difference exceeds 143, flip the GPIO pin to observe whether this abnormal jumping occurs.

If the issue is related to debugging, it is recommended to check section 47.5.28 Debug mode of S32K1XXRM.


Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "ACCEPT AS SOLUTION" 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.
-------------------------------------------------------------------------------

Tags (1)
No ratings
Version history
Last update:
‎11-20-2025 03:38 PM
Updated by: