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.

CCS/MSP432P401R: DELAY FUNCTION FOR MSP432 LAUNCHPAD

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hi friends,

I am doing a project in MSP432P401R Launchpad. For my project I need an accurate delay function, because I need milliseconds and microseconds delays. Could anyone suggest me an accurate delay function for msp432 launchpad working with CCS studio.

Thank you.

  • Hi!

    Using a timer module might be the best option for precise timing tasks - and of course you need a precise clock source.
  • Hi Dennis,
    Could you please give me an example project for led toggle using timer module for msp432.
  • Have a look at these code examples, especially

    • msp432p401x_ta0_01                             Timer0_A3, Toggle P1.0, CCR0 Cont Mode ISR, DCO SMCLK
    • msp432p401x_ta0_02                             Timer0_A3, Toggle P1.0, CCR0 Up Mode ISR, DCO SMCLK
    • msp432p401x_ta0_03                             Timer_A3, Toggle P1.0, Overflow ISR, DCO SMCLK
    • msp432p401x_ta0_04                             Timer0_A3, Toggle P1.0, Overflow ISR, 32kHz ACLK
    • msp432p401x_ta0_08                             Timer_A3, Toggle P1.0;P7.3,P2.4-5, Cont. Mode ISR, 32kHz ACLK
    • msp432p401x_ta1_05                             Timer1_A3, Toggle P1.0, CCR0 Cont. Mode ISR, 32kHz ACLK
    • msp432p401x_ta1_11                             Timer_A3, Toggle P8.0/TA1.0, Up Mode, 32kHz ACLK
    • msp432p401x_ta1_13                             Timer1_A3, Toggle P8.0/TA1.0, Up/Down Mode, DCO SMCLK
    • msp432p401x_ta1_14                             Timer1_A3, Toggle P8.0/TA1.0, Up/Down Mode, 32kHz ACLK

    Dennis

  • Hi Dennis,
    When I copy paste the code to ccs project, it shows many errors. I am sorry I am not an expert to solve this many errors.My CCS version is 6.1.2. I could only install this version because bigger versions shows error during installation. So could you give me just an led toggle project  using timer for my version.

    The below is my errors when I copy paste the msp432p401x_ta0_02  project.

     

    Description Resource Path Location Type
    #135 expected a field name blink.c /timer line 76 C/C++ Problem
    #135 expected a field name blink.c /timer line 100 C/C++ Problem
    #137 struct "<unnamed>" has no field "CCR" blink.c /timer line 87 C/C++ Problem
    #137 struct "<unnamed>" has no field "CCTL" blink.c /timer line 85 C/C++ Problem
    #137 struct "<unnamed>" has no field "CCTL" blink.c /timer line 86 C/C++ Problem
    #137 struct "<unnamed>" has no field "CCTL" blink.c /timer line 98 C/C++ Problem
    #137 struct "<unnamed>" has no field "CTL" blink.c /timer line 71 C/C++ Problem
    #137 struct "<unnamed>" has no field "CTL" blink.c /timer line 88 C/C++ Problem
    #20 identifier "P1" is undefined blink.c /timer line 75 C/C++ Problem
    #20 identifier "P1" is undefined blink.c /timer line 100 C/C++ Problem
    #20 identifier "TIMER_A_CCTLN_CCIE" is undefined blink.c /timer line 86 C/C++ Problem
    #20 identifier "TIMER_A_CCTLN_CCIFG" is undefined blink.c /timer line 85 C/C++ Problem
    #20 identifier "TIMER_A_CCTLN_CCIFG" is undefined blink.c /timer line 98 C/C++ Problem
    #20 identifier "TIMER_A_CTL_MC__UP" is undefined blink.c /timer line 89 C/C++ Problem
    #20 identifier "TIMER_A_CTL_SSEL__SMCLK" is undefined blink.c /timer line 88 C/C++ Problem
    #20 identifier "WDT_A_CTL_HOLD" is undefined blink.c /timer line 72 C/C++ Problem
    #20 identifier "WDT_A_CTL_PW" is undefined blink.c /timer line 71 C/C++ Problem

     

  • I like to mimic the arduino millis() function. This works well for millisecond delays - you need to test it for microsecond resolution.

    // global
       volatile uint32_t Tick;
    
    // In main/init    
        MAP_SysTick_enableModule();
        MAP_SysTick_setPeriod(1500000); //Depends on your clock and tick requirements
        MAP_SysTick_enableInterrupt();
        
        /* Enabling MASTER interrupts */
        MAP_Interrupt_enableMaster();  
    
    // ...
    
    void SysTick_Handler(void)
    {
        Tick++;
    }
    
    

    To time things you can simply save Tick at the start, and subtract the current Tick at the finish.

  • Hi Keith,
    I don't understand what is the outcome of above code. How do I add a delay using above code?
  • You can use it to add a delay, or just use it to do things at a certain time in your main loop.

    For a delay, write a function:

    void delay(uint32_t delay_ms) // assumes 1 ms tick.
    {
    uint32_t start = Tick;

    while (Tick - start < delay_ms) ; // nop
    }

    It also gives you a general purpose timer.

    Other wise if you have an "event loop" you can have a delay that does not block the main thread:

    main()
    {
    //init stuff
    uint32_t repetition_time = 300; // every 300 ms or so

    uint32_t start_time = Tick;
    while(1) { // event loop
    // stuff
    if (Tick - start_time > repetition_time) {
    start_time = Tick; // reset the clock
    // do stuff required every repetition time

    }
    }
    }
  • Hello Keith,
    Could you please explain this logic, I am sorry I don't think so this code can add a delay.

**Attention** This is a public forum