Hi,
I am using TWRKV46F150M evaluation board.
I'm testing PWM input capture by configuring PWMA submodule 0 A and B pins to capture input pulses. A0 and A1 captures rising and falling edges of PWM (on time). B0 and B1 captures two consecutive falling edges (period). Interrupt triggered by capture A0.
Submodule 2 is configured to generate 50 kHz PWM signal with 20% duty on both pins A and B.
SM2 PWM output is connected to SM0 input capture pins.
Capture value registers are being read in the interrupt and on time and period is calculated.
/* PWMA_CAP_IRQn interrupt handler */
void PWMA_OREDCAPTURE_IRQHANDLER(void) {
/* Place your code here */
static uint16_t capture_array[10][4];
static int i = 0;
static int32_t on_time = 0;
static int32_t period = 0;
capture_array[i][0] = PWMA->SM[kPWM_Module_0].CVAL2;
capture_array[i][1] = PWMA->SM[kPWM_Module_0].CVAL3;
capture_array[i][2] = PWMA->SM[kPWM_Module_0].CVAL4;
capture_array[i][3] = PWMA->SM[kPWM_Module_0].CVAL5;
on_time = capture_array[i][1] - capture_array[i][0];
period = capture_array[i][3] - capture_array[i][2];
if(++i >= 10)
{
i = 0;
}
/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F
Store immediate overlapping exception return operation might vector to incorrect interrupt. */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}
Expectation is that (CVAL3-CVAL2) and (CVAL5-CVAL4) are either always positive or always negative. Also, (CVAL3-CVAL2) must always give the on time.
Here, I am seeing that the on time and period are positive in some captures and negative value in the others. Also, in some cases, (CVAL3-CVAL2) contains the off time value.
I ran the code without breakpoints for 5 seconds and added breakpoint in the ISR to capture the values. The table below shows similar captured values -
| on_time | period |
| 40 | 208 |
| 40 | 208 |
| 40 | -208 |
| -168 | 208 |
| 40 | -208 |
| 40 | 208 |
| 40 | -208 |
| 40 | 208 |
| 40 | 208 |
| -168 | -208 |
| 40 | 208 |
| 40 | -208 |
| 40 | -208 |
| 40 | 208 |
| 40 | -208 |
| 40 | -208 |
| 40 | 208 |
| -168 | -208 |
| 40 | 208 |
| 40 | -208 |
| 40 | 208 |
| 40 | 208 |
| 40 | -208 |
| -168 | 208 |
| 40 | -208 |
| 40 | 208 |
| 40 | -208 |
| 40 | 208 |
| 40 | 208 |
| -168 | -208 |
| 40 | 208 |
| 40 | -208 |
This table was captured using MKV46F256VLH16 MCU. Similar values seen in the eval board.
Here, I expect all on time values to be same and equal to 40 and all period values be same and equal to 208. Why are there such variations? Are some edges being skipped? Is there some delay in updating the VAL registers?
J510.9 connected to J501.34 and J501.11 connected to J501.36 on the eval board. Project (eval board) is attached as zip file for reference.