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.

MSPM0C1104: Offset From Expected Delay When Using delay_cycles Function

Part Number: MSPM0C1104

Hello E2E Experts,

I have a Code Composer program that runs a simple algorithm that begins on processor power-up. The processor sets a pin HIGH after a specified delay set by delay_cycles(cycles), where cycles is calculated with the target delay in milliseconds * clock frequency (32.77kHz). 

However, when I measure the actual delay from start-up to pin HIGH, I measure about 33ms longer than the target delay. I also observed that this 33ms offset decreases as the target delay increases by about 10ms per 1000ms of target delay. 

Can you please help me understand the cause of this offset so that I can either eliminate it or design around it?

  • I think the delay is not from delay_cycles(cycles) because after power-up MCU will enter bootcode first.

    Could you set pin high before delay_cycles(cycles), and set low after delay_cycles(cycles). Then observe the waveform again.

  • I reconfigured the code to set the pin high on power-up and low after delay_cycles(cycles), and this was the result when the delay was set to 300ms:  

    Time (ms) Event
    0 Power-on
    ~2.5 Pin High
    ~328 Pin Low
  • Also, I observed that the 2.5ms offset is constant for different values of cycles, but the offset of Pin High - Pin Low decreases as cycles increase, even becoming negative at long delays

  • Pin high is before delay_cycles, pin low is after delay_cycles.

    If the cycles increase, the time between pin high to pin low should increase too.

    We have tested function of delay_cycles() and it works well.

  • Yes, cycles does increase the time between Pin High and Pin low, but there is an offset in the measured time vs. the expected time. For the example above, I expected the time between Pin High and Pin Low to be 300ms. However, when I measure the delay, I see ~325ms. When I reprogram for a 1000ms delay, I measure closer to 1018ms between Pin High and Pin Low. It is this offset (Measured Delay - Expected Delay) that I would like guidance on. I am also interested in what is causing the 2.5ms delay between Power-on and Pin High if the Pin High is placed before delay_cycles(cycles).

    Thank you

  • Hello Cameron,

    Sorry for jumping in. I have helped to do tests on my side using LP-MSPM0C1104. You can see my test code is below, setting high is about 300ms and setting low is about 1000ms. The test results are side using GPIO toggle to calculate is: 300ms -> 298ms, 1000ms -> 995ms

    The optimization level is 2, which is the default level of CCS setting.

    Best Regards,

    Janz Bai

  • Hello Janz,

    Thank you for your input. I wrote a test code that merged your test with mine, and I believe I found the issue. To calculate cycles, I multiplied the clock frequency by an integer representing the target delay in milliseconds. I originally used an unsigned int for this variable, but upon changing it to a const int the measured delay matched the expected. In the example below, the results are the following: delay1_ms -> 321ms, delay2_ms -> 995ms.

    unsigned int delay1_ms = 300; // Desired delay in milliseconds
    const int delay2_ms = 1000;   // Desired delay in milliseconds

    int main(void)
    {
        /* Power on GPIO, initialize pins as digital outputs */
        SYSCFG_DL_init();
        DL_GPIO_setPins(GPIO_MATCH_PORT, GPIO_MATCH_USER_MATCH_PIN | GPIO_MATCH_USER_TEST_PIN); // Set Pin to HIGH
        delay_cycles(delay1_ms * 32.77);
        DL_GPIO_clearPins(GPIO_MATCH_PORT, GPIO_MATCH_USER_MATCH_PIN | GPIO_MATCH_USER_TEST_PIN); // Default: LED is off
        delay_cycles(delay2_ms * 32.77);
        DL_GPIO_setPins(GPIO_MATCH_PORT, GPIO_MATCH_USER_MATCH_PIN | GPIO_MATCH_USER_TEST_PIN); // Set Pin to HIGH
       
        return 0;
    }
    I just have 2 more questions:
    1. Is the 2% clock error the cause of the difference in your results (298ms vs. 300ms & 995ms vs. 1000ms)?
    2. When I measure my waveform for the code above, why do I consistently see a 2.7ms delay between the rising edge of VCC and the rising edge of the first GPIO High?
  • 1. 2% clock could be the possible cause for the difference in results. Or you can test more boards to get more results to observe.

    2. As mentioned, when power-up MCU needs to execute boot code at first, then execute application .