对于上升计数,Update刚刚发生时,CNT 对于下降计数,Update刚刚发生时,CNT>CCRx
STM32 高级定时器 6-step PWM generation
6-step PWM generation
When complementary outputs are used on a channel, preload bits are available on the OCxM, CCxE and CCxNE bits. The preload bits are transferred to the shadow bits at the COM commutation event. Thus you can program in advance the configuration for the next step and change the configuration of all the channels at the same time. COM can be generated by software by setting the COM bit in the TIMx_EGR register or by hardware (on TRGI rising edge).
A flag is set when the COM event occurs (COMIF bit in the TIMx_SR register), which can generate an interrupt (if the COMIE bit is set in the TIMx_DIER register) or a DMA request(if the COMDE bit is set in the TIMx_DIER register).
@file TIM/6Steps/main.c
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
uint16_t CCR1_Val = 32767;
uint16_t CCR2_Val = 24575;
uint16_t CCR3_Val = 16383;
uint16_t CCR4_Val = 8191;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void SysTick_Configuration(void);
void NVIC_Configuration(void);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
/* System Clocks Configuration */
RCC_Configuration();
/* NVIC Configuration */
NVIC_Configuration();
/* GPIO Configuration */
GPIO_Configuration();
/* SysTick Configuration */
SysTick_Configuration();
/*-----------------------------------------------------------------------------
The STM32F10x TIM1 peripheral offers the possibility to program in advance the
configuration for the next TIM1 outputs behaviour (step) and change the configuration of all the channels at the same time. This operation is possible when the COM (commutation) event is used.
The COM event can be generated by software by setting the COM bit in the TIM1_EGR register or by hardware (on TRC rising edge).
In this example, a software COM event is generated each 100 ms: using the Systick interrupt.
The TIM1 is configured in Timing Mode, each time a COM event occurs,
a new TIM1 configuration will be set in advance.
The following Table describes the TIM1 Channels states:
-----------------------------------------------
| Step1 | Step2 | Step3 | Step4 | Step5 | Step6 |
----------------------------------------------------------
|Channel1 | 1 | 0 | 0 | 0 | 0 | 1 |
----------------------------------------------------------
|Channel1N | 0 | 0 | 1 | 1 | 0 | 0 |
----------------------------------------------------------
|Channel2 | 0 | 0 | 0 | 1 | 1 | 0 |
----------------------------------------------------------
|Channel2N | 1 | 1 | 0 | 0 | 0 | 0 |
----------------------------------------------------------
|Channel3 | 0 | 1 | 1 | 0 | 0 | 0 |
----------------------------------------------------------
|Channel3N | 0 | 0 | 0 | 0 | 1 | 1 |
----------------------------------------------------------
-----------------------------------------------------------------------------*/
/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
//Specifies the period value to be loaded into the active
//Auto-Reload Register at the next update event.
TIM_TimeBaseStructure.TIM_Period = 4095;
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //Specifies the clock division.
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Channel 1, 2,3 and 4 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
//Specifies the pulse value to be loaded into the Capture Compare Register.
TIM_OCInitStructure.TIM_Pulse = 2047;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 1023;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 511;
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; //运行模式下“关闭状态”选择 (Off-state selection for Run mode)
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
TIM_BDTRInitStructure.TIM_DeadTime = 1;
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High; //刹车输入极性 (Break polarity)
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;//1:MOE(主输出使能)能被软件置’1’或在下一个更新事件被自动置’1’(如果刹车输入无效)。
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
TIM_CCPreloadControl(TIM1, ENABLE);
TIM_ITConfig(TIM1, TIM_IT_COM, ENABLE);
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
/* Main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
while (1)
{}
}
@file TIM/6Steps/stm32f10x_it.c
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
/* Generate TIM1 COM event by software */
TIM_GenerateEvent(TIM1, TIM_EventSource_COM);
}
/******************************************************************************/
/* STM32F10x Peripherals Interrupt Handlers */
/******************************************************************************/
/**
* @brief This function handles TIM1 Trigger and commutation interrupts
* requests.
* @param None
* @retval None
*/
#if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL)
void TIM1_TRG_COM_TIM17_IRQHandler(void)
#else
void TIM1_TRG_COM_IRQHandler(void)
#endif
{
/* Clear TIM1 COM pending bit */
TIM_ClearITPendingBit(TIM1, TIM_IT_COM);
if (step == 1)
{
/* Next step: Step 2 Configuration ---------------------------- */
/* Channel3 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
/* Channel1 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
/* Channel2 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1 );
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);
step++;
}
else if (step == 2)
{
/* Next step: Step 3 Configuration ---------------------------- */
/* Channel2 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);
/* Channel3 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
/* Channel1 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
step++;
}
else if (step == 3)
{
/* Next step: Step 4 Configuration ---------------------------- */
/* Channel3 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
/* Channel2 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
/* Channel1 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
step++;
}
else if (step == 4)
{
/* Next step: Step 5 Configuration ---------------------------- */
/* Channel3 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
/* Channel1 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
/* Channel2 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
step++;
}
else if (step == 5)
{
/* Next step: Step 6 Configuration ---------------------------- */
/* Channel3 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);
/* Channel1 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
/* Channel2 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
step++;
}
else
{
/* Next step: Step 1 Configuration ---------------------------- */
/* Channel1 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
/* Channel3 configuration */
TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);
/* Channel2 configuration */
TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable);
step = 1;
}
}
stm32对于三相电机控制的特点
电机控制
STM32增强型系列内嵌非常适合三相无刷电机控制的定时器和ADC,其高级PWM定时器提供:
■ 6路PWM输出;
■ 死区产生;
■ 边沿对齐和中心对齐波形;
■ 紧急故障停机,可与2路ADC同步及与其它定时器同步;
■ 可编程的防范机制可以用于防止对寄存器的非法写入;
■ 编码器输入接口;
■ 霍尔传感器接口;
■ 完整的矢量控制环:无传感器模式下为21us
双ADC结构允许双通道采样/保持,以实现12位精度、1 ms的转化。此双ADC结构为2个工作在非连续模式的独立的时序控制,具有多个触发源,并且每个通道的采样时间可编程。以上专门的外围电路与高性能 Cotex-M3内核的结合,可使完整的矢量控制环软件执行时间缩短为21 ms(无传感器模式、3相PMSM马达)。当电流采样频率为10 kHz时,CPU的工作负载低于25%,STM32可以执行应用中电机控制之外的其它任务。
上一篇:STM32 TImer几种模式
下一篇:STM32定时器的预装寄存器及影子寄存器PSC—ARR-CCRx
推荐阅读最新更新时间:2024-11-17 00:49
推荐帖子
- 神舟IV LCD显示SD卡图片 (简易电子相架功能)
- 目的:在LCD上显示图片方案:由于STM32F107VC内置内存只有64K,不足以全屏显示板载LCD,SSD1289,320x240x16bit图像数据只能通过外部存储设备读入,板置W25X16,或SD。数据需要提前导入。另一个方案是通过数据连接在运行时实时传输,USART,LAN,或USB。需要数据服务端程序。通过SD传输是开发量最少且可以独立运行的方案研究:板载有2个SD卡槽,主板卡槽和LCD板背部槽。由于主板卡槽使用的CS线与LC
- btvnlue stm32/stm8
- blackfin706 学习步骤
- blackfin706学习步骤blackfin706学习步骤:):)
- wangjinquan ADI参考电路
- 有哪位仁兄开发过笔记本快捷键驱动
- 能否把原理说一下,另外快捷键调节亮度跟显卡驱动还有BIOS有关系是么?有哪位仁兄开发过笔记本快捷键驱动不同的方案解决方法不一样。一般情况下,笔记本快捷键是HID类设备,支持HID规范,加载HIDClass驱动。设备管理器里面很多的HIDCompliantDevice属于这类设备。亮度调节的实现方式跟显卡设计相关。一般来说,显卡驱动会提供一个调节亮度的接口,监控程序接收到对应按键信息之后,调用该接口来控制显示器亮度。BIOS控制亮度不太了解,BIOS的控制比较底层,有可能BIOS直接
- yingzi9 嵌入式系统
- 【Linux学习笔记5】shell脚本学习笔记
- 【Linux学习笔记5】shell脚本学习1.基础概念Shell概念:shell既是一种命令语言又是一种程序设计语言,它本身是一个用C语言编写的程序,作为用户使用Linux的桥梁Shell了解:系统给出shell提示符,对普通用户用$作提示符,对root用户用#做提示符,在提示符后输入命令名称及所需要的参数,shell将执行这些命令。2.shell脚本有什么用?《鸟哥私房菜》汇整一些在c
- 常见泽1 Linux与安卓
- 半天时间搞懂模拟电路
- 模拟电路精简教程。四十余页包含了模拟电路几乎所有重要知识点,讲解精细,透彻。不敢私藏,传上来与众共享。半天时间搞懂模拟电路多谢楼主分享,呵呵!回复模拟电路基础知识,还不错谢谢楼主了!谢谢楼主了!楼主辛苦了:rose:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy半天时间搞懂模电!!!!????太夸张吧,需要合理引导初学者啊,呵呵,我看没有大半辈子,模电哪里能谈的上“搞懂”。说得好,“三年磨数电,十年磨模电”。这资料是些基础的东西,简单易懂回复9
- linda_xia 模拟电子
- 2007年全国大学生电子设计竞赛基本仪器和主要元器
- 本帖最后由paulhyde于2014-9-1509:47编辑1、基本仪器清单20MHz普通示波器(双通道,外触发输入,有X轴输入,可选带Z轴输入)60MHz双通道数字示波器低频信号发生器(1Hz~1MHz)高频信号发生器(1MHz~40MHz)函数发生器低频毫伏表高频毫伏表普通频率计失真度测试仪直流稳压电源秒表2米卷尺游标高度尺单片机开发系统及EDA开发系统单相自耦调压器(>200W)五位半数字万用表(电压表)四位半数字万用表2、主要元器件清单
- 呱呱 电子竞赛
设计资源 培训 开发板 精华推荐
- 使用 Infineon Technologies AG 的 OMR7812ST 的参考设计
- AD8546ARMZ电压跟随器配置的典型应用电路
- LT6604IUFF-15 双路极低噪声、差分放大器和 15MHz 低通滤波器的典型应用电路
- NCP571MN12TBGEVB,用于便携式 1.2V DC 至 DC 单输出电源的评估板
- SensorTile可连接的传感器节点:插头或焊接
- LTC2267-14、14 位、105Msps 低功耗双路模数转换器的典型应用
- C500630_CH340S(C109467)USB转打印并口
- TWR-K65F180M: 面向Kinetis K26、K65、和K66 MCU的Kinetis K65 MCU塔式系统模块
- 原神/宵宫/久岐忍/喜多川海梦 校卡/水卡/门禁卡
- AM1G-1203SZ 3.3V 1 瓦 DC/DC 转换器的典型应用