2386 views|2 replies

1237

Posts

66

Resources
The OP
 

【MSPM0L1306 LaunchPad】8. PWM breathing light [Copy link]

 This post was last edited by dql2016 on 2023-11-5 22:02

Breathing light is a common design of many products, especially low-end products without LCD screens that use LED to display the working status.

It is very simple to configure PWM output using CCS. First, select the example:

Check out the demo


The configuration of PWM mainly involves the setting of timer clock, frequency division coefficient and load value:

The output pins are connected to LEDs:

The program is very simple and easy to understand:


#include "ti_msp_dl_config.h"

int pwm_count = 1800; // initial ccr count based on 10% duty cycle
int dc = 10;          // initialized to 10 % duty cycle
int mode = 1; // 1 = up (will indicate you need to increase dc), 0 = down (will
              // decrease dc)

int main(void) {
  SYSCFG_DL_init();

  NVIC_EnableIRQ(PWM_0_INST_INT_IRQN);
  DL_TimerG_startCounter(PWM_0_INST);

  while (1) {
    __WFI();
  }
}

void PWM_0_INST_IRQHandler(void) {
  switch (DL_TimerG_getPendingInterrupt(PWM_0_INST)) {
  case DL_TIMER_IIDX_LOAD:
    if (dc <= 10) {
      mode = 1;
    } // if reached lowest dc (10%), increase dc
    else if (dc >= 90) {
      mode = 0;
    } // if reached highest dc (90%), decrease dc
    if (mode) {
      pwm_count -= 20;
      dc += 1;
    } // up
    if (!mode) {
      pwm_count += 20;
      dc -= 1;
    } // down
    DL_TimerG_setCaptureCompareValue(PWM_0_INST, pwm_count,
                                     DL_TIMER_CC_1_INDEX); // update ccr1 value
    break;
  default:
    break;
  }
}

Effect:

This post is from MSPM0 MCU

Latest reply

PWM does not need to enable interrupts, after all, the frequency of PWM is generally relatively high   Details Published on 2023-11-6 10:41
 
 

6555

Posts

0

Resources
2
 

The pwm breathing light is a test item, and it is done well.

This post is from MSPM0 MCU
 
 
 

6027

Posts

6

Resources
3
 

PWM does not need to enable interrupts, after all, the frequency of PWM is generally relatively high

This post is from MSPM0 MCU
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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