while(1){Delay(500);if(CCR4_Val>1){CCR4_Val–;TIM_OCInitStructureTIM_OCMode=TIM_OCMode_PWM1;TIM_O
while (1)
{
Delay(500);
if(CCR4_Val>1)
{
CCR4_Val–;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_
PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR4_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC4Init(TIM3, &TIM_OCInitStructure);
}
else
{
CCR4_Val=990;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR4_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC4Init(TIM3, &TIM_OCInitStructure);
}
}
}
在主程序里改动对比值来改动PWM占空比,上面的程序是不是太笨了,有没有其他办法,请高手点拨
MCU2008 (2008-9-12 10:43:53)
是太笨了…
sunke9 (2008-9-12 10:47:56)
我的用法和你相同
while (1)
{
Delay(0x0000FFFF);
CCR1_Val = ADC_ConvertedValue*4;
CCR2_Val = 16000 – ADC_ConvertedValue*4;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);
}
nomoneyiv (2008-9-12 11:29:08)
在中止里搞!
nomoneyiv (2008-9-12 11:33:22)
比方:
void TIM1_UP_IRQHandler(void)
{
TIM1_SetCompare1(pwm_val_c1);
TIM1_SetCompare3(pwm_val_c3);
TIM1_SetCompare2(pwm_val_c2);
TIM1_ClearITPendingBit(TIM1_IT_Update);
}
然后在主循环里,更改值
pwm_val_c1++;
之类的。
020411 (2008-9-12 15:21:42)
谢谢STM32青菜
yemingxp (2008-9-12 20:02:26)
aleyn (2008-9-15 14:05:15)
此贴终究解惑者是谁?
sw笨笨 (2009-2-24 07:31:01)
while (1)
//无限循环
{
CCR4_Val=CCR4_Val+0x1000;
//变量递加
if(CCR4_Val >= 0xffff) CCR4_Val=0;
//变量归零
TIM_SetCompare4(TIM3, CCR4_Val); //改变长度
Delay(0xffff); //延时
}
selina (2009-12-12 15:28:56)
如同只能在中止内做吧
wslaurora (2010-1-26 15:48:33)
经过tim更新时刻触发DMA传输(循环形式),岂不是更简略?
TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)TIM1_CCR1_Address; //TIM1通道1外设捕获/比较寄存器首地址
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SRC_Buffer; //内存数据缓存首地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //外设作为数据传输的意图
DMA_InitStructure.DMA_BufferSize = 256; //DMA缓存巨细为256
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/fangan/258853.html