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.
工具与软件:
尊敬的论坛:
都需要您在一个任务中提供支持。
我想为 LED 0至100%呼吸、我尝试 timx_timer_mode_pwm_edge_sleep 示例、但没有出现任何情况。 然后、我尝试了 timx_timer_mode_periodic_standby_LP_MSPM0L1306_nortos_ticlang 这个示例、但也需要您的帮助。
请建议我如何处理此任务。
什么不是你所期望的? 示例的作用是什么?
这是 Launchpad 上的 LED 吗?
launchpad 上未指示灯。 我们的 PCBA 的 LED 位于 PA27、PA16、PA24。 我想把这个 LED 从100%点亮到0%。 比如让 LED 从100%的光褪色到0%的光。 我该如何处理它。
以下是来自 MSPM0G3507 adctopwm 示例的代码。 它应该可以让您快速入门。
#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); }
感谢 Keith 编写代码。
MCU 的所有引脚均被占用、对 ADC 引脚没有特权。 这可能还有其他方法吗?
只需为 ADC 值 gADCResult 输入一个假值、该值会随着时间的推移而变化、以查看 PWM 运行。 我刚才输入这个示例、以便向您展示如何更改 PWM 占空比。
可以摆脱所有 ADC 调用。
但请注意、如果没有 ADC、就没有中断。 删除_WFI()宏!
您好!
你 想让呼吸的 LED 吗?
请仅使用计时器来更改 PWM (LED 的输出)的 cc 值(使用以下代码行:DL_TimerG_setCaptureCompareValue (PWM_0_INST、5000、DL_TIMER_CC_0_INDEX);)
此致、
Zoey