1007 views|0 replies

6063

Posts

4

Resources
The OP
 

【MSPM0L1306 LaunchPad】 8 Timer timing function experiment [Copy link]

 
This post was last edited by damiaa on 2023-10-29 14:23

【MSPM0L1306 LaunchPad】 8 Timer timing function experiment

【MSPM0L1306 LaunchPad】 1 Unboxing + Environment Setting + Lighting

【MSPM0L1306 LaunchPad】 2 GUI Composer GUI Play Board

【MSPM0L1306 LaunchPad】 3 Ti cloud development environment

【MSPM0L1306 LaunchPad】 4 Use MDK environment to light up

【MSPM0L1306 LaunchPad】 5. Use ccs theia to light the environment

【MSPM0L1306 LaunchPad】 6 Temperature sensor experiment

MSPM0L1306 LaunchPad】 7 UART Basic Experiment (1) After

1, File ==》Create New Project to start
Select the board as MSPM0L1306 LaunchPad, the wrong operating system, and the compiler as ccs -Ti Arm clang. Select a DriverLib library empty_msp0l1306 Empty start-up project using DriverLib. and save


2, SysConfig configure led GPIO and save.

3. The system will generate GPIO initialization code in ti_msp_dl_config.h and ti_msp_dl_config.c.

4. In the main program, you only need to call SYS_CFG_DL_init() and the function that controls gpio

5. SysConfig configure tim as follows and save.

6. The system will generate the initialization code for the Tim initialization interrupt in ti_msp_dl_config.h and ti_msp_dl_config.c.

7. Just call it in the main program. The program code is as follows

Generated code ti_msp_dl_config.h

#ifndef ti_msp_dl_config_h
#define ti_msp_dl_config_h

#define CONFIG_MSPM0L130X

#if defined(__ti_version__) || defined(__TI_COMPILER_VERSION__)
#define SYSCONFIG_WEAK __attribute__((weak))
#elif defined(__IAR_SYSTEMS_ICC__)
#define SYSCONFIG_WEAK __weak
#elif defined(__GNUC__)
#define SYSCONFIG_WEAK __attribute__((weak))
#endif

#include <ti/devices/msp/msp.h>
#include <ti/driverlib/driverlib.h>
#include <ti/driverlib/m0p/dl_core.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 *  ======== SYSCFG_DL_init ========
 *  Perform all required MSP DL initialization
 *
 *  This function should be called once at a point before any use of
 *  MSP DL.
 */


/* clang-format off */

#define POWER_STARTUP_DELAY                                                (16)


#define CPUCLK_FREQ                                                     32000000



/* Defines for TIMER_0 */
#define TIMER_0_INST                                                     (TIMG0)
#define TIMER_0_INST_IRQHandler                                 TIMG0_IRQHandler
#define TIMER_0_INST_INT_IRQN                                   (TIMG0_INT_IRQn)
#define TIMER_0_INST_LOAD_VALUE                                          (1023U)




/* Port definition for Pin Group GPIO_GRP_0 */
#define GPIO_GRP_0_PORT                                                  (GPIOA)

/* Defines for PIN_0: GPIOA.0 with pinCMx 1 on package pin 1 */
#define GPIO_GRP_0_PIN_0_PIN                                     (DL_GPIO_PIN_0)
#define GPIO_GRP_0_PIN_0_IOMUX                                    (IOMUX_PINCM1)

/* clang-format on */

void SYSCFG_DL_init(void);
void SYSCFG_DL_initPower(void);
void SYSCFG_DL_GPIO_init(void);
void SYSCFG_DL_SYSCTL_init(void);
void SYSCFG_DL_TIMER_0_init(void);



#ifdef __cplusplus
}
#endif

#endif /* ti_msp_dl_config_h */

Generated code ti_msp_dl_config.c

#include "ti_msp_dl_config.h"

/*
 *  ======== SYSCFG_DL_init ========
 *  Perform any initialization needed before using any board APIs
 */
SYSCONFIG_WEAK void SYSCFG_DL_init(void)
{
    SYSCFG_DL_initPower();
    SYSCFG_DL_GPIO_init();
    /* Module-Specific Initializations*/
    SYSCFG_DL_SYSCTL_init();
    SYSCFG_DL_TIMER_0_init();
}

SYSCONFIG_WEAK void SYSCFG_DL_initPower(void)
{
    DL_GPIO_reset(GPIOA);
    DL_TimerG_reset(TIMER_0_INST);

    DL_GPIO_enablePower(GPIOA);
    DL_TimerG_enablePower(TIMER_0_INST);
    delay_cycles(POWER_STARTUP_DELAY);
}

SYSCONFIG_WEAK void SYSCFG_DL_GPIO_init(void)
{

    DL_GPIO_initDigitalOutput(GPIO_GRP_0_PIN_0_IOMUX);

    DL_GPIO_clearPins(GPIO_GRP_0_PORT, GPIO_GRP_0_PIN_0_PIN);
    DL_GPIO_enableOutput(GPIO_GRP_0_PORT, GPIO_GRP_0_PIN_0_PIN);

}


SYSCONFIG_WEAK void SYSCFG_DL_SYSCTL_init(void)
{
    DL_SYSCTL_setSYSOSCFreq(DL_SYSCTL_SYSOSC_FREQ_BASE);
    DL_SYSCTL_setMCLKDivider(DL_SYSCTL_MCLK_DIVIDER_DISABLE);

	//Low Power Mode is configured to be SLEEP0
    DL_SYSCTL_setBORThreshold(DL_SYSCTL_BOR_THRESHOLD_LEVEL_0);

}



/*
 * Timer clock configuration to be sourced by LFCLK /  (4096 Hz)
 * timerClkFreq = (timerClkSrc / (timerClkDivRatio * (timerClkPrescale + 1)))
 *   1024 Hz = 4096 Hz / (8 * (3 + 1))
 */
static const DL_TimerG_ClockConfig gTIMER_0ClockConfig = {
    .clockSel    = DL_TIMER_CLOCK_LFCLK,
    .divideRatio = DL_TIMER_CLOCK_DIVIDE_8,
    .prescale    = 3U,
};

/*
 * Timer load value (where the counter starts from) is calculated as (timerPeriod * timerClockFreq) - 1
 * TIMER_0_INST_LOAD_VALUE = (1 * 1024 Hz) - 1
 */
static const DL_TimerG_TimerConfig gTIMER_0TimerConfig = {
    .period     = TIMER_0_INST_LOAD_VALUE,
    .timerMode  = DL_TIMER_TIMER_MODE_PERIODIC,
    .startTimer = DL_TIMER_START,
};

SYSCONFIG_WEAK void SYSCFG_DL_TIMER_0_init(void) {

    DL_TimerG_setClockConfig(TIMER_0_INST,
        (DL_TimerG_ClockConfig *) &gTIMER_0ClockConfig);

    DL_TimerG_initTimerMode(TIMER_0_INST,
        (DL_TimerG_TimerConfig *) &gTIMER_0TimerConfig);
    DL_TimerG_enableInterrupt(TIMER_0_INST , DL_TIMERG_INTERRUPT_ZERO_EVENT);
    DL_TimerG_enableClock(TIMER_0_INST);
}

Main program code empty.c

#include "ti_msp_dl_config.h"

int main(void)
{
    SYSCFG_DL_init();
    NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN);
    DL_TimerG_startCounter(TIMER_0_INST);
    
    while (1) {
        delay_cycles(10000000);
 
    }
}
#define TIMER_100_MILLISECONDS_TICKS (99)
static uint32_t count = TIMER_100_MILLISECONDS_TICKS;
uint8_t inc_dec_flag=1;
void TIMER_0_INST_IRQHandler(void)
{
     if(count >2000) inc_dec_flag=0;
     if(count <100)  inc_dec_flag=1;
     if(inc_dec_flag ==0){
        count -=TIMER_100_MILLISECONDS_TICKS;
     }
     else {
        count +=TIMER_100_MILLISECONDS_TICKS;
     }
    switch (DL_TimerG_getPendingInterrupt(TIMER_0_INST)) {
        case DL_TIMER_IIDX_ZERO:
           
            DL_TimerG_stopCounter(TIMER_0_INST);
            DL_Timer_setLoadValue(TIMER_0_INST, count); 
            DL_TimerG_startCounter(TIMER_0_INST);
            DL_GPIO_togglePins(GPIO_GRP_0_PORT, GPIO_GRP_0_PIN_0_PIN);
            break;
        default:
            break;
    }   
}

8. Compile and run. Observe the red light changes from fast to slow and then from slow to fast.

80

That's the experiment.

Thanks

This post is from MSPM0 MCU
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list