本文整理汇总了C++中TIM_OC2PreloadConfig函数的典型用法代码示例。如果您正苦于以下问题:C++ TIM_OC2PreloadConfig函数的具体用法?C++ TIM_OC2PreloadConfig怎么用?C++ TIM_OC2PreloadConfig使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TIM_OC2PreloadConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vLedSetDuty
void vLedSetDuty(LedState_t state, int32_t duty)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_Cmd(TIM2, DISABLE);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 400;
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t) (SystemCoreClock / 24000000) - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = duty<<2;
if (TIM_OCInitStructure.TIM_Pulse>TIM_TimeBaseStructure.TIM_Period)
TIM_OCInitStructure.TIM_Pulse=TIM_TimeBaseStructure.TIM_Period-1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
if (state==LedState_White)
{
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_OC2Init(TIM2, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_OC3Init(TIM2, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);
}
else if (state==LedState_Green)
{
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);
}
else if (state==LedState_Red)
{
TIM_OC2Init(TIM2, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);
}
else if (state==LedState_Blue)
{
TIM_OC3Init(TIM2, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);
}
TIM_ARRPreloadConfig(TIM2, ENABLE);
/* TIM3 enable counter */
TIM_Cmd(TIM2, ENABLE);
}
示例2: TIM3_Init
void TIM3_Init(void) {
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = TIM3_PRESCALER;
TIM_TimeBaseStructure.TIM_Period = TIM3_PERIOD;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel2 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC2Init(TIM3, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3, ENABLE);
/* TIM3 enable counter */
TIM_Cmd(TIM3, ENABLE);
}
示例3: TIM3_PWM_Init
void TIM3_PWM_Init( void )
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE );
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOA, &GPIO_InitStructure );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_Init( GPIOB, &GPIO_InitStructure );
/* ------------------------------------------------------------
* TIM3 Configuration: generate 4 PWM signals with 4 different duty cycles:
* TIM3CLK = 72 MHz, Prescaler = 0x0, TIM3 counter clock = 72 MHz
* TIM3 ARR Register = 999 => TIM3 Frequency = TIM3 counter clock/(ARR + 1)
* TIM3 Frequency = 72 KHz.
* TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR)* 100 = 50%
* TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR)* 100 = 37.5%
* TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR)* 100 = 25%
* TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR)* 100 = 12.5%
* ------------------------------------------------------------- */
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = PWM_ARR;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure );
TIM_ARRPreloadConfig( TIM3, ENABLE );
TIM_Cmd( TIM3, ENABLE );
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC1Init( TIM3, &TIM_OCInitStructure );
TIM_OC1PreloadConfig( TIM3, TIM_OCPreload_Enable );
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC2Init( TIM3, &TIM_OCInitStructure );
TIM_OC2PreloadConfig( TIM3, TIM_OCPreload_Enable );
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC3Init( TIM3, &TIM_OCInitStructure );
TIM_OC3PreloadConfig( TIM3, TIM_OCPreload_Enable );
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC4Init( TIM3, &TIM_OCInitStructure );
TIM_OC4PreloadConfig( TIM3, TIM_OCPreload_Enable );
}
示例4: initPWM
void initPWM() {
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
/* PWM1 Mode configuration: Channel1 (GPIOD Pin 12)*/
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel2 (GPIOD Pin 13)*/
TIM_OC2Init(TIM4, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel3 (GPIOD Pin 14)*/
TIM_OC3Init(TIM4, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel4 (GPIOD Pin 15)*/
TIM_OC4Init(TIM4, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_Cmd(TIM4, ENABLE);
}
示例5: TIM_OC1Init
void pwm::setControlRegister(uint8_t registerNum, TIM_TypeDef* timer)
{
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //sets the timer to output pwm signals
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse = 0;
if(registerNum == 1)
{
TIM_OC1Init(timer, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(timer, TIM_OCPreload_Enable);
}
else if(registerNum == 2)
{
TIM_OC2Init(timer, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(timer, TIM_OCPreload_Enable);
}
else if(registerNum == 3)
{
TIM_OC3Init(timer, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(timer, TIM_OCPreload_Enable);
}
else if(registerNum == 4)
{
TIM_OC4Init(timer, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(timer, TIM_OCPreload_Enable);
}
}
示例6: TIM9_Configuration
void TIM9_Configuration(void)
{
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* Time base configuration - SystemCoreClock = 168000000 for 168 MHz board */
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t) (((SystemCoreClock / 1000000)) - 1); // Shooting for 1 MHz, (1us)
TIM_TimeBaseStructure.TIM_Period = 20000 - 1; // 1 MHz / 20000 = 50 Hz (20ms)
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM9, &TIM_TimeBaseStructure);
/* Enable TIM4 Preload register on ARR */
TIM_ARRPreloadConfig(TIM9, ENABLE);
/* TIM PWM1 Mode configuration: Channel */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 1500; // Servo Top-Center
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
/* Output Compare PWM1 Mode configuration: Channel1 PD.12 */
TIM_OC1Init(TIM9, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM9, TIM_OCPreload_Enable);
/* Output Compare PWM1 Mode configuration: Channel2 PD.13 */
TIM_OC2Init(TIM9, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM9, TIM_OCPreload_Enable);
/* TIM Interrupts enable */
TIM_ITConfig(TIM9, TIM_IT_Update, ENABLE);
/* TIM4 enable counter */
TIM_Cmd(TIM9, ENABLE);
}
示例7: Timer3Init
/**
* @brief Main program
* @param None
* @retval None
*/
void Timer3Init(void)
{
RCC_Configuration();
GPIO_Configuration();
/* Compute the prescaler value */
PrescalerValue = (uint16_t) (SystemCoreClock / 1000000) - 1;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 1000;
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel2 */
TIM_OC2Init(TIM3, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3, ENABLE);
/* TIM3 enable counter */
TIM_Cmd(TIM3, ENABLE);
}
示例8: SA_TIMER_PWM_Init
void SA_TIMER_PWM_Init(TIM_TypeDef* TIMx, uint8_t NUM)
{
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //选择定时器模式:TIM脉冲宽度调制模式2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //比较输出使能
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //输出极性:TIM输出比较极性高
//TIM_OCPolarity_High
if (1 == NUM)
{
TIM_OC1Init(TIMx, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIMx, TIM_OCPreload_Enable);
}
else if(2 == NUM)
{
TIM_OC2Init(TIMx, &TIM_OCInitStructure); //根据T指定的参数初始化外设TIM3 OC2
TIM_OC2PreloadConfig(TIMx, TIM_OCPreload_Enable); //使能TIMx在CCR2上的预装载寄存器
}
else if(3 == NUM)
{
TIM_OC3Init(TIMx, &TIM_OCInitStructure); //根据T指定的参数初始化外设TIM3 OC2
TIM_OC3PreloadConfig(TIMx, TIM_OCPreload_Enable); //使能TIMx在CCR2上的预装载寄存器
}
else
{
if (4 == NUM)
{
TIM_OC4Init(TIMx, &TIM_OCInitStructure); //根据T指定的参数初始化外设TIM3 OC2
TIM_OC4PreloadConfig(TIMx, TIM_OCPreload_Enable); //使能TIMx在CCR2上的预装载寄存器
}
}
}
示例9: RCC_APB2PeriphClockCmd
void Rilma_t::Init() {
// ==== GPIO ====
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
// ==== Timer4 as PWM ====
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 255;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
// ==== PWM outputs ====
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
// Init channels
#ifdef CHANNEL1_ENABLE
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
#endif
#ifdef CHANNEL2_ENABLE
TIM_OC2Init(TIM4, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
#endif
#ifdef CHANNEL3_ENABLE
TIM_OC3Init(TIM4, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_OC4Init(TIM4, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);
#endif
TIM_ARRPreloadConfig(TIM4, ENABLE); // Enable autoreload of preload
}
示例10: configBeeperPWMTimer
static void configBeeperPWMTimer(const beeperDevConfig_t *config)
{
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = (1000000 / BEEPER_PWM_FREQUENCY) * 50 / 100; // 50% duty cycle
TIM_OCInitStructure.TIM_OCPolarity = config->isInverted ? TIM_OCPolarity_High : TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = config->isInverted ? TIM_OCIdleState_Reset : TIM_OCIdleState_Set;
configTimeBase(BEEPER_PWM_TIMER, 1000000 / BEEPER_PWM_FREQUENCY, PWM_TIMER_MHZ);
TIM_Cmd(BEEPER_PWM_TIMER, ENABLE);
switch (BEEPER_PWM_TIMER_CH) {
case TIM_Channel_1:
TIM_OC1Init(BEEPER_PWM_TIMER, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(BEEPER_PWM_TIMER, TIM_OCPreload_Enable);
break;
case TIM_Channel_2:
TIM_OC2Init(BEEPER_PWM_TIMER, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(BEEPER_PWM_TIMER, TIM_OCPreload_Enable);
break;
case TIM_Channel_3:
TIM_OC3Init(BEEPER_PWM_TIMER, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(BEEPER_PWM_TIMER, TIM_OCPreload_Enable);
break;
case TIM_Channel_4:
TIM_OC4Init(BEEPER_PWM_TIMER, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(BEEPER_PWM_TIMER, TIM_OCPreload_Enable);
break;
}
TIM_CtrlPWMOutputs(BEEPER_PWM_TIMER, DISABLE);
}
示例11: pwm_mode
void pwm_mode(timer_dev *dev, uint8_t channel) {
timer_disable_irq(dev, channel);
// timer_oc_set_mode(dev, channel, TIMER_OC_MODE_PWM_1, TIMER_OC_PE);
switch (channel)
{
case 1:
TIM_SelectOCxM(dev->regs, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_OC1PreloadConfig(dev->regs, TIM_OCPreload_Enable);
break;
case 2:
TIM_SelectOCxM(dev->regs, TIM_Channel_2, TIM_OCMode_PWM1);
TIM_OC2PreloadConfig(dev->regs, TIM_OCPreload_Enable);
break;
case 3:
TIM_SelectOCxM(dev->regs, TIM_Channel_3, TIM_OCMode_PWM1);
TIM_OC3PreloadConfig(dev->regs, TIM_OCPreload_Enable);
break;
case 4:
TIM_SelectOCxM(dev->regs, TIM_Channel_4, TIM_OCMode_PWM1);
TIM_OC4PreloadConfig(dev->regs, TIM_OCPreload_Enable);
break;
}
timer_cc_enable(dev, channel);
}
示例12: PWM_Config
void PWM_Config(void)
{
/* Configure PWM mode for TIM4 Channels 1->4*/
TIM_OCInitTypeDef TIM_OCInitStructure;
/* PWM Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM4, ENABLE);
//3 other channels
TIM_OC2Init(TIM4, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_OC3Init(TIM4, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_OC4Init(TIM4, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);
/* TIM4 enable counter */
TIM_Cmd(TIM4, ENABLE);
}
示例13: Tim_pulse_set
//----------------------------------------------------------
//TIM PWMモード時のパルス幅変更
void Tim_pulse_set(TIM_TypeDef *tim,int ch,unsigned int pulse){
TIM_OCInitTypeDef TIM_OCInitStructure; //TIMを設定するための構造体
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
if((ch&TIM_CH1) != 0){
TIM_OCInitStructure.TIM_Pulse = pulse;
TIM_OC1Init(tim,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(tim,TIM_OCPreload_Disable);
}
if((ch&TIM_CH2) != 0){
TIM_OCInitStructure.TIM_Pulse = pulse;
TIM_OC2Init(tim,&TIM_OCInitStructure);
TIM_OC2PreloadConfig(tim,TIM_OCPreload_Disable);
}
if((ch&TIM_CH3) != 0){
TIM_OCInitStructure.TIM_Pulse = pulse;
TIM_OC3Init(tim,&TIM_OCInitStructure);
TIM_OC3PreloadConfig(tim,TIM_OCPreload_Disable);
}
if((ch&TIM_CH4) != 0){
TIM_OCInitStructure.TIM_Pulse = pulse;
TIM_OC4Init(tim,&TIM_OCInitStructure);
TIM_OC4PreloadConfig(tim,TIM_OCPreload_Disable);
}
TIM_Cmd(tim,ENABLE);
TIM_ARRPreloadConfig(tim,ENABLE);
}
示例14: switch
void klPwmChannel_t::Init(TIM_TypeDef* PTimer, uint16_t ATopValue, uint32_t AFreqHz, uint8_t ANumber, uint16_t APolarity) {
klTimer_t::Init(PTimer, ATopValue, AFreqHz);
INumber = ANumber;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = APolarity;
switch (ANumber) {
case 1:
TIM_OC1Init(PTimer, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(PTimer, TIM_OCPreload_Enable);
break;
case 2:
TIM_OC2Init(PTimer, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(PTimer, TIM_OCPreload_Enable);
break;
case 3:
TIM_OC3Init(PTimer, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(PTimer, TIM_OCPreload_Enable);
break;
case 4:
TIM_OC4Init(PTimer, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(PTimer, TIM_OCPreload_Enable);
break;
default: break;
}
TIM_ARRPreloadConfig(PTimer, ENABLE); // Enable autoreload of preload
klTimer_t::Enable();
}
示例15: TIM2_Configuration
/**TIM2选用没有重影像方式**/
void TIM2_Configuration(void)//TIMER INITIALIZATION
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
// GPIO_PinRemapConfig(_,_);//没有重映像
// TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
TIM_TimeBaseStructure.TIM_Period = 100-1;
TIM_TimeBaseStructure.TIM_Prescaler =36-1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
// TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);//定时器中断
//PWM初始化
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OC1Init(TIM2,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Enable);//使能预装载寄存器
TIM_OC2Init(TIM2,&TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM2,TIM_OCPreload_Enable);//使能预装载寄存器
TIM_OC3Init(TIM2,&TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM2,TIM_OCPreload_Enable);//使能预装载寄存器
TIM_OC4Init(TIM2,&TIM_OCInitStructure);
TIM_OC4PreloadConfig(TIM2,TIM_OCPreload_Enable);//使能预装载寄存器
TIM_Cmd(TIM2,ENABLE);
}