| | |
| | | //Òý½Å¶¨Òå |
| | | /*******************************************************/ |
| | | // Á¬½ÓÇý¶¯°åµÄ SD ½Å |
| | | #define SHUTDOWN_PIN GPIO_PIN_15 |
| | | #define SHUTDOWN_GPIO_PORT GPIOD |
| | | #define SHUTDOWN_PIN GPIO_PIN_6 |
| | | #define SHUTDOWN_GPIO_PORT GPIOA |
| | | // #define SHUTDOWN_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE() |
| | | /*******************************************************/ |
| | | |
| | |
| | | #define PERIOD_CAP (30000U) |
| | | |
| | | //48Mzhz / 3000 = 16Khz = 62.5us |
| | | #define PERIOD_CMP (4000u) |
| | | #define PERIOD_CMP (3000u) |
| | | |
| | | void TimerInit(void); |
| | | void SetPwmDuty(uint16_t ch, uint32_t duty); |
| | |
| | | ; |
| | | } |
| | | /* configure the systick handler priority */ |
| | | NVIC_SetPriority(SysTick_IRQn, 0x00); |
| | | NVIC_SetPriority(SysTick_IRQn, 0x01); |
| | | } |
| | | |
| | | /*! |
| | |
| | | { |
| | | rcu_periph_clock_enable(RCU_GPIOA); |
| | | rcu_periph_clock_enable(RCU_GPIOB); |
| | | rcu_periph_clock_enable(RCU_GPIOF); |
| | | |
| | | // rcu_periph_clock_enable(RCU_GPIOF); |
| | | /* enable the CFGCMP clock */ |
| | | rcu_periph_clock_enable(RCU_CFGCMP); |
| | | //初始化配置霍尔输入引脚 |
| | | gpio_mode_set(HALL_SENSOR_A_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, HALL_SENSOR_A_PIN); |
| | | gpio_mode_set(HALL_SENSOR_B_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, HALL_SENSOR_B_PIN); |
| | | gpio_mode_set(HALL_SENSOR_C_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, HALL_SENSOR_C_PIN); |
| | | /* enable the CFGCMP clock */ |
| | | rcu_periph_clock_enable(RCU_CFGCMP); |
| | | nvic_irq_enable(EXTI4_15_IRQn, 0U); |
| | | |
| | | /* connect EXTI line to GPIO pin */ |
| | | syscfg_exti_line_config(EXTI_SOURCE_GPIOB, EXTI_SOURCE_PIN4); |
| | | syscfg_exti_line_config(EXTI_SOURCE_GPIOB, EXTI_SOURCE_PIN5); |
| | | syscfg_exti_line_config(EXTI_SOURCE_GPIOA, EXTI_SOURCE_PIN15); |
| | | |
| | | exti_init(EXTI_4 | EXTI_5 | EXTI_15, EXTI_INTERRUPT, EXTI_TRIG_RISING); //配置外部上升沿中断 |
| | | exti_init(EXTI_4, EXTI_INTERRUPT, EXTI_TRIG_RISING); //配置外部上升沿中断 |
| | | exti_init(EXTI_5, EXTI_INTERRUPT, EXTI_TRIG_RISING); //配置外部上升沿中断 |
| | | exti_init(EXTI_15, EXTI_INTERRUPT, EXTI_TRIG_RISING); //配置外部上升沿中断 |
| | | nvic_irq_enable(EXTI4_15_IRQn, 0U); |
| | | exti_interrupt_flag_clear(EXTI_4 | EXTI_5 | EXTI_15); |
| | | |
| | | //初始化PWM引脚 |
| | | gpio_mode_set(PWM_HIN1_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, PWM_HIN1_PIN); |
| | | gpio_af_set(PWM_HIN1_PORT, GPIO_AF_2, PWM_HIN1_PIN); |
| | | gpio_output_options_set(PWM_HIN1_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, PWM_HIN1_PIN); |
| | | |
| | | gpio_mode_set(PWM_HIN2_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, PWM_HIN2_PIN); |
| | | gpio_af_set(PWM_HIN2_PORT, GPIO_AF_2, PWM_HIN2_PIN); |
| | | gpio_output_options_set(PWM_HIN2_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, PWM_HIN2_PIN); |
| | | |
| | | gpio_mode_set(PWM_HIN3_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, PWM_HIN3_PIN); |
| | | gpio_af_set(PWM_HIN3_PORT, GPIO_AF_2, PWM_HIN3_PIN); |
| | | gpio_output_options_set(PWM_HIN3_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, PWM_HIN3_PIN); |
| | | |
| | | // gpio_mode_set(PWM_LIN1_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, PWM_LIN1_PIN); |
| | | // gpio_af_set(PWM_LIN1_PORT, GPIO_AF_2, PWM_LIN1_PIN); |
| | |
| | | } |
| | | extern uint8_t Get_HallSensorA_State(void) |
| | | { |
| | | return (uint8_t)(gpio_input_bit_get(HALL_SENSOR_A_PORT, HALL_SENSOR_A_PIN)); |
| | | uint8_t rtn = 0; |
| | | rtn = (SET == gpio_input_bit_get(HALL_SENSOR_A_PORT, HALL_SENSOR_A_PIN)) ? 1 : 0; |
| | | return rtn; |
| | | } |
| | | extern uint8_t Get_HallSensorB_State(void) |
| | | { |
| | | return (uint8_t)(gpio_input_bit_get(HALL_SENSOR_B_PORT, HALL_SENSOR_B_PIN)); |
| | | uint8_t rtn = 0; |
| | | rtn = (SET == gpio_input_bit_get(HALL_SENSOR_B_PORT, HALL_SENSOR_B_PIN)) ? 1 : 0; |
| | | return rtn; |
| | | } |
| | | extern uint8_t Get_HallSensorC_State(void) |
| | | { |
| | | return (uint8_t)(gpio_input_bit_get(HALL_SENSOR_C_PORT, HALL_SENSOR_C_PIN)); |
| | | uint8_t rtn = 0; |
| | | rtn = (SET == gpio_input_bit_get(HALL_SENSOR_C_PORT, HALL_SENSOR_C_PIN)) ? 1 : 0; |
| | | return rtn; |
| | | } |
| | |
| | | #include "SEGGER_RTT_Conf.h" |
| | | #include "SEGGER_RTT.h" |
| | | static volatile motor_rotate_t motor_drive = {0}; |
| | | static uint32_t motor_pluse = 0; |
| | | static uint32_t motor_pluse = 1500; |
| | | static volatile uint8_t motor_step = 0; |
| | | static void motor_phasechange(void); |
| | | static void update_speed_dir(uint8_t dir_in); |
| | | |
| | |
| | | exti_interrupt_enable(HALL_B_EXTI); |
| | | exti_interrupt_enable(HALL_C_EXTI); |
| | | StartSpeedTime(); //start speed timer |
| | | motor_phasechange(); // Ö´ÐÐÒ»´Î»»Ïà |
| | | // motor_phasechange(); // Ö´ÐÐÒ»´Î»»Ïà |
| | | |
| | | motor_drive.enable_flag = 1; |
| | | } |
| | |
| | | /* ¶ÁÈ¡»ô¶û´«¸ÐÆ÷ U µÄ״̬ */ |
| | | if (Get_HallSensorA_State()) |
| | | { |
| | | state |= 0x01U << 0; |
| | | state |= (0x01U << 0); |
| | | } |
| | | |
| | | /* ¶ÁÈ¡»ô¶û´«¸ÐÆ÷ V µÄ״̬ */ |
| | | if (Get_HallSensorB_State()) |
| | | { |
| | | state |= 0x01U << 1; |
| | | state |= (0x01U << 1); |
| | | } |
| | | |
| | | /* ¶ÁÈ¡»ô¶û´«¸ÐÆ÷ W µÄ״̬ */ |
| | | if (Get_HallSensorC_State()) |
| | | { |
| | | state |= 0x01U << 2; |
| | | state |= (0x01U << 2); |
| | | } |
| | | |
| | | return state; // ·µ»Ø´«¸ÐÆ÷״̬ |
| | |
| | | void HAL_HallExti_TriggerCallback(void) |
| | | { |
| | | uint8_t step = 0; |
| | | step = get_hall_state(); |
| | | /* »ñÈ¡»ô¶û´«¸ÐÆ÷Òý½Å״̬,×÷Ϊ»»ÏàµÄÒÀ¾Ý */ |
| | | if (exti_interrupt_flag_get(HALL_A_EXTI | HALL_B_EXTI | HALL_C_EXTI)) // ÅжÏÊÇ·ñÓÉ´¥·¢ÖжϲúÉú |
| | | |
| | | // /* »ñÈ¡»ô¶û´«¸ÐÆ÷Òý½Å״̬,×÷Ϊ»»ÏàµÄÒÀ¾Ý */ |
| | | // if (exti_interrupt_flag_get(HALL_A_EXTI | HALL_B_EXTI | HALL_C_EXTI)) // ÅжÏÊÇ·ñÓÉ´¥·¢ÖжϲúÉú |
| | | // { |
| | | |
| | | // // exti_interrupt_flag_clear(HALL_A_EXTI | HALL_B_EXTI | HALL_C_EXTI); |
| | | // } |
| | | for (step = 0; step < 30; step++) |
| | | { |
| | | // update_motor_speed(step, __HAL_TIM_GET_COMPARE(htim, TIM_CHANNEL_1));//TODO Ö÷¶¨Ê±Æ÷´¦»ñµÃ¼ÆÊýʱ¼ä |
| | | update_motor_speed(step, 300u * GetSpeedTimerOutcnt() + timer_counter_read(TIMER2)); |
| | | SEGGER_RTT_printf(0, "Speed is:%d!\n", motor_drive.speed); |
| | | motor_drive.timeout = 0; |
| | | exti_interrupt_flag_clear(HALL_A_EXTI | HALL_B_EXTI | HALL_C_EXTI); |
| | | } |
| | | motor_step = get_hall_state(); |
| | | // update_motor_speed(step, __HAL_TIM_GET_COMPARE(htim, TIM_CHANNEL_1));//TODO Ö÷¶¨Ê±Æ÷´¦»ñµÃ¼ÆÊýʱ¼ä |
| | | // update_motor_speed(step, 300u * GetSpeedTimerOutcnt() + timer_counter_read(TIMER2)); |
| | | SEGGER_RTT_printf(0, "Hall state is:%d!\n", motor_step); |
| | | motor_drive.timeout = 0; |
| | | // if (RESET != exti_interrupt_flag_get(EXTI_4)) |
| | | // { |
| | | // SEGGER_RTT_printf(0, "HALL_A_EXTI triggle!\n"); |
| | |
| | | // { |
| | | // SEGGER_RTT_printf(0, "HALL_B_EXTI triggle!\n"); |
| | | // } |
| | | motor_phasechange(); |
| | | // motor_phasechange(); |
| | | // HAL_TIM_GenerateEvent(&htimx_bldcm, TIM_EVENTSOURCE_COM); // Èí¼þ²úÉú»»Ïàʼþ£¬´Ëʱ²Å½«ÅäÖÃдÈë |
| | | } |
| | | |
| | |
| | | /* next step: step 2 configuration .A-C` breakover---------------------------- */ |
| | | case 1: |
| | | /* channel U configuration */ |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCX_ENABLE); |
| | | MOTOR_U_L_DISABLE; |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCXN_DISABLE); |
| | |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCXN_DISABLE); |
| | | |
| | | /* channel W configuration */ |
| | | // timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM1); |
| | | // timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCX_DISABLE); |
| | | MOTOR_W_L_ENABLE; |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCXN_ENABLE); |
| | |
| | | MOTOR_U_L_DISABLE; |
| | | |
| | | /* channel V configuration */ |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCX_ENABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCXN_DISABLE); |
| | | MOTOR_V_L_DISABLE; |
| | | |
| | | /* channel W configuration */ |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCX_DISABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCXN_ENABLE); |
| | | MOTOR_W_L_ENABLE; |
| | |
| | | /* next step: step 4 configuration .B-A` breakover---------------------------- */ |
| | | case 3: |
| | | /* channel U configuration */ |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCX_DISABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCXN_ENABLE); |
| | | MOTOR_U_L_ENABLE; |
| | | |
| | | /* channel V configuration */ |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCX_ENABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCXN_DISABLE); |
| | | MOTOR_V_L_DISABLE; |
| | |
| | | /* next step: step 5 configuration .C-A` breakover---------------------------- */ |
| | | case 4: |
| | | /* channel U configuration */ |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCX_DISABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCXN_ENABLE); |
| | | MOTOR_U_L_ENABLE; |
| | |
| | | MOTOR_V_L_DISABLE; |
| | | |
| | | /* channel W configuration */ |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCX_ENABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCXN_DISABLE); |
| | | MOTOR_W_L_DISABLE; |
| | |
| | | MOTOR_U_L_DISABLE; |
| | | |
| | | /* channel V configuration */ |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCX_DISABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCXN_ENABLE); |
| | | MOTOR_V_L_ENABLE; |
| | | |
| | | /* channel W configuration */ |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_W, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCX_ENABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_W, TIMER_CCXN_DISABLE); |
| | | MOTOR_W_L_DISABLE; |
| | |
| | | /* next step: step 1 configuration .A-B` breakover---------------------------- */ |
| | | case 6: |
| | | /* channel U configuration */ |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_U, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCX_ENABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_U, TIMER_CCXN_DISABLE); |
| | | MOTOR_U_L_DISABLE; |
| | | |
| | | /* channel V configuration */ |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, MOTOR_OUT_CH_V, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCX_DISABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, MOTOR_OUT_CH_V, TIMER_CCXN_ENABLE); |
| | | MOTOR_V_L_ENABLE; |
| | |
| | | extern void stop_pwm_output(void) |
| | | { |
| | | timer_channel_output_state_config(TIMER0, TIMER_CH_0, TIMER_CCX_DISABLE); |
| | | timer_channel_complementary_output_state_config(TIMER0, TIMER_CH_0, TIMER_CCXN_DISABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, TIMER_CH_0, TIMER_CCXN_DISABLE); |
| | | timer_channel_output_state_config(TIMER0, TIMER_CH_1, TIMER_CCX_DISABLE); |
| | | timer_channel_complementary_output_state_config(TIMER0, TIMER_CH_1, TIMER_CCXN_DISABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, TIMER_CH_1, TIMER_CCXN_DISABLE); |
| | | timer_channel_output_state_config(TIMER0, TIMER_CH_2, TIMER_CCX_DISABLE); |
| | | timer_channel_complementary_output_state_config(TIMER0, TIMER_CH_2, TIMER_CCXN_DISABLE); |
| | | // timer_channel_complementary_output_state_config(TIMER0, TIMER_CH_2, TIMER_CCXN_DISABLE); |
| | | MOTOR_W_L_DISABLE; |
| | | MOTOR_V_L_DISABLE; |
| | | MOTOR_U_L_DISABLE; |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | /* ÉèÖö¨Ê±Æ÷ͨµÀÊä³ö PWM µÄÕ¼¿Õ±È */ |
| | | motor_pluse = pulse; |
| | | //SetPwmDuty(); |
| | | SetPwmDuty(TIMER_CH_0, motor_pluse); |
| | | SetPwmDuty(TIMER_CH_1, motor_pluse); |
| | | SetPwmDuty(TIMER_CH_2, motor_pluse); |
| | | |
| | | if (motor_drive.enable_flag) |
| | | { |
| | | motor_phasechange(); |
| | |
| | | { |
| | | // PWM_TIMx_Configuration(); // µç»ú¿ØÖƶ¨Ê±Æ÷£¬Òý½Å³õʼ»¯ |
| | | // hall_tim_config(); // »ô¶û´«¸ÐÆ÷³õʼ»¯ |
| | | sd_gpio_config(); // sd Òý½Å³õʼ»¯ |
| | | // sd_gpio_config(); // sd Òý½Å³õʼ»¯ |
| | | // Set_SDH2136_Enable(); |
| | | Set_SDH2136_Disable(); |
| | | bldcm_data.direction = MOTOR_FWD; |
| | | bldcm_data.is_enable = 1; |
| | | bldcm_data.dutyfactor = 1500; |
| | | } |
| | | |
| | | /** |
| | |
| | | if (RESET != exti_interrupt_flag_get(EXTI_4 | EXTI_5 | EXTI_15)) |
| | | { |
| | | HAL_HallExti_TriggerCallback(); |
| | | } |
| | | |
| | | exti_interrupt_flag_clear(EXTI_4 | EXTI_5 | EXTI_15); |
| | | } |
| | | } |
| | | |
| | | /*! |
| | | \brief this function handles time2 |
| | |
| | | #include "bsp_pid.h" |
| | | #include "os_task.h" |
| | | #include "RttTask.h" |
| | | #include "SEGGER_RTT_Conf.h" |
| | | #include "SEGGER_RTT.h" |
| | | |
| | | static void Comm_Task(void *p) |
| | | { |
| | | // uint8_t step = 0; |
| | | // step = get_hall_state(); |
| | | // SEGGER_RTT_printf(0, "Hall state is:%d!\n", step); |
| | | } |
| | | |
| | | int main() |
| | |
| | | *****************************************************************************************************/ |
| | | static void Timer0Init(void) |
| | | { |
| | | uint16_t Duty = PERIOD_CMP / 10; |
| | | uint16_t Duty = PERIOD_CMP / 2; |
| | | timer_parameter_struct timercontralcfg; |
| | | timer_oc_parameter_struct timeroutcfg[3]; |
| | | timer_break_parameter_struct timer_breakpara; |
| | |
| | | timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_1, Duty); |
| | | timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_2, Duty); |
| | | |
| | | timer_channel_output_mode_config(TIMER0, TIMER_CH_0, TIMER_OC_MODE_PWM1); //set pwm1 mode first low then high |
| | | timer_channel_output_mode_config(TIMER0, TIMER_CH_1, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, TIMER_CH_2, TIMER_OC_MODE_PWM1); |
| | | timer_channel_output_mode_config(TIMER0, TIMER_CH_0, TIMER_OC_MODE_PWM0); //set pwm1 mode first low then high |
| | | timer_channel_output_mode_config(TIMER0, TIMER_CH_1, TIMER_OC_MODE_PWM0); |
| | | timer_channel_output_mode_config(TIMER0, TIMER_CH_2, TIMER_OC_MODE_PWM0); |
| | | |
| | | timer_channel_output_shadow_config(TIMER0, TIMER_CH_0, TIMER_OC_SHADOW_ENABLE); //shadow ENable |
| | | timer_channel_output_shadow_config(TIMER0, TIMER_CH_1, TIMER_OC_SHADOW_ENABLE); |
| | | timer_channel_output_shadow_config(TIMER0, TIMER_CH_2, TIMER_OC_SHADOW_ENABLE); |
| | | |
| | | /* configure TIMER break function */ |
| | | timer_break_struct_para_init(&timer_breakpara); |
| | | /* automatic output enable, break, dead time and lock configuration*/ |
| | | timer_breakpara.runoffstate = TIMER_ROS_STATE_DISABLE; |
| | | timer_breakpara.ideloffstate = TIMER_IOS_STATE_DISABLE; |
| | | timer_breakpara.deadtime = 255; |
| | | timer_breakpara.breakpolarity = TIMER_BREAK_POLARITY_LOW; |
| | | timer_breakpara.outputautostate = TIMER_OUTAUTO_ENABLE; |
| | | timer_breakpara.protectmode = TIMER_CCHP_PROT_0; |
| | | timer_breakpara.breakstate = TIMER_BREAK_ENABLE; |
| | | timer_break_config(TIMER0, &timer_breakpara); |
| | | // /* configure TIMER break function */ |
| | | // timer_break_struct_para_init(&timer_breakpara); |
| | | // /* automatic output enable, break, dead time and lock configuration*/ |
| | | // timer_breakpara.runoffstate = TIMER_ROS_STATE_DISABLE; |
| | | // timer_breakpara.ideloffstate = TIMER_IOS_STATE_DISABLE; |
| | | // timer_breakpara.deadtime = 32; |
| | | // timer_breakpara.breakpolarity = TIMER_BREAK_POLARITY_LOW; |
| | | // timer_breakpara.outputautostate = TIMER_OUTAUTO_ENABLE; |
| | | // timer_breakpara.protectmode = TIMER_CCHP_PROT_0; |
| | | // timer_breakpara.breakstate = TIMER_BREAK_DISABLE; |
| | | // timer_break_config(TIMER0, &timer_breakpara); |
| | | |
| | | timer_primary_output_config(TIMER0, ENABLE); |
| | | timer_auto_reload_shadow_enable(TIMER0); |
| | |
| | | |
| | | void SetPwmDuty(uint16_t ch, uint32_t duty) |
| | | { |
| | | uint32_t duty_temp = (PERIOD_CMP >= duty) ? (PERIOD_CMP - duty) : 0; |
| | | // uint32_t duty_temp = (PERIOD_CMP >= duty) ? (PERIOD_CMP - duty) : 0; |
| | | timer_channel_output_pulse_value_config(TIMER0, ch, duty); |
| | | } |
| | | |