专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
STM32
有没有STM32F407ZGTIME1互补4路PWM输出程序
2019-07-20 00:34
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
STM32/STM8
6953
2
1779
有没有STM32F407ZGTIME1互补4路PWM输出程序
一组两路PWM互补输出为一组,其余两路为互补输出
并且有死区。
有的可联系我呀。
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
peng1554
1楼-- · 2019-07-20 00:40
精彩回答 2 元偷偷看……
加载中...
JerryYung
2楼-- · 2019-07-20 06:39
使用 TIM 的 TIM_OCMODE_PWM1 或者 TIM_OCMODE_PWM2
再配置对应的极性即可
下面是我用过的,但是不是你的那个需求,应该只需要修改我两处就行了,
{
GPIO_InitTypeDef GPIO_InitStruct;
TIM_MasterConfigTypeDef sMasterConfig;
GPIO_InitStruct.Pin = HVC_LLN_CH1N_PIN|HVC_LLP_CH1_PIN|
HVC_RLN_CH2N_PIN|HVC_RLP_CH2_PIN|
TIM1_BRK_IN_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.Alternate = GPIO_AF2_TIM1;
HAL_GPIO_Init(HVC_GPIO_PORT_E, &GPIO_InitStruct);
SHOCK_RELEASE_TIM_CLK_ENABLE();
// 暂时使用内部晶振
tim1_shock_release.Instance = SHOCK_RELEASE_TIM;
tim1_shock_release.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
tim1_shock_release.Init.Prescaler = SHOCK_RELEASE_TIM_PRESCALER - 1; // 1us
tim1_shock_release.Init.CounterMode = TIM_COUNTERMODE_UP;
tim1_shock_release.Init.Period = SHOCK_RELEASE_TIM_PERIOD - 1;
tim1_shock_release.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
//tim1_shock_release.Init.RepetitionCounter = 3;
HAL_TIM_OC_Init(&tim1_shock_release);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&tim1_shock_release, &sMasterConfig);
tim1_sConfigOC.OCMode = TIM_OCMODE_PWM2; // TIM_OCMODE_ACTIVE
tim1_sConfigOC.Pulse = 5 ;
tim1_sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW; // 需修改
tim1_sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
tim1_sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; // 需修改
tim1_sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
tim1_sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
HAL_TIM_OC_ConfigChannel(&tim1_shock_release, &tim1_sConfigOC, TIM_CHANNEL_1);
HAL_TIM_OC_ConfigChannel(&tim1_shock_release, &tim1_sConfigOC, TIM_CHANNEL_2);
/* Tdts = (1/64)us
* dead time 0xC8 = 1100 1000
* DT = ( 32 + 0x8 )*8*(1/64)us = 5us
*/
tim1_sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_ENABLE;
tim1_sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_ENABLE;
tim1_sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
tim1_sBreakDeadTimeConfig.DeadTime = 0xC8;//0xC8; // dead time keep 5us constant
tim1_sBreakDeadTimeConfig.BreakState = TIM_BREAK_ENABLE;
tim1_sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
tim1_sBreakDeadTimeConfig.BreakFilter = 0;
tim1_sBreakDeadTimeConfig.Break2State = TIM_BREAK2_ENABLE;
tim1_sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
tim1_sBreakDeadTimeConfig.Break2Filter = 0;
tim1_sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_ENABLE;
HAL_TIMEx_ConfigBreakDeadTime(&tim1_shock_release, &tim1_sBreakDeadTimeConfig) ;
HAL_NVIC_SetPriority(SHOCK_RELEASE_TIM_CC_IRQ, 2, 0);
HAL_NVIC_EnableIRQ(SHOCK_RELEASE_TIM_CC_IRQ);
Stop_Shock_Release();
}
加载中...
一周热门
更多
>
相关问题
STM32F4上I2C(在PROTEUS中模拟)调试不通的问题
6 个回答
芯片供应紧张,准备换个MCU,MM32L系列替换STM32L系列的怎么样?
7 个回答
STM32同时使用两个串口进行数据收发时数据丢包的问题
5 个回答
STM32F103串口通信死机问题
4 个回答
STM32WLE5CC连接SX1268在LoRa模式下能与 SX1278互通吗?
2 个回答
STM32开发板免费用活动
7 个回答
stm32 处理 DHT11占用太多时间,大家程序是怎么设计的
8 个回答
分享一个STM32单片机做的离线编程器代码
9 个回答
相关文章
ST公司第一款无线低功耗单片机模块有效提高物联网设计生产效率
0个评论
如何实现对单片机寄存器的访问
0个评论
通过USB用STM32片内自带Bootloader下载程序及注意事项
0个评论
欲练此功必先自宫之STM32汇编启动,放慢是为了更好的前行
0个评论
×
关闭
采纳回答
向帮助了您的网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
STM32
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
关闭
您已邀请
15
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
再配置对应的极性即可
下面是我用过的,但是不是你的那个需求,应该只需要修改我两处就行了,
{
GPIO_InitTypeDef GPIO_InitStruct;
TIM_MasterConfigTypeDef sMasterConfig;
GPIO_InitStruct.Pin = HVC_LLN_CH1N_PIN|HVC_LLP_CH1_PIN|
HVC_RLN_CH2N_PIN|HVC_RLP_CH2_PIN|
TIM1_BRK_IN_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.Alternate = GPIO_AF2_TIM1;
HAL_GPIO_Init(HVC_GPIO_PORT_E, &GPIO_InitStruct);
SHOCK_RELEASE_TIM_CLK_ENABLE();
// 暂时使用内部晶振
tim1_shock_release.Instance = SHOCK_RELEASE_TIM;
tim1_shock_release.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
tim1_shock_release.Init.Prescaler = SHOCK_RELEASE_TIM_PRESCALER - 1; // 1us
tim1_shock_release.Init.CounterMode = TIM_COUNTERMODE_UP;
tim1_shock_release.Init.Period = SHOCK_RELEASE_TIM_PERIOD - 1;
tim1_shock_release.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
//tim1_shock_release.Init.RepetitionCounter = 3;
HAL_TIM_OC_Init(&tim1_shock_release);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&tim1_shock_release, &sMasterConfig);
tim1_sConfigOC.OCMode = TIM_OCMODE_PWM2; // TIM_OCMODE_ACTIVE
tim1_sConfigOC.Pulse = 5 ;
tim1_sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW; // 需修改
tim1_sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
tim1_sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; // 需修改
tim1_sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
tim1_sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
HAL_TIM_OC_ConfigChannel(&tim1_shock_release, &tim1_sConfigOC, TIM_CHANNEL_1);
HAL_TIM_OC_ConfigChannel(&tim1_shock_release, &tim1_sConfigOC, TIM_CHANNEL_2);
/* Tdts = (1/64)us
* dead time 0xC8 = 1100 1000
* DT = ( 32 + 0x8 )*8*(1/64)us = 5us
*/
tim1_sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_ENABLE;
tim1_sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_ENABLE;
tim1_sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
tim1_sBreakDeadTimeConfig.DeadTime = 0xC8;//0xC8; // dead time keep 5us constant
tim1_sBreakDeadTimeConfig.BreakState = TIM_BREAK_ENABLE;
tim1_sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
tim1_sBreakDeadTimeConfig.BreakFilter = 0;
tim1_sBreakDeadTimeConfig.Break2State = TIM_BREAK2_ENABLE;
tim1_sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
tim1_sBreakDeadTimeConfig.Break2Filter = 0;
tim1_sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_ENABLE;
HAL_TIMEx_ConfigBreakDeadTime(&tim1_shock_release, &tim1_sBreakDeadTimeConfig) ;
HAL_NVIC_SetPriority(SHOCK_RELEASE_TIM_CC_IRQ, 2, 0);
HAL_NVIC_EnableIRQ(SHOCK_RELEASE_TIM_CC_IRQ);
Stop_Shock_Release();
}
一周热门 更多>