반응형
개발환경) System workbench
// PortD
#define PIN_WIPER_PWM_IN GPIO_Pin_13 // PD13
void InitGPIO(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = PIN_Z_CLK_CNT | PIN_UNWIND_PWM_IN1 | PIN_UNWIND_PWM_IN2 | PIN_WIPER_PWM_IN ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
void InitTimer_Pwm(void)
{ //TIMER4
/* TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
/* Time base configuration */
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure_TIM4;
TIM_TimeBaseStructure_TIM4.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure_TIM4.TIM_Prescaler = 3-1; // 72Mhz / 3 = 24Mhz
TIM_TimeBaseStructure_TIM4.TIM_Period = 1000-1; // 24Mhz / 1000 = 24Khz (PWM 주기는 24Khz)
TIM_TimeBaseStructure_TIM4.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure_TIM4);
/* PWM1 Mode configuration */
TIM_OCInitTypeDef TIM_OCInitStructure_WIPER;
TIM_OCInitStructure_WIPER.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure_WIPER.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure_WIPER.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure_WIPER.TIM_Pulse = (int)(nFanDuty * 10); // Duty 설정. nFanDuty (0 ~ 100)
TIM_OC2Init(TIM4, &TIM_OCInitStructure_WIPER);
TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_Cmd(TIM4, ENABLE);
}
728x90
반응형
'공부 > HW' 카테고리의 다른 글
201123 불량사례 ULN2803 파손 (0) | 2020.11.25 |
---|---|
201112 NAND vs. NOR flash (0) | 2020.11.12 |
201013 백래시 (0) | 2020.10.13 |
200928 SystemWorkbench - 문자열 연결 (0) | 2020.09.28 |
200925 스텝 모터 드라이버 (TB6560AHQ) excitation mode (0) | 2020.09.26 |