eFlexPWM input capture

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

eFlexPWM input capture

1,000 Views
JulianS
Contributor II

Hello,

I am testing the pwm input capture capabilities on the MKV58F1M0VLQ24 and I guess that I miss something basic here.

In general, I am aware that for input capturing, the FTM Module is the first choice. I already validated this module successfully capturing the tacho signal of a fan (signal frequency at ~300 Hz). In order to validate the pwm input capture capabilities (for general module testing purposes) I am now trying to get a similar result for the same hardware setup.

To my setup:
The tacho is connected to the µC pin PORTE25 which then is multiplexed as an XBARA input XB_In3 which will be connected via XBARA to XBARA_OUT20 (PwmCh0ExtA).

My initialization for this setup looks like this (using the NXP SDK version 2.7.0):

CLOCK_EnableClock(kCLOCK_PortE);

port_pin_config_t portConfig =
{
	.pullSelect = kPORT_PullUp,
	.slewRate = kPORT_FastSlewRate,
	.passiveFilterEnable = kPORT_PassiveFilterDisable,
	.openDrainEnable = kPORT_OpenDrainDisable,
	.driveStrength = kPORT_LowDriveStrength,
	.lockRegister = kPORT_UnlockRegister
};

portConfig.mux = kPORT_MuxAlt4;
PORT_SetPinConfig(PORTE, 25, &portConfig);

SIM->SCGC4 = ((SIM->SCGC4 &
(~SIM_SCGC4_PWM0_SM0_MASK))
  | SIM_SCGC4_PWM0_SM0(1)
);
XBARA_Init(XBARA);
XBARA_SetSignalsConnection(XBARA,
						   kXBARA_InputXbarIn3,
						   kXBARA_OutputPwmCh0ExtA);

pwm_config_t config;
PWM_GetDefaultConfig(&config);
config.prescale = kPWM_Prescale_Divide_128;
PWM_Init(PWM0, kPWM_Module_0, &config);
pwm_input_capture_param_t inputCaptureParams =
{
	.captureInputSel = false,
	.edgeCompareValue = 0,
	.edge0 = kPWM_RisingEdge,
	.edge1 = kPWM_Disable,
	.enableOneShotCapture = false,
	.fifoWatermark = 0
};
PWM_SetupInputCapture(PWM0, kPWM_Module_0, kPWM_PwmA, &inputCaptureParams);
PWM_StartTimer(PWM0, kPWM_Control_Module_0);

After the initialization I poll the pwm registers manually by key-pressing in order to see if the capture works in any way:

printf("Counter Register:                 %d\n", PWM0->SM[0].CNT);
printf("Initial Count Register:           %d\n", PWM0->SM[0].INIT);
printf("Value Register 0:                 %d\n", PWM0->SM[0].VAL0);
printf("Value Register 1:                 %d\n", PWM0->SM[0].VAL1);
printf("Value Register 2:                 %d\n", PWM0->SM[0].VAL2);
printf("Value Register 3:                 %d\n", PWM0->SM[0].VAL3);
printf("Value Register 4:                 %d\n", PWM0->SM[0].VAL4);
printf("Value Register 5:                 %d\n", PWM0->SM[0].VAL5);
printf("Status Register:                  %d\n", PWM0->SM[0].STS);
printf("Capture Control A Register:       %d\n", PWM0->SM[0].CAPTCTRLA);
printf("Capture Compare A Register:       %d\n", PWM0->SM[0].CAPTCOMPA);
printf("Capture Value 0 Register:         %d\n", PWM0->SM[0].CVAL0);
printf("Capture Value 1 Register:         %d\n", PWM0->SM[0].CVAL1);
printf("Capture Value 2 Register:         %d\n", PWM0->SM[0].CVAL2);
printf("Capture Value 3 Register:         %d\n", PWM0->SM[0].CVAL3);
printf("Capture Value 4 Register:         %d\n", PWM0->SM[0].CVAL4);
printf("Capture Value 5 Register:         %d\n", PWM0->SM[0].CVAL5);
printf("Capture Value Cycle 0 Register:   %d\n", PWM0->SM[0].CVAL0CYC);
printf("Capture Value Cycle 1 Register:   %d\n", PWM0->SM[0].CVAL1CYC);
printf("Capture Value Cycle 2 Register:   %d\n", PWM0->SM[0].CVAL2CYC);
printf("Capture Value Cycle 3 Register:   %d\n", PWM0->SM[0].CVAL3CYC);
printf("Capture Value Cycle 4 Register:   %d\n", PWM0->SM[0].CVAL4CYC);
printf("Capture Value Cycle 5 Register:   %d\n", PWM0->SM[0].CVAL5CYC);

Up to now, the only register that is changing perpetually is the Counter Register CNT. The other registers persist in the following states:

Counter Register:                 50810
Initial Count Register:           0
Value Register 0:                 0
Value Register 1:                 0
Value Register 2:                 0
Value Register 3:                 0
Value Register 4:                 0
Value Register 5:                 0
Status Register:                  28735
Capture Control A Register:       9
Capture Compare A Register:       0
Capture Value 0 Register:         0
Capture Value 1 Register:         0
Capture Value 2 Register:         0
Capture Value 3 Register:         0
Capture Value 4 Register:         0
Capture Value 5 Register:         0
Capture Value Cycle 0 Register:   0
Capture Value Cycle 1 Register:   0
Capture Value Cycle 2 Register:   0
Capture Value Cycle 3 Register:   0
Capture Value Cycle 4 Register:   0
Capture Value Cycle 5 Register:   0

As no value or capture value register is changing in the process, I assume that there is still something important missing. Up to now, I am not even sure if I can use this module similar to my previous tests with the FTM module.

Can you tell me what the missing part is, or if the setup is possible with the eFlexPWM input capture in general?

Kind regards,
Julian

Tags (1)
0 Kudos
2 Replies

979 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

Hope you are well.
The eFlexPWM can be used as input capture. To a detailed explanation and recommendations of how to setup this module you can check this document: https://community.nxp.com/t5/Digital-Signal-Controllers/The-Capture-feature-of-eFlexPWM-module/ta-p/...

Let me know if this is helpful, if you have more questions do not hesitate to ask me.
Best regards,
Omar

0 Kudos

966 Views
JulianS
Contributor II

Hello Omar,

thank you for your response!

I already studied your mentioned document during my initial setup of the PWM input capture.

In general I think the problem is based on the selection of my µC-Pin setup.
You can see that I am using the crossbar switch for my input signal in order to connect  my µC-Pin with the multiplex XB_In3 to "kXBARA_OutputPwmCh0ExtA".
After rereading the reference manual, I think the setup failed because I tried using a extern synchronisation input instead of using a correct µC-Pin with e.g. "FLEXPWM0_A0" multiplex.

As I am currently not able to reroute the tacho-signal on my pcb to an other µC pin, I will get back to this case when I have the opportunity to make those changes.

Kind regards,
Julian

0 Kudos