S32K144_Edge Capure using GPIO or FTM

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

S32K144_Edge Capure using GPIO or FTM

2,771 Views
kwakd_y
Contributor III

▶ Goal:  To calculate the pulse interval.(Using EVBs)

▶ Description

 (1) GPIO pin is set to interrupt when falling or rising edge.(Pin No: EVB1_A)

 (2) And a pulse of 250us cycle is output to the other pin.(Pin No: EVB1_B)

 (3) Set the FTM timer.

 (4) EVB1_A and  EVB1_B are connected.

 (5) When the falling and rising edge of the pulse occurs, the interrupt is executed well and it measures the reading of the time counter when the interrupt occurs. (6)The result is a success of 250us.

▶ problem

  The problem is when two EVBs are used.

  (1) EVB1 and EVB2 Download the same code as above.

  (2) Connect the EVB2 pulse output signal to the EVB1 Capture input pin. Then connect the ground pins to each other.

  (3) And if you calculate the cycle, 30 ~ 40 us is measured instead of 250us.

  (4) When measured with an oscilloscope, a pulse of 250us is output.

  

▶ Question

  I wonder why 30 ~ 40 us is measured when receiving 250us pulse signal from other board.

  The same phenomenon occurs when using FTM Capture instead of GPIO.

 

          efaefgewfwefewfweewe      ()                 The same phenomenon occurs when using FTM Capture instead of GPIO.

9 Replies

1,913 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

can you please share your project? I'll test your scenario with my EVBs. Thanks. 

Jiri

0 Kudos

1,913 Views
kwakd_y
Contributor III

Hi. Jiri

First of all, Thank you for your reply.

I am sorry, but it is difficult to share a project that is being coded.
However, you can see the same thing with the example code.

S32 Disign Studio-> Example -> S32K144 -> FTM. or CooKBooK(https://www.nxp.com/docs/en/application-note/AN5413.pdf)

In example, Input is FTM0_Ch6, Output is FTM0_ch1.

When input and output are connected on the same board and pulse interval is calculated, it is good read, but when the output of another board is connected to the input, it is read shorter than the actual interval.

There is a fact that I learned more through the additional test.
I have caused a low / high toggle when an edge cupture interrupt occurs. The read time through the FTM timer is short, but the toggle signal is output the same as the input signal.

This means that the signal coming from the other board is normally captured, but the speed of the reading timer counter seems strange.


I would appreciate your help. Please reply if you do not understand anything.I would appreciate your help. Please reply if you do not understand anything.

0 Kudos

1,913 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

I updated the example project a little bit (in attachment)  - and for me it is working as expected - terminal output:

pastedImage_1.png

Board settings:

pastedImage_4.png

Signal shape:

pastedImage_5.png

1,913 Views
kwakd_y
Contributor III

Hi, Jiri

Thank you for your reply and your test result.

Like the waveform you attached, the output waveform and the input waveform are measured the same.

Again, I'll explain the problem in detail.

EVB_A:

  -. Input_A: Set Edge capture

  -. Output_A: Set PWM(Period_250us, Duty_50%)

EVB_B:

  -. Input_B: Set Edge capture

  -. Output_B: Set PWM(Period_250us, Duty_50%)

▶ EVB_A and EVB_B have the same code down.

▶ When Input_A and Output_B are connected, each input and output waveform are same.

▶ To measure the interval, I read the FTM.Cnt value at Edge Capture in EVB_A.

▶ The difference between the FTM.cnt value at the rising edge and the FTM.cnt value at the falling edge is the period.

▶ When Input_A and Output_B are connected, The period obtained through the FTM.cnt value is about 30us.

   When Input_A and Output_A are connected, The period obtained through the FTM.cnt value is about 250us.For each connection, the Output_A and Output_B signals are the same waveform with a period of 250us.

   However, the difference in FTM.Cnt change rate in EVB_A can not be understood.

In the example code below, "FTM0->CONTROLS[6].CnV It is a difference When Input_A and Output_B are connected.

and When Input_A and Output_A are connected.

<example code: calculate period>

void FTM0_CH6_input_capture(void) {
  if (1==((FTM0->CONTROLS[6].CnSC & FTM_CnSC_CHF_MASK)>>FTM_CnSC_CHF_SHIFT)) {
                                                /* If chan flag is set */
  FTM0->CONTROLS[6].CnSC &= ~FTM_CnSC_CHF_MASK;    /* Clear flag: read reg then set CHF=0 */
  PriorCaptureVal = CurrentCaptureVal;             /* Record value of prior capture */
  CurrentCaptureVal = FTM0->CONTROLS[6].CnV;       /* Record value of current capture */
  DeltaCapture = CurrentCaptureVal - PriorCaptureVal;
                                  /* Will be 6250 clocks (100 msec) if connected to FTM0 CH0 */
  }
}

<example code: FTM0 Init>

void FTM0_init(void) {
  PCC->PCCn[PCC_FTM0_INDEX] &= ~PCC_PCCn_CGC_MASK;  /* Ensure clk disabled for config */
  PCC->PCCn[PCC_FTM0_INDEX] |= PCC_PCCn_PCS(0b001) /* Clock Src=1, 8 MHz SOSCDIV1_CLK */
                                |  PCC_PCCn_CGC_MASK;   /* Enable clock for FTM regs */
  FTM0->MODE |= FTM_MODE_WPDIS_MASK;  /* Write protect to registers disabled (default) */
  FTM0->SC = 0x00030000;     /* Enable PWM channel 0 output*/
                             /* Enable PWM channel 1 output*/
                             /* TOIE (Timer Overflow Interrupt Ena) = 0 (default) */
                             /* CPWMS (Center aligned PWM Select) = 0 (default, up count) */
                             /* CLKS (Clock source) = 0 (default, no clock; FTM disabled) */
                             /* PS (Prescaler factor) = 7. Prescaler = 128 */
  FTM0->COMBINE = 0x00000000;/* FTM mode settings used: DECAPENx, MCOMBINEx, COMBINEx=0  */
  FTM0->POL = 0x00000000;    /* Polarity for all channels is active high (default) */
  FTM0->MOD = 62500 -1 ;     /* FTM1 counter final value (used for PWM mode) */
                             /* FTM1 Period = MOD-CNTIN+0x0001 ~= 62500 ctr clks  */
                             /* 8MHz /128 = 62.5kHz ->  ticks -> 1Hz */}

}

void FTM0_CH6_IC_init(void) {
  FTM0->CONTROLS[6].CnSC = 0x0000000C;  /* FTM0 ch6: Input Capture rising or falling edge */
                                        /* CHIE (Chan Interrupt Ena) = 0 (default) */
                                        /* MSB:MSA (chan Mode Select)=0b00, Input Capture */
                                        /* ELSB:ELSA (ch Edge/Level Select)=0b11, rise or fall*/
}

0 Kudos

1,913 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

that's what I exactly did - connected two boards Input_A to output_B (don't care about Ch2 on scope - I just forgot disconnect it). But I used different example to avoid using breakpoints. 

In the non SDK example (the FTM_s32k144) is not handled timer Overflow and you get periodically wrong value. In this particular case - 9 times okay value - then counter overflows (FTM.SC.TOF) - you need to handle this event. 

pastedImage_1.png

How do you check the DeltaCapture value? Don't forget that these two boards aren't synchronized - so if you are using breakpoints - you will resume in random point of PWM period. 

Hope it helps. 

Jiri 

0 Kudos

1,913 Views
kwakd_y
Contributor III

Hi, Jiri

The point of the problem seems to have been misunderstood.

1. Related to TOF

 ▶ This register is set when FTM.CNT equals FTM.MOD. FTM.CNT continues to be clocked regardless of the TOF, and I do not use the FTM timer interrupt, so it has nothing to do with the TOF register.
If you are talking about the Interrupt flag at Capture, I'm clearing that flag for every Edge interrupt.

"In this particular case - 9 times okay value - then counter overflows (FTM.SC.TOF) "

 --> It is measured strangely from the beginning 9 times.

2. you said that " Don't forget that these two boards aren't synchronized "

 ▶ If I try to read FTM.Cnt of EVB_B when the signal of output_B comes in, you are right.

 ▶ However, I read EVB_A's FTM.Cnt. If you measure the signal that Output_B is input to EVB_A, it is normal to 250us.

★ It seems to be difficult to understand because it is two boards.
Simply, the thing that makes me question is that the signal that Output_A and Output_B go into Input_A when measuring with an oscilloscope is the same, but why the rate of increase of FTM_Cnt of EVB_A is different.

0 Kudos

1,913 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

So - let's make a summary:

  • I'm using FTM_s32k144 example - as it is, without any modification. Part of code which you shared looks like exactly the same as in the FTM_s32k144 example. 
  • I have two boards EVB_1 and EVB_2 with very same program. Both boards have one FTM input on ch6 (PTE-8) and one Output with 4Hz on PTD-15. Let's name these pins as EVB_1_In, EVB_1_Out, EVB_2_In, EVB_2_Out. 

Observed behavior on my side with FTM_s32k144 example

Scenario 1: EVB_1_In connected to EVB_1_Out - got correct value 250ms for 9 times, 10th time counter  overflows and I got bad vaule. Also FTM.SC.TOF is set to 1. 

Scenario 2: EVB_1_In connected to EVB_2_Out (GND is also connected) - I have the very same result. 9 times okay value, 10th counter overflows and FTM.SC.TOF is set to 1. 

The way how is the FTM_s32k144 written doesn't care about counter reset/overflow and uses cumulative global variables for period computing. The counter overflow event is handled as rise/fall edge by the example. 

Am I missing something? 

It will be very helpful if you can share your project. With standard non SDK  FTM example I can't reproduce your issue - or may be I still don't get it. 

Jiri

0 Kudos

1,913 Views
kwakd_y
Contributor III

Hi, Jiri

Thank you for help.

I solved the problem.

The problem was a breakpoint.

If there is a breakpoint when connecting EVB1_input and EVB2_output, I get the wrong result.

Thank you again for your help.

Have great day. Bye

1,913 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

okay, I'll try the examples and let you know. 

Jiri

0 Kudos