| | |
| | | * |
| | | */ |
| | | #include "pwm.h" |
| | | |
| | | static volatile uint32_t timer_outcnt = 0; |
| | | /***************************************************************************************************** |
| | | Timer2 is used to speed cal |
| | | APB1 is 64M ,so Timer2 clock is 64M,after prescaler 480 is 0.1M(10us) |
| | |
| | | |
| | | timer_deinit(TIMER2); |
| | | |
| | | timercontralcfg.prescaler = 6399; //64Mhz /6400 =0.01Mhz = 100us |
| | | timercontralcfg.prescaler = 4799; //48Mhz /4800 =0.01Mhz = 100us |
| | | timercontralcfg.alignedmode = TIMER_COUNTER_EDGE; |
| | | timercontralcfg.counterdirection = TIMER_COUNTER_UP; |
| | | timercontralcfg.period = PERIOD_CAP; //100us*10000=1s |
| | |
| | | *****************************************************************************************************/ |
| | | static void Timer0Init(void) |
| | | { |
| | | uint16_t Duty = PERIOD_CMP + 1; |
| | | uint16_t Duty = PERIOD_CMP / 10; |
| | | timer_parameter_struct timercontralcfg; |
| | | timer_oc_parameter_struct timeroutcfg[3]; |
| | | timer_break_parameter_struct timer_breakpara; |
| | |
| | | timeroutcfg[0].ocpolarity = TIMER_OC_POLARITY_HIGH; //channel output polarity is high |
| | | timeroutcfg[0].ocnpolarity = TIMER_OCN_POLARITY_HIGH; |
| | | timeroutcfg[0].outputstate = TIMER_CCX_ENABLE; //channel enable |
| | | timeroutcfg[0].outputnstate = TIMER_CCXN_ENABLE; //channel complementary 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].ocnpolarity = TIMER_OCN_POLARITY_HIGH; |
| | | timeroutcfg[1].outputstate = TIMER_CCX_ENABLE; //channel enable |
| | | timeroutcfg[1].outputnstate = TIMER_CCXN_ENABLE; //channel complementary 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].ocnpolarity = TIMER_OCN_POLARITY_HIGH; |
| | | timeroutcfg[2].outputstate = TIMER_CCX_ENABLE; //channel enable |
| | | timeroutcfg[2].outputnstate = TIMER_CCXN_ENABLE; //channel complementary enable |
| | | timeroutcfg[2].outputnstate = TIMER_CCXN_DISABLE; //channel complementary DISABLE |
| | | timeroutcfg[2].ocidlestate = TIMER_OC_IDLE_STATE_LOW; |
| | | timeroutcfg[2].ocnidlestate = TIMER_OCN_IDLE_STATE_LOW; |
| | | |
| | |
| | | |
| | | void TimerInit(void) |
| | | { |
| | | // rcu_periph_clock_enable(RCU_TIMER2); |
| | | rcu_periph_clock_enable(RCU_TIMER2); |
| | | rcu_periph_clock_enable(RCU_TIMER0); |
| | | Timer0Init(); |
| | | Timer2Init(); |
| | |
| | | { |
| | | timer_disable(TIMER2); |
| | | } |
| | | extern void TIMER2_IRQHandler_CallBack(void) |
| | | { |
| | | timer_outcnt++; |
| | | } |
| | | |
| | | extern uint32_t GetSpeedTimerOutcnt(void) |
| | | { |
| | | uint32_t rtn = timer_outcnt; |
| | | timer_outcnt = 0; |
| | | return rtn; |
| | | } |