本文整理汇总了C++中TIM_Cmd函数的典型用法代码示例。如果您正苦于以下问题:C++ TIM_Cmd函数的具体用法?C++ TIM_Cmd怎么用?C++ TIM_Cmd使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TIM_Cmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: analogWrite
//.........这里部分代码省略.........
{
return;
}
// SPI safety check
if (SPI.isEnabled() == true && (pin == SCK || pin == MOSI || pin == MISO))
{
return;
}
// I2C safety check
if (Wire.isEnabled() == true && (pin == SCL || pin == SDA))
{
return;
}
// Serial1 safety check
if (Serial1.isEnabled() == true && (pin == RX || pin == TX))
{
return;
}
if(PIN_MAP[pin].pin_mode != OUTPUT && PIN_MAP[pin].pin_mode != AF_OUTPUT_PUSHPULL)
{
return;
}
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
//PWM Frequency : 500 Hz
uint16_t TIM_Prescaler = (uint16_t)(SystemCoreClock / 24000000) - 1;//TIM Counter clock = 24MHz
uint16_t TIM_ARR = (uint16_t)(24000000 / TIM_PWM_FREQ) - 1;
// TIM Channel Duty Cycle(%) = (TIM_CCR / TIM_ARR + 1) * 100
uint16_t TIM_CCR = (uint16_t)(value * (TIM_ARR + 1) / 255);
// AFIO clock enable
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
pinMode(pin, AF_OUTPUT_PUSHPULL);
// TIM clock enable
if(PIN_MAP[pin].timer_peripheral == TIM2)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
}
else if(PIN_MAP[pin].timer_peripheral == TIM3)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
}
else if(PIN_MAP[pin].timer_peripheral == TIM4)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
}
// Time base configuration
TIM_TimeBaseStructure.TIM_Period = TIM_ARR;
TIM_TimeBaseStructure.TIM_Prescaler = TIM_Prescaler;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(PIN_MAP[pin].timer_peripheral, &TIM_TimeBaseStructure);
// PWM1 Mode configuration
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse = TIM_CCR;
if(PIN_MAP[pin].timer_ch == TIM_Channel_1)
{
// PWM1 Mode configuration: Channel1
TIM_OC1Init(PIN_MAP[pin].timer_peripheral, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(PIN_MAP[pin].timer_peripheral, TIM_OCPreload_Enable);
}
else if(PIN_MAP[pin].timer_ch == TIM_Channel_2)
{
// PWM1 Mode configuration: Channel2
TIM_OC2Init(PIN_MAP[pin].timer_peripheral, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(PIN_MAP[pin].timer_peripheral, TIM_OCPreload_Enable);
}
else if(PIN_MAP[pin].timer_ch == TIM_Channel_3)
{
// PWM1 Mode configuration: Channel3
TIM_OC3Init(PIN_MAP[pin].timer_peripheral, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(PIN_MAP[pin].timer_peripheral, TIM_OCPreload_Enable);
}
else if(PIN_MAP[pin].timer_ch == TIM_Channel_4)
{
// PWM1 Mode configuration: Channel4
TIM_OC4Init(PIN_MAP[pin].timer_peripheral, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(PIN_MAP[pin].timer_peripheral, TIM_OCPreload_Enable);
}
TIM_ARRPreloadConfig(PIN_MAP[pin].timer_peripheral, ENABLE);
// TIM enable counter
TIM_Cmd(PIN_MAP[pin].timer_peripheral, ENABLE);
}
示例2: tim_state
void tim_state(int dev, uint8_t state) {
TIM_Cmd(tim_devs[dev], state);
}
示例3: main
/**
* @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();
/* GPIO Configuration */
GPIO_Configuration();
/* DMA Configuration */
DMA_Configuration();
/* TIM1 DMA Transfer example -------------------------------------------------
TIM1CLK = SystemCoreClock, Prescaler = 0, TIM1 counter clock = SystemCoreClock
SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density
and Connectivity line devices and to 24 MHz for Low-Density Value line and
Medium-Density Value line devices.
The objective is to configure TIM1 channel 3 to generate complementary PWM
signal with a frequency equal to 17.57 KHz:
- TIM1_Period = (SystemCoreClock / 17570) - 1
and a variable duty cycle that is changed by the DMA after a specific number of
Update DMA request.
The number of this repetitive requests is defined by the TIM1 Repetion counter,
each 3 Update Requests, the TIM1 Channel 3 Duty Cycle changes to the next new
value defined by the SRC_Buffer .
-----------------------------------------------------------------------------*/
/* Compute the value to be set in ARR regiter to generate signal frequency at 17.57 Khz */
TimerPeriod = (SystemCoreClock / 17570 ) - 1;
/* Compute CCR1 value to generate a duty cycle at 50% */
SRC_Buffer[0] = (uint16_t) (((uint32_t) 5 * (TimerPeriod - 1)) / 10);
/* Compute CCR1 value to generate a duty cycle at 37.5% */
SRC_Buffer[1] = (uint16_t) (((uint32_t) 375 * (TimerPeriod - 1)) / 1000);
/* Compute CCR1 value to generate a duty cycle at 25% */
SRC_Buffer[2] = (uint16_t) (((uint32_t) 25 * (TimerPeriod - 1)) / 100);
/* TIM1 Peripheral Configuration --------------------------------------------*/
/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = TimerPeriod;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 2;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Channel 3 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 = SRC_Buffer[0];
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
/* TIM1 Update DMA Request enable */
TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE);
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
/* Main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
while (1)
{}
}
示例4: main
//.........这里部分代码省略.........
/* ---------------------------------------------------------------------------
TIM1 Configuration to:
1/ Generate 3 complementary PWM signals with 3 different duty cycles:
TIM1 input clock (TIM1CLK) is set to 2 * APB2 clock (PCLK2), since APB2
prescaler is different from 1.
TIM1CLK = 2 * PCLK2
PCLK2 = HCLK / 2
=> TIM1CLK = 2 * (HCLK / 2) = HCLK = SystemCoreClock
TIM1CLK is fixed to SystemCoreClock, the TIM1 Prescaler is equal to 0 so the
TIM1 counter clock used is SystemCoreClock (168MHz).
The objective is to generate PWM signal at 17.57 KHz:
- TIM1_Period = (SystemCoreClock / 17570) - 1
The Three Duty cycles are computed as the following description:
The channel 1 duty cycle is set to 50% so channel 1N is set to 50%.
The channel 2 duty cycle is set to 25% so channel 2N is set to 75%.
The channel 3 duty cycle is set to 12.5% so channel 3N is set to 87.5%.
The Timer pulse is calculated as follows:
- ChannelxPulse = DutyCycle * (TIM1_Period - 1) / 100
2/ Insert a dead time equal to (11/SystemCoreClock) ns
3/ Configure the break feature, active at High level, and using the automatic
output enable feature
4/ Use the Locking parameters level1.
Note:
SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.
Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
function to update SystemCoreClock variable value. Otherwise, any configuration
based on this variable will be incorrect.
--------------------------------------------------------------------------- */
/* Compute the value to be set in ARR register to generate signal frequency at 17.57 Khz */
TimerPeriod = (SystemCoreClock / 17570) - 1;
/* Compute CCR1 value to generate a duty cycle at 50% for channel 1 */
Channel1Pulse = (uint16_t) (((uint32_t) 5 * (TimerPeriod - 1)) / 10);
/* Compute CCR2 value to generate a duty cycle at 25% for channel 2 */
Channel2Pulse = (uint16_t) (((uint32_t) 25 * (TimerPeriod - 1)) / 100);
/* Compute CCR3 value to generate a duty cycle at 12.5% for channel 3 */
Channel3Pulse = (uint16_t) (((uint32_t) 125 * (TimerPeriod - 1)) / 1000);
/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = TimerPeriod;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Channel 1, 2 and 3 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 = Channel1Pulse;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = Channel2Pulse;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = Channel3Pulse;
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
TIM_BDTRInitStructure.TIM_DeadTime = 11;
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
/* Main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
while (1)
{
}
}
示例5: ADC_StopConver
void ADC_StopConver(void)
{
TIM_Cmd(TIM2, DISABLE);
ADC_DMACmd(ADC1, DISABLE);
}
示例6: TIM2_IRQHandler
//------------------------------------------------------------------------------
void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus (TIM2, TIM_IT_Update) != RESET)
{
uiTime_AlarmLevel = uiTime_AlarmLevel + 1;
uiRespond_time = uiRespond_time + 1;
STM_EVAL_LEDOff(LED5);
if (uiCurrent_Status == STATUS_SpO2_BELOW_L1 | uiCurrent_Status == STATUS_SpO2_BEHIGH_L1)
{
if (uiTime_AlarmLevel > SProfile.uiAlarm_Level1)
{
uiTime_AlarmLevel = 0; // Reset Time_AlarmLevel
uiRespond_time = 0;
/* If Time alarm more than alarm level 1 set */
if (uiCurrent_Status == STATUS_SpO2_BELOW_L1)
{
uiCurrent_Status = STATUS_SpO2_BELOW_ALARM_L1;
uiPurpose_FiO2 = uiPurpose_FiO2 + 6;
if (uiPurpose_FiO2 > SProfile.uiFiO2_Maximum)
{
/* if uiPurpose_FiO2 more than uiFiO2_Maximum */
uiPurpose_FiO2 = SProfile.uiFiO2_Maximum;
}
FiO2_Range(uiPurpose_FiO2);
/* Update LCD */
lcdString(1,5,"Status: Below ");
lcdString(1,6,"Alarm Level 2");
}
else if (uiCurrent_Status == STATUS_SpO2_BEHIGH_L1)
{
uiCurrent_Status = STATUS_SpO2_BEHIGH_ALARM_L1;
uiPurpose_FiO2 = uiPurpose_FiO2 - 6;
if (uiPurpose_FiO2 < SProfile.uiFiO2_Minimum)
{
/* if uiPurpose_FiO2 more than uiFiO2_Minimum */
uiPurpose_FiO2 = SProfile.uiFiO2_Minimum;
}
FiO2_Range(uiPurpose_FiO2);
/* Update LCD */
lcdString(1,5,"Status: Behigh ");
lcdString(1,6,"Alarm Level 2");
}
}
else if( uiRespond_time > SProfile.uiRespondsTime)
{
if( uiCurrent_Status == STATUS_SpO2_BELOW_L1)
{
/* Check Current SpO2. if SpO2 is lower than last time, the system will increase FiO2 */
if (uiCurrent_SpO2 <= uiInitial_SpO2)
{
uiPurpose_FiO2 = uiPurpose_FiO2 + 4; // Increase FiO2 4 percent
}
uiRespond_time = 0; // clear Respond time
/* Check Limit of FiO2 */
if (uiPurpose_FiO2 > SProfile.uiFiO2_Maximum)
{
uiPurpose_FiO2 = SProfile.uiFiO2_Maximum;
}
uiInitial_SpO2 = uiCurrent_SpO2; // save current SpO2 at initial
}
else if(uiCurrent_Status == STATUS_SpO2_BEHIGH_L1)
{
/* if SpO2 is higher than last time, the system will decrease FiO2*/
if(uiCurrent_SpO2 >= uiInitial_SpO2)
{
uiPurpose_FiO2 = uiPurpose_FiO2 - 4; // Decrease FiO2 4 percent
}
uiRespond_time = 0; // Clear Respond time
/* Check Limit of FiO2 */
if (uiPurpose_FiO2 < SProfile.uiFiO2_Minimum)
{
uiPurpose_FiO2 = SProfile.uiFiO2_Minimum;
}
}
uiInitial_SpO2 = uiCurrent_SpO2; // save new Current SpO2
FiO2_Range(uiPurpose_FiO2);
}
}
else if (uiCurrent_Status == STATUS_SpO2_BEHIGH_L2 | uiCurrent_Status == STATUS_SpO2_BELOW_L2)
{
/* Alarm Level 2 */
if (uiTime_AlarmLevel >= SProfile.uiAlarm_Level2)
{
GPIO_SetBits(Alarm_Set_GPIO_Port, Alarm_Set_Pin);
uiCurrent_Status = STATUS_ALARM;
USART_Cmd(OPM_USART, ENABLE); // ENABLE Oxygen Pulse Meter USART
TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE);
TIM_Cmd(TIM3, DISABLE);
//.........这里部分代码省略.........
示例7: RCC_APB2PeriphClockCmd
bool Servo::attach(uint16_t pin,
uint16_t minPW,
uint16_t maxPW,
int16_t minAngle,
int16_t maxAngle) {
if (pin >= TOTAL_PINS || PIN_MAP[pin].timer_peripheral == NULL)
{
return false;
}
// SPI safety check
if (SPI.isEnabled() == true && (pin == SCK || pin == MOSI || pin == MISO))
{
return false;
}
// I2C safety check
if (Wire.isEnabled() == true && (pin == SCL || pin == SDA))
{
return false;
}
// Serial1 safety check
if (Serial1.isEnabled() == true && (pin == RX || pin == TX))
{
return false;
}
if (this->attached()) {
this->detach();
}
this->pin = pin;
this->minPW = minPW;
this->maxPW = maxPW;
this->minAngle = minAngle;
this->maxAngle = maxAngle;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
// AFIO clock enable
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
pinMode(pin, AF_OUTPUT_PUSHPULL);
// TIM clock enable
if(PIN_MAP[pin].timer_peripheral == TIM2)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
else if(PIN_MAP[pin].timer_peripheral == TIM3)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
else if(PIN_MAP[pin].timer_peripheral == TIM4)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
// Time base configuration
TIM_TimeBaseStructure.TIM_Period = SERVO_TIM_ARR;
TIM_TimeBaseStructure.TIM_Prescaler = SERVO_TIM_PRESCALER;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(PIN_MAP[pin].timer_peripheral, &TIM_TimeBaseStructure);
// PWM1 Mode configuration
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse = 0x0000;
if(PIN_MAP[this->pin].timer_ch == TIM_Channel_1)
{
// PWM1 Mode configuration: Channel1
TIM_OC1Init(PIN_MAP[this->pin].timer_peripheral, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(PIN_MAP[this->pin].timer_peripheral, TIM_OCPreload_Enable);
}
else if(PIN_MAP[this->pin].timer_ch == TIM_Channel_2)
{
// PWM1 Mode configuration: Channel2
TIM_OC2Init(PIN_MAP[this->pin].timer_peripheral, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(PIN_MAP[this->pin].timer_peripheral, TIM_OCPreload_Enable);
}
else if(PIN_MAP[this->pin].timer_ch == TIM_Channel_3)
{
// PWM1 Mode configuration: Channel3
TIM_OC3Init(PIN_MAP[this->pin].timer_peripheral, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(PIN_MAP[this->pin].timer_peripheral, TIM_OCPreload_Enable);
}
else if(PIN_MAP[this->pin].timer_ch == TIM_Channel_4)
{
// PWM1 Mode configuration: Channel4
TIM_OC4Init(PIN_MAP[this->pin].timer_peripheral, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(PIN_MAP[this->pin].timer_peripheral, TIM_OCPreload_Enable);
}
TIM_ARRPreloadConfig(PIN_MAP[this->pin].timer_peripheral, ENABLE);
// TIM enable counter
TIM_Cmd(PIN_MAP[this->pin].timer_peripheral, ENABLE);
// Main Output Enable
//.........这里部分代码省略.........
示例8: TIM_Config
//.........这里部分代码省略.........
/* --------------------------- System Clocks Configuration -----------------*/
/* TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
/* GPIOD clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
/*-------------------------- GPIO Configuration ----------------------------*/
/* GPIOD Configuration: Pins 12, 13, 14 and 15 in output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Connect TIM4 pins to AF2 */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_TIM4);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_TIM4);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_TIM4);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_TIM4);
/* -----------------------------------------------------------------------
TIM4 Configuration: Output Compare Timing Mode:
In this example TIM4 input clock (TIM4CLK) is set to 2 * APB1 clock (PCLK1),
since APB1 prescaler is different from 1 (APB1 Prescaler = 4, see system_stm32f4xx.c file).
TIM4CLK = 2 * PCLK1
PCLK1 = HCLK / 4
=> TIM4CLK = 2*(HCLK / 4) = HCLK/2 = SystemCoreClock/2
To get TIM4 counter clock at 2 KHz, the prescaler is computed as follows:
Prescaler = (TIM4CLK / TIM1 counter clock) - 1
Prescaler = (168 MHz/(2 * 2 KHz)) - 1 = 41999
To get TIM4 output clock at 1 Hz, the period (ARR)) is computed as follows:
ARR = (TIM4 counter clock / TIM4 output clock) - 1
= 1999
TIM4 Channel1 duty cycle = (TIM4_CCR1/ TIM4_ARR)* 100 = 50%
TIM4 Channel2 duty cycle = (TIM4_CCR2/ TIM4_ARR)* 100 = 50%
TIM4 Channel3 duty cycle = (TIM4_CCR3/ TIM4_ARR)* 100 = 50%
TIM4 Channel4 duty cycle = (TIM4_CCR4/ TIM4_ARR)* 100 = 50%
==> TIM4_CCRx = TIM4_ARR/2 = 1000 (where x = 1, 2, 3 and 4).
Note:
SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.
Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
function to update SystemCoreClock variable value. Otherwise, any configuration
based on this variable will be incorrect.
----------------------------------------------------------------------- */
/* Compute the prescaler value */
PrescalerValue = (uint16_t) ((SystemCoreClock /2) / 2000) - 1;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = TIM_ARR;
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* Enable TIM4 Preload register on ARR */
TIM_ARRPreloadConfig(TIM4, ENABLE);
/* TIM PWM1 Mode configuration: Channel */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = TIM_CCR;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
/* Output Compare PWM1 Mode configuration: Channel1 */
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
TIM_CCxCmd(TIM4, TIM_Channel_1, DISABLE);
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
/* Output Compare PWM1 Mode configuration: Channel2 */
TIM_OC2Init(TIM4, &TIM_OCInitStructure);
TIM_CCxCmd(TIM4, TIM_Channel_2, DISABLE);
TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
/* Output Compare PWM1 Mode configuration: Channel3 */
TIM_OC3Init(TIM4, &TIM_OCInitStructure);
TIM_CCxCmd(TIM4, TIM_Channel_3, DISABLE);
TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
/* Output Compare PWM1 Mode configuration: Channel4 */
TIM_OC4Init(TIM4, &TIM_OCInitStructure);
TIM_CCxCmd(TIM4, TIM_Channel_4, DISABLE);
TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);
/* TIM4 enable counter */
TIM_Cmd(TIM4, ENABLE);
}
示例9: main
//.........这里部分代码省略.........
/* Timers synchronisation in cascade mode ----------------------------
1/TIM2 is configured as Master Timer:
- PWM Mode is used
- The TIM2 Update event is used as Trigger Output
2/TIM3 is slave for TIM2 and Master for TIM4,
- PWM Mode is used
- The ITR1(TIM2) is used as input trigger
- Gated mode is used, so start and stop of slave counter
are controlled by the Master trigger output signal(TIM2 update event).
- The TIM3 Update event is used as Trigger Output.
3/TIM4 is slave for TIM3,
- PWM Mode is used
- The ITR2(TIM3) is used as input trigger
- Gated mode is used, so start and stop of slave counter
are controlled by the Master trigger output signal(TIM3 update event).
* For Low-density, Medium-density, High-density and Connectivity line devices:
The TIMxCLK is fixed to 72 MHz, the TIM2 counter clock is 72 MHz.
The Master Timer TIM2 is running at TIM2 frequency :
TIM2 frequency = (TIM2 counter clock)/ (TIM2 period + 1) = 281.250 KHz
and the duty cycle = TIM2_CCR1/(TIM2_ARR + 1) = 25%.
The TIM3 is running:
- At (TIM2 frequency)/ (TIM3 period + 1) = 70.312 KHz and a duty cycle
equal to TIM3_CCR1/(TIM3_ARR + 1) = 25%
The TIM4 is running:
- At (TIM3 frequency)/ (TIM4 period + 1) = 17.578 KHz and a duty cycle
equal to TIM4_CCR1/(TIM4_ARR + 1) = 25%
* For Low-Density Value line and Medium-Density Value line devices:
The TIMxCLK is fixed to 24 MHz, the TIM2 counter clock is 24 MHz.
So TIM2 frequency = 93.750 KHz,
TIM3 is running at 23.437 KHz,
and TIM4 is running at 5.85 KHz
-------------------------------------------------------------------- */
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 255;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 3;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 3;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* Master Configuration in PWM1 Mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 64;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
/* Select the Master Slave Mode */
TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
/* Master Mode selection */
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
/* Slaves Configuration: PWM1 Mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 1;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
/* Slave Mode selection: TIM3 */
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Gated);
TIM_SelectInputTrigger(TIM3, TIM_TS_ITR1);
/* Select the Master Slave Mode */
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);
/* Master Mode selection: TIM3 */
TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Update);
/* Slave Mode selection: TIM4 */
TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Gated);
TIM_SelectInputTrigger(TIM4, TIM_TS_ITR2);
/* TIM enable counter */
TIM_Cmd(TIM3, ENABLE);
TIM_Cmd(TIM2, ENABLE);
TIM_Cmd(TIM4, ENABLE);
while (1)
{
}
}
示例10: boardInit
void boardInit() {
SysTick_Config(SystemCoreClock/1000 - 1);
/*
A note about interrupt priorities
A smaller numeric priority means that the priority is higher, thus
the most important interrupt has priority 0, the least import 31.
If an interrupt arrives while servicing an interrupt with a lower
priority, then the lesser interrupt is interrupted to service the
high priority one, if the high priority interrupt is of a different
preemption priority group.
IOW: an IRQ in PP group 3 will be interrupted if an IRQ arrives with
PP group 2,1 or 0.
The sub priority is only used to order the interrupts at the same PE
level.
NVIC_SetPriorityGrouping is used here to divide the 32 levels of
IRQ priorities into 8 preemption groups and 4 sub priorities.
*/
NVIC_SetPriorityGrouping(4);
for (int i=0;i<35;i++) {
NVIC_SetPriority(i, GROUP_PRIORITY_DEFAULT);
}
NVIC_SetPriority(TIMER2_IRQn, GROUP_PRIORITY_STEPPER);
NVIC_SetPriority(SysTick_IRQn, GROUP_PRIORITY_1000HZ);
NVIC_SetPriority(TIMER3_IRQn, GROUP_PRIORITY_100HZ);
NVIC_SetPriority(USB_IRQn, GROUP_PRIORITY_USB);
initUARTs();
initADC();
initPWM();
// Motor drivers are active low, so let's disable all of them, until the drivers turn them on:
GPIO_SET(IO_X_ENABLE);
GPIO_SET(IO_Y_ENABLE);
GPIO_SET(IO_Z_ENABLE);
GPIO_SET(IO_A_ENABLE);
/*
Set the simple I/O configuration for all the pins we use,
this will ensure that all pins have had its function selected
*/
for (int i=0;i<ALL_PINS_SIZE;i++) {
configPin(ALL_PINS[i]);
}
/*
Set up timer3 to poke the "slow" 100Hz maintainance routine
*/
TIM_TIMERCFG_Type timerCfg;
timerCfg.PrescaleOption = TIM_PRESCALE_USVAL;
timerCfg.PrescaleValue = 1000; // 1 ms interval
TIM_Init(LPC_TIM3, TIM_TIMER_MODE, &timerCfg);
TIM_MATCHCFG_Type timerMatch;
timerMatch.MatchChannel = 0;
timerMatch.IntOnMatch = TRUE;
timerMatch.ResetOnMatch = TRUE;
timerMatch.StopOnMatch = FALSE;
timerMatch.ExtMatchOutputType = TIM_EXTMATCH_NOTHING;
timerMatch.MatchValue = 10-1;
TIM_ConfigMatch(LPC_TIM3,&timerMatch);
NVIC_EnableIRQ(TIMER3_IRQn);
TIM_Cmd(LPC_TIM3,ENABLE);
initAPI();
}
示例11: main
//.........这里部分代码省略.........
- Rising edge is used to start and stop the TIM1: Gated Mode.
3/TIM3 is slave for TIM1 and Master for TIM4,
- Toggle Mode is used
- The ITR1(TIM1) is used as input trigger
- Gated mode is used, so start and stop of slave counter
are controlled by the Master trigger output signal(TIM1 enable event).
- The TIM3 enable event is used as Trigger Output.
4/TIM4 is slave for TIM3,
- Toggle Mode is used
- The ITR2(TIM3) is used as input trigger
- Gated mode is used, so start and stop of slave counter
are controlled by the Master trigger output signal(TIM3 enable event).
The TIMxCLK is fixed to 72 MHZ, the Prescaler is equal to 2 so the TIMx clock counter
is equal to 24 MHz.
The Three Timers are running at:
TIMx frequency = TIMx clock counter/ 2*(TIMx_Period + 1) = 162.1 KHz.
The starts and stops of the TIM1 counters are controlled by the
external trigger.
The TIM3 starts and stops are controlled by the TIM1, and the TIM4
starts and stops are controlled by the TIM3.
-------------------------------------------------------------------- */
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 73;
TIM_TimeBaseStructure.TIM_Prescaler = 2;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 73;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 73;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* Master Configuration in Toggle Mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 64;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
/* TIM1 Input Capture Configuration */
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0;
TIM_ICInit(TIM1, &TIM_ICInitStructure);
/* TIM1 Input trigger configuration: External Trigger connected to TI2 */
TIM_SelectInputTrigger(TIM1, TIM_TS_TI2FP2);
TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Gated);
/* Select the Master Slave Mode */
TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);
/* Master Mode selection: TIM1 */
TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Enable);
/* Slaves Configuration: Toggle Mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
/* Slave Mode selection: TIM3 */
TIM_SelectInputTrigger(TIM3, TIM_TS_ITR0);
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Gated);
/* Select the Master Slave Mode */
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);
/* Master Mode selection: TIM3 */
TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Enable);
/* Slave Mode selection: TIM4 */
TIM_SelectInputTrigger(TIM4, TIM_TS_ITR2);
TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Gated);
/* TIM1 Main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
/* TIM enable counter */
TIM_Cmd(TIM1, ENABLE);
TIM_Cmd(TIM3, ENABLE);
TIM_Cmd(TIM4, ENABLE);
while (1)
{}
}
示例12: initialize_timers
/*This function initializes the pins that are used in pwm, assigns them to their alternate functions,
*and then initializes the TIM(ers) for those pins. For parameters, it takes the frequency of the pwm
*and the prescaler for the clock. The frequency will work fine for anything bellow 525000, but it is
*not guaranteed to work above that. The prescaler divides into the stm boards own internal clock to
*get a clock speed for the timer. The prescaler works good at 1, but it can take any multiple of two
*as its input. The function will return the period of the pwm which is used to calculate the duty cycle
*when setting the pwm for each pin
*/
int32_t initialize_timers(uint32_t frequency, uint16_t preScaler)
{
// Enable TIM3 and GPIOC clocks
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure; //structure used by stm in initializing pins.
// Configure PC6-PC9 pins as AF, Pull-Down
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9; //specifies which pins are used
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //assigns the pins to use their alternate functions
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure); //initializes the structure
// Since each pin has multiple extra functions, this part of the code makes the alternate functions the TIM3 functions.
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_TIM3);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_TIM3);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_TIM3);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_TIM3);
// Compute prescaler value for timebase
uint32_t PrescalerValue = (uint32_t) ((SystemCoreClock /2) / (84000000 / preScaler)) - 1; //To figure out what the numbers do
//second value in the divide is the frequency
uint32_t PreCalPeriod = ((84000000 * preScaler) / frequency) - 1; //To figure out what the numbers do
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //structure used by stm in initializing the pwm
TIM_OCInitTypeDef TIM_OCInitStructure;
// Setup timebase for TIM3
TIM_TimeBaseStructure.TIM_Period = PreCalPeriod; //sets the period of the timer
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; //sets the prescaller which is divided into the cpu clock to get a clock speed that is small enough to use for timers
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //initializes this part of the code
// Initialize TIM3 for 4 channels
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //sets the time to be pulse width
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC1Init(TIM3, &TIM_OCInitStructure); //initiates this part of the pulse width modulation
TIM_OC2Init(TIM3, &TIM_OCInitStructure);
TIM_OC3Init(TIM3, &TIM_OCInitStructure);
TIM_OC4Init(TIM3, &TIM_OCInitStructure);
// Enable TIM3 peripheral Preload register on CCR1 for 4 channels
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable);
// Enable TIM3 peripheral Preload register on ARR.
TIM_ARRPreloadConfig(TIM3, ENABLE);
// Enable TIM3 counter
TIM_Cmd(TIM3, ENABLE);
return(PreCalPeriod);
}
示例13: hold
void hold(uint16_t T){ //Timer up to 1 seconds. (currently)
TIM5->ARR=T*15000;
TIM5->CNT=0;
TIM_Cmd(TIM5, ENABLE);
}
示例14: SweepRobot_WheelFloatCtrlMoveToDownPos
void SweepRobot_WheelFloatCtrlMoveToDownPos(void)
{
TIM_SetCompare1(WHEEL_FLOAT_TEST_CTRL_TIM, WHEEL_FLOAT_TEST_STEERING_ENGINE_DOWN_POS);
TIM_Cmd(WHEEL_FLOAT_TEST_CTRL_TIM, ENABLE);
}
示例15: main
/**
* @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();
/* GPIO Configuration */
GPIO_Configuration();
/* -----------------------------------------------------------------------
TIM1 Configuration to:
1/ Generate 3 complementary PWM signals with 3 different duty cycles:
TIM1CLK is fixed to SystemCoreClock, the TIM1 Prescaler is equal to 0 so the
TIM1 counter clock used is SystemCoreClock.
* SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density
and Connectivity line devices. For Low-Density Value line and Medium-Density
Value line devices, SystemCoreClock is set to 24 MHz.
The objective is to generate PWM signal at 17.57 KHz:
- TIM1_Period = (SystemCoreClock / 17570) - 1
The Three Duty cycles are computed as the following description:
The channel 1 duty cycle is set to 50% so channel 1N is set to 50%.
The channel 2 duty cycle is set to 25% so channel 2N is set to 75%.
The channel 3 duty cycle is set to 12.5% so channel 3N is set to 87.5%.
The Timer pulse is calculated as follows:
- ChannelxPulse = DutyCycle * (TIM1_Period - 1) / 100
2/ Insert a dead time equal to 11/SystemCoreClock ns
3/ Configure the break feature, active at High level, and using the automatic
output enable feature
4/ Use the Locking parameters level1.
----------------------------------------------------------------------- */
/* Compute the value to be set in ARR register to generate signal frequency at 17.57 Khz */
TimerPeriod = (SystemCoreClock / 17570) - 1;
/* Compute CCR1 value to generate a duty cycle at 50% for channel 1 */
Channel1Pulse = (uint16_t) (((uint32_t) 5 * (TimerPeriod - 1)) / 10);
/* Compute CCR2 value to generate a duty cycle at 25% for channel 2 */
Channel2Pulse = (uint16_t) (((uint32_t) 25 * (TimerPeriod - 1)) / 100);
/* Compute CCR3 value to generate a duty cycle at 12.5% for channel 3 */
Channel3Pulse = (uint16_t) (((uint32_t) 125 * (TimerPeriod - 1)) / 1000);
/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = TimerPeriod;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Channel 1, 2 and 3 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 = Channel1Pulse;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = Channel2Pulse;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = Channel3Pulse;
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
TIM_BDTRInitStructure.TIM_DeadTime = 11;
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
/* Main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
//.........这里部分代码省略.........