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.

MSPM0L1105: MSPM0L1105 LED Fading

Part Number: MSPM0L1105
Other Parts Discussed in Thread: MSPM0L1306, MSPM0G3507

Tool/software:

Hi Forum,

Need you support in One task.

I want to breathe my LED 0 to 100% I am trying timx_timer_mode_pwm_edge_sleep example but not going anywhere. Then I tried with timx_timer_mode_periodic_standby_LP_MSPM0L1306_nortos_ticlang this example also but need your help.

Please suggest me how do I approach this task.

  • What is not happening as you expect? What does the example do?

    Is this the LED on the Launchpad?

  • LED is not on launchpad. We have a PCBA with LED at PA27, PA16,PA24. I want to glow this led from 100% to 0%. Like fading the led from 100% glow to 0%. How do I approach this,.

  • Here is the code from the MSPM0G3507 adctopwm example. IT should get you started.

    #define  ADC_MINIMUM_VALUE 500  
    
    #include "ti_msp_dl_config.h"
    
    volatile bool gCheckADC;
    volatile uint32_t gCCV;
    volatile uint16_t gAdcResult;
    
    int main(void) {
    
        SYSCFG_DL_init();
        NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN);
    
        DL_Timer_setCaptCompUpdateMethod(PWM_0_INST, GPTIMER_CCCTL_01_CCUPD_ZERO_EVT, DL_TIMER_CC_0_INDEX);
    
        /* Start our ADC conversion and PWM Timers */
        DL_Timer_startCounter(TIMER_0_INST);
        DL_Timer_startCounter(PWM_0_INST);
    
        gCheckADC = false;
    
        while (1) 
        {
        __WFI();
    
        if (gCheckADC) {
        
            gCheckADC = false;
            gAdcResult = DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0);
            /* Check if the gAdcResult is above the minmum threshold */
                if (gAdcResult > ADC_MINIMUM_VALUE)
                {
                    /* Start counter in case it was previously stopped. */
                    DL_Timer_startCounter(PWM_0_INST);
    
                    /* Do necessary ADC-to-PWM scaling here: */
    
                    /* Here we just map the ADC Result from 0 to 100% of the Load Value */
                    gCCV = DL_Timer_getLoadValue(PWM_0_INST)*gAdcResult/4096;
                    /* CC Value will update on the next zero event */
                    DL_TimerG_setCaptureCompareValue(PWM_0_INST, DL_Timer_getLoadValue(PWM_0_INST)-gCCV, DL_TIMER_CC_0_INDEX);
                }
                else 
                {
                    /* If gAdcResult is not above minmum value then disable timer */
                    DL_TimerG_stopCounter(PWM_0_INST);
                }
            }
        }
    }
    
    void ADC12_0_INST_IRQHandler(void) {
      switch (DL_ADC12_getPendingInterrupt(ADC12_0_INST)) {
      case DL_ADC12_IIDX_MEM0_RESULT_LOADED:
        gCheckADC = true;
        break;
      default:
        break;
      }
      DL_ADC12_enableConversions(ADC12_0_INST);
    }

  • Thank Keith for the code.

    All the pins of MCu are occupied and has no privilege for ADC pin. Is this possible any other way?

  • Just put in a fake value for the ADC value gADCResult that changes over time to see the PWM operate. I just put in this example to show you how to change the PWM duty cycle.

    You can get rid of all the ADC calls.

    But note that without the ADC, there is no interrupt. Remove the _WFI() macro!

  • Hi,

    Do you want to make the breathed LED?

    Please just use timer to change the PWM(output for LED)'s cc value(use this code line: DL_TimerG_setCaptureCompareValue(PWM_0_INST, 5000, DL_TIMER_CC_0_INDEX);)

    Regards,

    Zoey