专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
怎样利用STM32L476的TIM1输出脉冲??
2019-03-23 15:23
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
STM32/STM8
8332
10
1540
各位,我想用单独的TIM1通过PA7(TIM1_CH1N)输出指定个数的脉冲。参考了很多例程,网上的,还有STM32CUBE库自带的例程。都没有输出,只是CNT计数器可以计数。请大家指点指点。ST的技术支持也不是狠好。
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
10条回答
Li_Lei
2019-03-25 06:14
void MTIM8_Init(void) {
LL_TIM_InitTypeDef TIM_InitStruct;
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct;
// LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct;
LL_GPIO_InitTypeDef GPIO_InitStruct;
/* Tim8 PC PA 时钟 */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM8);
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/* TIM8 interrupt Init */
NVIC_SetPriority(TIM8_UP_TIM13_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(TIM8_UP_TIM13_IRQn);
TIM_InitStruct.Prescaler = 0;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_CENTER_UP;
TIM_InitStruct.Autoreload = 16384-1;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
TIM_InitStruct.RepetitionCounter = 0;
LL_TIM_Init(TIM8, &TIM_InitStruct);
LL_TIM_SetClockSource(TIM8, LL_TIM_CLOCKSOURCE_INTERNAL);
/*
LL_TIM_OC_EnablePreload(TIM8, LL_TIM_CHANNEL_CH1);
LL_TIM_OC_EnablePreload(TIM8, LL_TIM_CHANNEL_CH2);
LL_TIM_OC_EnablePreload(TIM8, LL_TIM_CHANNEL_CH3);
LL_TIM_OC_EnablePreload(TIM8, LL_TIM_CHANNEL_CH4);*/
LL_TIM_EnableARRPreload(TIM8);
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_ENABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.CompareValue = 0;
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW;
TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
LL_TIM_OC_Init(TIM8, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
LL_TIM_OC_Init(TIM8, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct);
LL_TIM_OC_Init(TIM8, LL_TIM_CHANNEL_CH3, &TIM_OC_InitStruct);
LL_TIM_OC_Init(TIM8, LL_TIM_CHANNEL_CH4, &TIM_OC_InitStruct);
LL_TIM_OC_EnableFast(TIM8, LL_TIM_CHANNEL_CH1);
LL_TIM_OC_EnableFast(TIM8, LL_TIM_CHANNEL_CH2);
LL_TIM_OC_EnableFast(TIM8, LL_TIM_CHANNEL_CH3);
LL_TIM_OC_EnableFast(TIM8, LL_TIM_CHANNEL_CH4);
LL_TIM_SetTriggerOutput(TIM8, LL_TIM_TRGO_RESET);
LL_TIM_DisableMasterSlaveMode(TIM8);
/**TIM8 GPIO Configuration
PC6 ------> TIM8_CH1
PC7 ------> TIM8_CH2
PC8 ------> TIM8_CH3
PC9 ------> TIM8_CH4
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7|LL_GPIO_PIN_8|LL_GPIO_PIN_9;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;//LL_GPIO_OUTPUT_OPENDRAIN;//
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_3;
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
LL_TIM_EnableAllOutputs(TIM8);
LL_TIM_EnableCounter(TIM8);
加载中...
查看其它10个回答
一周热门
更多
>
相关问题
相关文章
嵌入式编译生成的HEX文件和BIN文件内容详解
0个评论
ST公司第一款无线低功耗单片机模块有效提高物联网设计生产效率
0个评论
单片机中把部分Flash虚拟成Eeprom使用时,如何延长使用寿命
0个评论
如何实现对单片机寄存器的访问
0个评论
通过USB用STM32片内自带Bootloader下载程序及注意事项
0个评论
欲练此功必先自宫之STM32汇编启动,放慢是为了更好的前行
0个评论
敢问路在何方,STM32迈出的第一步,却注定了它非凡的一生
0个评论
年工作时间真的就等于3年工作经验?也许你就不配
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
LL_TIM_InitTypeDef TIM_InitStruct;
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct;
// LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct;
LL_GPIO_InitTypeDef GPIO_InitStruct;
/* Tim8 PC PA 时钟 */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM8);
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/* TIM8 interrupt Init */
NVIC_SetPriority(TIM8_UP_TIM13_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(TIM8_UP_TIM13_IRQn);
TIM_InitStruct.Prescaler = 0;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_CENTER_UP;
TIM_InitStruct.Autoreload = 16384-1;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
TIM_InitStruct.RepetitionCounter = 0;
LL_TIM_Init(TIM8, &TIM_InitStruct);
LL_TIM_SetClockSource(TIM8, LL_TIM_CLOCKSOURCE_INTERNAL);
/*
LL_TIM_OC_EnablePreload(TIM8, LL_TIM_CHANNEL_CH1);
LL_TIM_OC_EnablePreload(TIM8, LL_TIM_CHANNEL_CH2);
LL_TIM_OC_EnablePreload(TIM8, LL_TIM_CHANNEL_CH3);
LL_TIM_OC_EnablePreload(TIM8, LL_TIM_CHANNEL_CH4);*/
LL_TIM_EnableARRPreload(TIM8);
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_ENABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.CompareValue = 0;
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW;
TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
LL_TIM_OC_Init(TIM8, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
LL_TIM_OC_Init(TIM8, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct);
LL_TIM_OC_Init(TIM8, LL_TIM_CHANNEL_CH3, &TIM_OC_InitStruct);
LL_TIM_OC_Init(TIM8, LL_TIM_CHANNEL_CH4, &TIM_OC_InitStruct);
LL_TIM_OC_EnableFast(TIM8, LL_TIM_CHANNEL_CH1);
LL_TIM_OC_EnableFast(TIM8, LL_TIM_CHANNEL_CH2);
LL_TIM_OC_EnableFast(TIM8, LL_TIM_CHANNEL_CH3);
LL_TIM_OC_EnableFast(TIM8, LL_TIM_CHANNEL_CH4);
LL_TIM_SetTriggerOutput(TIM8, LL_TIM_TRGO_RESET);
LL_TIM_DisableMasterSlaveMode(TIM8);
/**TIM8 GPIO Configuration
PC6 ------> TIM8_CH1
PC7 ------> TIM8_CH2
PC8 ------> TIM8_CH3
PC9 ------> TIM8_CH4
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7|LL_GPIO_PIN_8|LL_GPIO_PIN_9;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;//LL_GPIO_OUTPUT_OPENDRAIN;//
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_3;
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
LL_TIM_EnableAllOutputs(TIM8);
LL_TIM_EnableCounter(TIM8);
一周热门 更多>