最近遇到一個(gè)奇怪的問(wèn)題:
如果用一個(gè)程序單獨(dú)用定時(shí)器內(nèi)中斷每隔1s點(diǎn)亮LED,此時(shí)LED亮度是正常的,單獨(dú)的呼吸燈程序LED亮度也正常
后來(lái)另外寫(xiě)了一個(gè)程序?qū)⑸厦娑〞r(shí)器內(nèi)部中斷每隔1s點(diǎn)亮LED的功能跟PWM呼吸燈的程序合并在一起后呼吸燈亮度就變的很暗了,但是呼吸燈是能夠正常呼吸的
以上是什么原因?qū)е碌?
程序如下:
#include "stm32f10x.h" // Device header
#include "Led.h"
#include "Timer.h"
#include "PWM.h"
#include "Delay.h"
#include "SysTick.h"
uint16_t i;
int main(void)
{
// SysTick_Init(72);
Timer_Init();
LED_Init();
PWM_Init(100,720); //1000Hz
while(1)
{
for(i=0; i<=100; i++)
{
PWM_SetCompare1(i);
PWM_SetCompare2(i);
Delay_ms(10);
}
for(i=0; i<=100; i++)
{
PWM_SetCompare1(100-i);
PWM_SetCompare2(100-i);
Delay_ms(10);
}
}
}
#include "stm32f10x.h" // Device header
void PWM_Init(uint16_t Per, uint16_t Psc)
{
//íaéè2?êy?á11ì?
GPIO_InitTypeDef GPIO_InitStruct;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct;
//íaéèê±?ó?a??
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
//??ó3é?òy??PA6μ?PC6
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE);
//GPIO?á11ì?2?êyéè??
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStruct);
//????ê±?ùμ¥?aμ?ê±?ó?′
TIM_InternalClockConfig(TIM3);
//?¨ê±?÷ê±?ù?á11ì?2?êyéè??
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_Period = Per-1; //ARR ?¤??×°???μ
TIM_TimeBaseInitStruct.TIM_Prescaler = Psc-1; //PSC ?¤·??μ?μêy
TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseStructInit(&TIM_TimeBaseInitStruct);
//ê?3?±è???á11ì?2?êyéè??
TIM_OCStructInit(&TIM_OCInitStruct);
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStruct.TIM_Pulse = 0; //CCR ??êy?÷
TIM_OC1Init(TIM3, &TIM_OCInitStruct);
TIM_OC2Init(TIM3, &TIM_OCInitStruct);
// TIM_ARRPreloadConfig(TIM3, ENABLE);
// TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
//ê1?ü?¨ê±?÷
TIM_Cmd(TIM3, ENABLE);
}
//éè??CCR,??±?PWM????±è
void PWM_SetCompare1(uint16_t Compare)
{
TIM_SetCompare1(TIM3, Compare);
}
void PWM_SetCompare2(uint16_t Compare)
{
TIM_SetCompare2(TIM3, Compare);
}
//éè???¤·??μ?μ,??±?PWM?μ?ê
void PWM_Prescaler(uint16_t Prescaler)
{
TIM_PrescalerConfig(TIM3, Prescaler, TIM_PSCReloadMode_Immediate);
}
審核編輯 黃宇
-
led
+關(guān)注
關(guān)注
242文章
23277瀏覽量
660844 -
PWM
+關(guān)注
關(guān)注
114文章
5186瀏覽量
213916 -
STM32
+關(guān)注
關(guān)注
2270文章
10900瀏覽量
355980 -
編程
+關(guān)注
關(guān)注
88文章
3615瀏覽量
93731
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論