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