This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS570LS3137: HET microcode to perform pulse/period measurement working intermittently

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;

  • Hello Brayan,

    Your input signal is 50khz, the period is 20us, and high pulse is 4us (20% duty cycle). The LPR in your setup is 6.4us. Can you increase the VCLK2 to half of the system clock and try again? At what condition you see the wrong value?

    Regards,
    QJ
  • Hello QJ, thanks for your reply.

    We have a design restriction to keep the VCLK2 at 20MHz.However, I changed the LRP to 3.2us and I don't see the issue. But with LRP of 3.2us, the loop resolution prescalar has to be 6 reducing the number of instruction cycles to 64. We want to have the full 128 instruction cycles per loop.

    In the HET code, I am using PCNT in high resolution with corresponding pin HR structure shared. Therefor, even with loop resolution at 6.4us I was expecting the HET code to be able to detect a pulse/period of atleast 1 high resolution period i.e. 50nano seconds. Is that correct assumption?

    Also, to answer your last question, once I power up, the board is configured to log the duty/period at every 1sec via UART. The input fed in is a constant 50KHz/20% dutycycle signal and is monitored on the oscilloscope. The observation is that once in every 3 seconds a wrong value is shown up for duty cycle or period or both. This behavior vanishes if I change the loop resolution to 3.2us and I am able to see the correct value of duty/period all the time every second.

    regards

    Brayan