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: Get time in milliseconds, or configure system ticks

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hi,

I am currently using an application on the MSP432, and am transferring sensor data through UART using the boostxlsensor project.

The standard C headers allow me to get current time, but only in 1 sec. resolution... I would like it in the order of milliseconds. For example, Arduino has the millis() function that is easy to implement, but I have not seen a simple solution in CCS. I've looked through the timer examples, but could not isolate a way to configure tick resolution, or output number of ticks since program start.

If someone could give me a detailed answer, it would be very helpful, and thank you very much!

Best,
Farib

  • Hello Farib,
    Are you using driverLib or TIDrivers?

    Driver Library
    This example continuously counts and provides an interrupt for potentially counting overflows. Each count is 1/32768, but you could change the source to get a desired resolution. In order to get the time you can use the driverLib API, Timer_A_getCounterValue() and and this value to number of overflows that have occurred to determine the time.

    dev.ti.com/.../

    A description of the getCounterValue API can be found here:
    dev.ti.com/.../

    For the TI-RTOS Kernel you should review the Timing services described on page 129:
    dev.ti.com/.../

    Regards,
    Chris
  • Try this:

    It uses driverlib()

    The change from .5 secs to .001 seconds depends on your clock rate.

    	
    /*
     * -------------------------------------------
     *    MSP432 DriverLib - v3_21_00_05 
     * -------------------------------------------
     *
     * --COPYRIGHT--,BSD,BSD
     * Copyright (c) 2016, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    /*******************************************************************************
     * MSP432 SysTick - Blink LED Program
     *
     * Description: This program will use the SysTick module to blink an LED with
     * a one second period. Once setup, the application will go into LPM3
     * mode and only wake up to toggle the GPIO pin.
     *
     * This program runs infinitely until manually halted by the user.
     *
     *                MSP432P401
     *             ------------------
     *         /|\|                  |
     *          | |                  |
     *          --|RST         P1.0  |---> P1.0 LED
     *            |                  |
     *            |                  |
     *            |                  |
     *            |                  |
     *            |                  |
     *
     * Author: Timothy Logan
     *******************************************************************************/
    /* DriverLib Includes */
    #include "driverlib.h"
    
    /* Standard Includes */
    #include <stdint.h>
    
    #include <stdbool.h>
    
    uint32_t millis(void);
    
    volatile uint32_t Tick;
    
    int main(void)
    {
        /* Halting the Watchdog */
        MAP_WDT_A_holdTimer();
    
        /* Configuring GPIO as an output */
        MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
    
        /* Configuring SysTick to trigger at 1500000 (MCLK is 3MHz so this will make
         * it toggle every 0.5s) */
        MAP_SysTick_enableModule();
        MAP_SysTick_setPeriod(1500000);
        MAP_Interrupt_enableSleepOnIsrExit();
        MAP_SysTick_enableInterrupt();
        
        /* Enabling MASTER interrupts */
        MAP_Interrupt_enableMaster();  
    
        while (1)
        {
            MAP_PCM_gotoLPM0();
        }
    }
    
    void SysTick_Handler(void)
    {
        MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
        Tick++;
    }
    
    uint32_t millis(void) { return Tick;}

  • Hi Keith, I tried this code but for some reason millis() always returns 0. Is there a way to use this as a delay? I am sending some commands and I need to finish a function when I get some response or timeout. I am using interrupts to get the response.

    Best regards,
    Alix

**Attention** This is a public forum