| | |
| | | * |
| | | */ |
| | | #include "pwm.h" |
| | | #include "bldc_ctrl.h" |
| | | static volatile uint32_t timer_outcnt = 0; |
| | | /***************************************************************************************************** |
| | | Timer2 is used to speed cal |
| | |
| | | |
| | | timer_deinit(TIMER2); |
| | | |
| | | timercontralcfg.prescaler = 4799; //48Mhz /4800 =0.01Mhz = 100us |
| | | timercontralcfg.prescaler = TIMER2_PERIOD; //64Mhz /64 =1Mhz = 1us |
| | | timercontralcfg.alignedmode = TIMER_COUNTER_EDGE; |
| | | timercontralcfg.counterdirection = TIMER_COUNTER_UP; |
| | | timercontralcfg.period = PERIOD_CAP; //100us*10000=1s |
| | | timercontralcfg.period = PERIOD_CAP; //1us*30000=30ms |
| | | |
| | | timer_init(TIMER2, &timercontralcfg); |
| | | timer_interrupt_flag_clear(TIMER2, TIMER_INT_UP); |
| | |
| | | timercontralcfg.period = PERIOD_CMP; // set period(counter value 0~2^15) |
| | | timer_init(TIMER0, &timercontralcfg); |
| | | |
| | | timeroutcfg[0].ocpolarity = TIMER_OC_POLARITY_HIGH; //channel output polarity is high |
| | | timeroutcfg[0].ocpolarity = TIMER_OC_POLARITY_HIGH; //channel output polarity is low |
| | | timeroutcfg[0].ocnpolarity = TIMER_OCN_POLARITY_HIGH; |
| | | timeroutcfg[0].outputstate = TIMER_CCX_ENABLE; //channel enable |
| | | timeroutcfg[0].outputnstate = TIMER_CCXN_DISABLE; //channel complementary DISABLE |
| | | timeroutcfg[0].ocidlestate = TIMER_OC_IDLE_STATE_LOW; |
| | | timeroutcfg[0].ocnidlestate = TIMER_OCN_IDLE_STATE_LOW; |
| | | |
| | | timeroutcfg[1].ocpolarity = TIMER_OC_POLARITY_HIGH; //channel output polarity is high |
| | | timeroutcfg[1].ocpolarity = TIMER_OC_POLARITY_HIGH; //channel output polarity is LOW |
| | | timeroutcfg[1].ocnpolarity = TIMER_OCN_POLARITY_HIGH; |
| | | timeroutcfg[1].outputstate = TIMER_CCX_ENABLE; //channel enable |
| | | timeroutcfg[1].outputnstate = TIMER_CCXN_DISABLE; //channel complementary DISABLE |
| | | timeroutcfg[1].ocidlestate = TIMER_OC_IDLE_STATE_LOW; |
| | | timeroutcfg[1].ocnidlestate = TIMER_OCN_IDLE_STATE_LOW; |
| | | |
| | | timeroutcfg[2].ocpolarity = TIMER_OC_POLARITY_HIGH; //channel output polarity is high |
| | | timeroutcfg[2].ocpolarity = TIMER_OC_POLARITY_HIGH; //channel output polarity is LOW |
| | | timeroutcfg[2].ocnpolarity = TIMER_OCN_POLARITY_HIGH; |
| | | timeroutcfg[2].outputstate = TIMER_CCX_ENABLE; //channel enable |
| | | timeroutcfg[2].outputnstate = TIMER_CCXN_DISABLE; //channel complementary DISABLE |
| | |
| | | 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); |
| | | timer_channel_output_shadow_config(TIMER0, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE); //shadow ENable |
| | | timer_channel_output_shadow_config(TIMER0, TIMER_CH_1, TIMER_OC_SHADOW_DISABLE); |
| | | timer_channel_output_shadow_config(TIMER0, TIMER_CH_2, TIMER_OC_SHADOW_DISABLE); |
| | | |
| | | // /* configure TIMER break function */ |
| | | // timer_break_struct_para_init(&timer_breakpara); |
| | |
| | | } |
| | | extern void TIMER2_IRQHandler_CallBack(void) |
| | | { |
| | | timer_outcnt++; |
| | | if (++timer_outcnt > SPEED_TIMEOUT) |
| | | { |
| | | //to do |
| | | set_bldcm_disable(); |
| | | } |
| | | } |
| | | |
| | | extern uint32_t GetSpeedTimerOutcnt(void) |