引用: zhaojun_xf 发表于 2015-3-11 11:30
__enable_interrupt(); 打开总中断
引用: 幽灵公主 发表于 2015-3-14 08:52
我用TIM1也不能输出波形:
#include "pwm_output.h"
static void TIM1_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9| GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // 复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
static void TIM1_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
u16 CCR1_Val = 50;
u16 CCR2_Val = 50;
u16 CCR3_Val = 50;
u16 CCR4_Val = 50;
TIM_TimeBaseStructure.TIM_Period = 999; //当定时器从0计数到999,即为1000次,为一个定时周期
TIM_TimeBaseStructure.TIM_Prescaler = 71;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ; //设置时钟分频系数:不分频
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //配置为PWM模式1
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
// TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR1_Val; //设置跳变值,当计数器计数到这个值时,电平发生跳变
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //当定时器计数值小于CCR1_Val时为高电平
TIM_OC1Init(TIM1, &TIM_OCInitStructure); //使能通道1
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR2_Val; //设置通道2的电平跳变值,输出另外一个占空比的PWM
TIM_OC2Init(TIM1, &TIM_OCInitStructure); //使能通道2
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR3_Val; //设置通道3的电平跳变值,输出另外一个占空比的PWM
TIM_OC3Init(TIM1, &TIM_OCInitStructure); //使能通道3
TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR4_Val; //设置通道4的电平跳变值,输出另外一个占空比的PWM
TIM_OC4Init(TIM1, &TIM_OCInitStructure); //使能通道4
TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM1, ENABLE); // 使能TIM1重载寄存器ARR
TIM_Cmd(TIM1, ENABLE); //使能定时器1
}
void TIM1_PWM_Init(void)
{
TIM1_GPIO_Config();
TIM1_Mode_Config();
}
只知道TIM1的时钟和TIM2的时钟不一样
引用: michael_llh 发表于 2015-3-14 12:32
我的问题已经解决了。是端口复用的问题。你那边也可以查下是否存在端口复用,顺便把定时器的初始化放在所有的初始化之后试试看
引用: 幽灵公主 发表于 2015-3-14 22:45
我刚发现TIM1要打开 TIM_CtrlPWMOutputs(TIM1,ENABLE);//使能TIM1外设的主输出
现在也能输出PWM了,谢谢
引用: michael_llh 发表于 2015-3-14 23:02
恩,互帮互助哈!
引用: 幽灵公主 发表于 2015-3-16 21:54
你有用过STM32显示BMP图片没?
使用STM32的例程,可以显示图片,把图片换成其它BMP图片,修改Lcd_show_bmp(0, 0,"/tupian.bmp");,并把图片放到SD卡,液晶不能显示图片,那么图片的路径是如何设置的?
void Lcd_show_bmp(unsigned short int x, unsigned short int y,unsigned char *pic_name)
{
int i, j, k;
int width, height, l_width;
BYTE red,green,blue;
BITMAPFILEHEADER bitHead;
BITMAPINFOHEADER bitInfoHead;
WORD fileType;
unsigned int read_num;
unsigned char tmp_name[20];
sprintf((char*)tmp_name,"0:%s",pic_name);
f_mount(0, &bmpfs[0]);
BMP_DEBUG_PRINTF("file mount ok \r\n");
bmpres = f_open( &bmpfsrc , (char *)tmp_name, FA_OPEN_EXISTING | FA_READ);
if(bmpres == FR_OK)
{
BMP_DEBUG_PRINTF("Open file success\r\n");
f_read(&bmpfsrc,&fileType,sizeof(WORD),&read_num);
if(fileType != 0x4d42)
{
BMP_DEBUG_PRINTF("file is not .bmp file!\r\n");
return;
}
else
{
BMP_DEBUG_PRINTF("Ok this is .bmp file\r\n");
}
f_read(&bmpfsrc,&bitHead,sizeof(tagBITMAPFILEHEADER),&read_num);
showBmpHead(&bitHead);
f_read(&bmpfsrc,&bitInfoHead,sizeof(BITMAPINFOHEADER),&read_num);
showBmpInforHead(&bitInfoHead);
}
else
{
BMP_DEBUG_PRINTF("file open fail!\r\n");
return;
}
width = bitInfoHead.biWidth;
height = bitInfoHead.biHeight;
l_width = WIDTHBYTES(width* bitInfoHead.biBitCount);
if(l_width > 960)
{
BMP_DEBUG_PRINTF("\n SORRY, PIC IS TOO BIG (
引用: michael_llh 发表于 2015-3-14 12:32
我的问题已经解决了。是端口复用的问题。你那边也可以查下是否存在端口复用,顺便把定时器的初始化放在所有 ...
引用: jinag2018 发表于 2018-4-13 11:31
楼主您好,我也遇到了相同的问题,SYM32的TIM8_CH1 不管怎么样就是不输出PWM波,同样是高级定时器的TIM1_ ...
引用: huo_hu 发表于 2018-4-13 12:00
你先看CNT有没有变化,再看通道有数值没有,再看管脚有输出没,再验频率和占空比
引用: jinag2018 发表于 2018-4-13 13:33
谢谢您的解答,关于您说的CNT,是中断定时器计数值吧。我在这里并没有用到中断呢