Part Number: TMS570LS3137
Hi, I am trying to measure a PWM input using the N2HET1 of TMS570LS3137. Below is the configuration and code snippets of the implementation. The test signal I fed in to the PWM input is 50Khz with 20% duty cycle. In my logic, I use the PCNT instructions in HR mode to measure the pulse/period. When I run the setup, things work fine and the period and duty cycle are computed correctly. However, every now and then both the values seem to be incorrect i.e. instead of 20 the duty shows up 90, 150 etc and then settles back to 20. The same is the case with period as well. Could you please help me in identifying the issue in my logic?
configuration:
VCLK2 = 20MHz
HR clk = 20MHz
Loop resolution time = 6400 nano seconds, LR prescale = 7.
Pin no: 26
HET program
const uint32_t hetPROGRAM[] =
{
/* PCNT: Capture Duty
* - Instruction = 0
* - Next instruction = 1
* - Conditional next instruction = na
* - Interrupt = na
* - Pin = 26
*/
0x00002E00U | (1U << 6U) | (26U), /* Program */
0x00000000U, /* Control */
0x00000000U, /* Data */
0x00000000U,
/* PCNT: Capture Period
* - Instruction = 1
* - Next instruction = 0
* - Conditional next instruction = na
* - Interrupt = na
* - Pin = 26 + 1
*/
0x00000E80U | (3U << 6U) | ((26U) + 1U), /* Program */
0x00000000U, /* Control */
0x00000000U, /* Data */
0x00000000U
};
CPU code
init code
hetREG1->HRSH = 0x00002000U; /* Set HET pin26/27 high resolution share */
hetREG1->PFR = (7U << 8U); /* setup prescalar*/
memcpy((void *)hetRAM1, (const void *)hetPROGRAM, sizeof(hetPROGRAM));
run time
duty = 100.0 * (double)hetPROGRAM[2] / (double)hetPROGRAM[6];
period = ((hetPROGRAM[6] >> 7U) + (double)(hetPROGRAM[6] & 0x0000007F)/128.0) * 6400.000 / 1000.0;