Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void xx() {
- RCC_APB2PeriphClockCmd(RCC_APB2ENR_TIM1EN, ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOAEN, ENABLE);
- GPIO_InitTypeDef gpio_cfg;
- gpio_cfg.GPIO_Pin = GPIO8;
- gpio_cfg.GPIO_Mode = GPIO_Mode_AF;
- gpio_cfg.GPIO_Speed = GPIO_Speed_50MHz;
- gpio_cfg.GPIO_OType = GPIO_OType_PP;
- gpio_cfg.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOA, &gpio_cfg);
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_6);
- // timer core
- TIM_TimeBaseInitTypeDef tbinit = {0,};
- tbinit.TIM_Period = 400;
- tbinit.TIM_Prescaler = 0;
- tbinit.TIM_ClockDivision = TIM_CKD_DIV1;
- tbinit.TIM_CounterMode = TIM_CounterMode_Up;
- tbinit.TIM_RepetitionCounter = 0x0000;
- TIM_TimeBaseInit(TIM1, &tbinit);
- TIM_Cmd(TIM1, ENABLE); // start the timer
- // pwm generation
- TIM_OCInitTypeDef ocinit = {0,};
- ocinit.TIM_OCMode = TIM_OCMode_PWM1;
- ocinit.TIM_Pulse = 200;
- ocinit.TIM_OutputState = TIM_OutputState_Enable;
- ocinit.TIM_OCPolarity = TIM_OCPolarity_High;
- TIM_OC1Init(TIM1, &ocinit);
- TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
- }
Advertisement
Add Comment
Please, Sign In to add comment