完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include "timer.h"
#include "STM32f10x.h" extern u16 ccr1; void TIM3_IRQHandler(void) //TIM3ÖÐ¶Ï { if (TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET) //¼ì²éÖ¸¶¨µÄTIMÖжϷ¢ÉúÓë·ñ:TIM ÖжÏÔ´ { TIM_ClearITPendingBit(TIM3, TIM_IT_CC1 ); //Çå³ýTIMxµÄÖжϴý´¦Àíλ:TIM ÖжÏÔ´ if(ccr1<5000) { ccr1=ccr1+500; } else ccr1=999; TIM_SetCompare1(TIM3,ccr1); } } void TIM13_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE); /* TIM3 and TIM4 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); TIM_TimeBaseStructure.TIM_Period = 5559; TIM_TimeBaseStructure.TIM_Prescaler =0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_Pulse = 499; TIM_ClearFlag(TIM3, TIM_FLAG_CC1); TIM_ITConfig(TIM3,TIM_IT_CC1,ENABLE);//ÖжÏʹÄÜ TIM_OC1Init(TIM3, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable); /* Slave Mode selection: TIM3 */ TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Trigger); TIM_SelectInputTrigger(TIM3, TIM_TS_ITR0); TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 255; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 4; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); /* Channel 1 Configuration in PWM mode */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; TIM_OCInitStructure.TIM_Pulse = 127; TIM_OC1Init(TIM1, &TIM_OCInitStructure); GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE); TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update); /* Select the Master Slave Mode */ TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable); /* TIM1 counter enable */ TIM_Cmd(TIM1, ENABLE); /* TIM enable counter */ TIM_Cmd(TIM3, ENABLE); /* Main Output Enable */ TIM_CtrlPWMOutputs(TIM1, ENABLE); } void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOE |RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); } void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;//ʹÄÜÖÐ¶Ï NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); } |
|
相关推荐
7个回答
|
|
|
|
|
|
试过其它pwm模式,都是无法进入中断,无法更改比较值和溢出值,即arr和ccr值,在slave模式下是不是还要做一些其它命令设定或是修改,忘大佬解答
|
|
|
|
单步运行下看寄存器的值是否正常,计数器到后状态位是否有变化
|
|
|
|
|
|
|
|
的确,不能中断,就要看中断是否打开,如果被mark掉,是不会进入中断的。
|
|
|
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2105 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1941 浏览 3 评论
4537 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2084 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2599 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 10:16 , Processed in 0.757856 second(s), Total 85, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号