// Test the mosfet void mosfet_start_up_test(void) { on_tim1_cc4 = gather_adc_values; TIM_ITConfig(TIM1, TIM_IT_CC4, ENABLE); mosfet_test_step = 1; // apply the step mosfet_test_update_phase(); // trggier a COM event TIM_GenerateEvent(TIM1, TIM_EventSource_COM); set_duty(DUTY(10), DUTY(50)); // PWM 10% duty, CC4 20% set_phase_update_freq(G5_Tone*2, mosfet_test_update_phase); initial_adc_dma_for_mosfet_test(); start_adc(CH_A, ADC_SampleTime_1_5Cycles); while(1); }
void platform_pwm_init() { int i; for(i=0;i<NUM_PWM;i++){ pwms_duty[i] = DUTY(0); } pwm_init(500, NULL); // NODE_DBG("Function pwms_init() is called.\n"); }
void platform_pwm_start( unsigned pin ) { // NODE_DBG("Function platform_pwm_start() is called.\n"); if ( pin < NUM_PWM) { if(!pwm_exist(pin)) return; pwm_set_duty(DUTY(pwms_duty[pin]), pin); pwm_start(); } }
// Set the PWM duty uint32_t platform_pwm_set_duty( unsigned pin, uint32_t duty ) { // NODE_DBG("Function platform_pwm_set_duty() is called.\n"); if ( pin < NUM_PWM) { if(!pwm_exist(pin)) return 0; pwm_set_duty(DUTY(duty), pin); } else { return 0; } pwm_start(); pwms_duty[pin] = NORMAL_DUTY(pwm_get_duty(pin)); return pwms_duty[pin]; }
void pwmOutputInit(drv_pwm_output_config_t * init) { GPIO_InitTypeDef GPIO_InitStructure = { 0, }; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure = { 0, }; TIM_OCInitTypeDef TIM_OCInitStructure = { 0, }; // Outputs // PWM1 TIM1_CH1 PA8 // PWM2 TIM1_CH4 PA11 // PWM3 TIM4_CH1 PB6 // PWM4 TIM4_CH2 PB7 // PWM5 TIM4_CH3 PB8 // PWM6 TIM4_CH4 PB9 // Output pins GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3; 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_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9; //GPIO_Init(GPIOB, &GPIO_InitStructure); // Output timers TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Prescaler = (36 - 1); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; if (init->noEsc) { TIM_TimeBaseStructure.TIM_Period = (2000000 / init->motorPwmRate) - 1; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); pwm_period = 2000000 / init->motorPwmRate; TIM_OCInitStructure.TIM_Pulse = DUTY(10); TIM_OC1Init(TIM2, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = DUTY(20); TIM_OC2Init(TIM2, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = DUTY(30); TIM_OC3Init(TIM2, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = DUTY(40); TIM_OC4Init(TIM2, &TIM_OCInitStructure); }else if (init->useServos == true) { // ch1, 2 for servo TIM_TimeBaseStructure.TIM_Period = (2000000 / init->servoPwmRate) - 1; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_Pulse = PULSE_1p5MS; TIM_OC1Init(TIM1, &TIM_OCInitStructure); TIM_OC4Init(TIM1, &TIM_OCInitStructure); TIM_TimeBaseStructure.TIM_Period = (2000000 / init->escPwmRate) - 1; TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_Pulse = PULSE_1MS; TIM_OC1Init(TIM4, &TIM_OCInitStructure); TIM_OC2Init(TIM4, &TIM_OCInitStructure); TIM_OC3Init(TIM4, &TIM_OCInitStructure); TIM_OC4Init(TIM4, &TIM_OCInitStructure); } else { TIM_TimeBaseStructure.TIM_Period = (2000000 / init->escPwmRate) - 1; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_Pulse = PULSE_1MS; TIM_OC1Init(TIM1, &TIM_OCInitStructure); TIM_OC4Init(TIM1, &TIM_OCInitStructure); TIM_OC1Init(TIM4, &TIM_OCInitStructure); TIM_OC2Init(TIM4, &TIM_OCInitStructure); TIM_OC3Init(TIM4, &TIM_OCInitStructure); TIM_OC4Init(TIM4, &TIM_OCInitStructure); } TIM_Cmd(TIM2, ENABLE); //TIM_Cmd(TIM4, ENABLE); TIM_CtrlPWMOutputs(TIM2, ENABLE); //TIM_CtrlPWMOutputs(TIM4, ENABLE); }