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.

MSPM0G3507: Simple Timer example

Part Number: MSPM0G3507
Other Parts Discussed in Thread: SYSCONFIG

I have used the MSP430 for about 18+ years. I have used different MSP430 in teaching Embedded Systems and it has gone well. I am trying to transition the assignments to an M0 to give students exposure to an ARM processor. I am looking for a simple project to load that shows a timer configuration that is equivalent to an MSP430 device. The TI examples are NOT PORTABLE. I am looking for a project that is stand alone and can be open in Code Composer which contains a timers.c file and a interrupts_timers.c in addition to main.c where the timer is 200msec and sets a global variable set to a non zero value. In main, this variable is evaluated and when true will call a function to update a custom display. I have the display working, I just need to configure a timer and understand how to see the interrupt happen.

I am also interested in setting up both SW1 and SW2 to trigger an interrupt which in that interrupt will enable a timer to debounce the switch press. The Debounce time for the switch is a 500ms delay. In the timer interrupt the debounce will be disabled and the switch enabled.

  • Here's something I use. It doesn't do exactly what you're asking, but it illustrates some of the mechanics.

    You need to provide the value of "HZ" (clk.h), which is just the system clock speed. If you haven't fooled with the clock then "#define HZ 32000000UL // 32MHz" will suffice.

    ///
    //      timer.c
    //      Simple timer for pausing in WFI.
    //      No Warranty, No Support. I may not even exist.
    //
    #include <ti/devices/msp/msp.h>
    #include "clk.h"        // HZ
    #include "timer.h"
    #define TIMT        TIMG8
    #define TIMT_ISR    TIMG8_IRQHandler
    #define TIMT_IRQn   TIMG8_INT_IRQn
    volatile uint32_t timer_ms;
    
    void
    TIMT_ISR(void)
    {
        uint32_t mis;
        mis = TIMT->CPU_INT.MIS;                // Enabled interrupts
        TIMT->CPU_INT.ICLR = mis;               // Clear 'em all
        if (mis & GPTIMER_CPU_INT_MIS_Z_SET)
        {
            ++timer_ms;
        }
        return;
    }
    
    void
    timer_init(void)
    {
        //  Power up timer
        TIMT->GPRCM.PWREN = (GPTIMER_PWREN_KEY_UNLOCK_W | GPTIMER_PWREN_ENABLE_ENABLE);
    
        //  CTR: Start at 0, repeat, count up, Advance per CCCTL_01[0].ACOND
        TIMT->COUNTERREGS.CTRCTL = GPTIMER_CTRCTL_CAC_CCCTL0_ACOND|GPTIMER_CTRCTL_CVAE_ZEROVAL|
                                    GPTIMER_CTRCTL_REPEAT_REPEAT_1|GPTIMER_CTRCTL_CM_UP;
    
        //  1kHz from BUSCLK (SYSCLK)
        TIMT->COUNTERREGS.LOAD = (HZ/1000)-1;     // 1kHz period
    
        //  CCR0: advance on clock
        TIMT->COUNTERREGS.CCCTL_01[0] = GPTIMER_CCCTL_01_ACOND_TIMCLK;
    
        //  Enable clock, then timer
        TIMT->CLKSEL = GPTIMER_CLKSEL_BUSCLK_SEL_ENABLE;
        TIMT->COMMONREGS.CCLKCTL = GPTIMER_CCLKCTL_CLKEN_ENABLED;
        TIMT->COUNTERREGS.CTRCTL |= GPTIMER_CTRCTL_EN_ENABLED;
    
        TIMT->CPU_INT.IMASK |= GPTIMER_CPU_INT_IMASK_Z_SET; // Interrupt on counter wrap
        NVIC_ClearPendingIRQ(TIMT_IRQn);
        NVIC_EnableIRQ(TIMT_IRQn);
        return;
    }
    
    void
    timer_wait(uint32_t ms)
    {
        uint32_t start = timer_ms;
    
        while (timer_ms - start < ms)
        {
            __WFI();
        }
        return;
    }
    

  • Hi Jim Carlson

    Please refer to Migration Guide From MSP430 MCUs to MSPM0 MCUs (Rev. A) on the difference between mspm0 and msp430

    Please refer to MSPM0 MCUs Quick Reference Guide (Rev. A) on quick start using SDK and sysconfig

    Please use mspm0 SDK https://www.ti.com/tool/MSPM0-SDK on the software ecosystem on mspm0

    Thanks