|
|
@@ -69,15 +69,25 @@ void enc_intf_quadrature_init(u32 rate) {
|
|
|
timer_input_capture_config(timer,TIMER_CH_1,&timer_icinitpara);
|
|
|
|
|
|
timer_quadrature_decoder_mode_config(timer ,TIMER_ENCODER_MODE2,TIMER_IC_POLARITY_FALLING, TIMER_IC_POLARITY_RISING);
|
|
|
-
|
|
|
+
|
|
|
+ /* TIMER CH2 PWM input capture configuration */
|
|
|
+ timer_icinitpara.icpolarity = TIMER_IC_POLARITY_RISING;
|
|
|
+ timer_icinitpara.icselection = TIMER_IC_SELECTION_ITS;
|
|
|
+ timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;
|
|
|
+ timer_icinitpara.icfilter = 0;
|
|
|
+ timer_input_capture_config(timer, TIMER_CH_2, &timer_icinitpara);
|
|
|
+ timer_input_trigger_source_select(timer, TIMER_SMCFG_TRGSEL_ITI3);//come from trigger out of time3 which captrue the Z singnal and output to me
|
|
|
+
|
|
|
/* auto-reload preload enable */
|
|
|
timer_auto_reload_shadow_enable(timer);
|
|
|
|
|
|
-
|
|
|
timer_interrupt_flag_clear(timer, TIMER_INT_FLAG_UP);
|
|
|
|
|
|
- //timer_interrupt_enable(timer, TIMER_INT_UP);
|
|
|
- //nvic_irq_enable(ENC_TIMER_IRQ, ENC_TIMER_IRQ_PRIORITY, 0);
|
|
|
+ /* clear channel 0 interrupt bit */
|
|
|
+ timer_interrupt_flag_clear(timer, TIMER_INT_FLAG_CH2);
|
|
|
+ /* channel 0 interrupt enable */
|
|
|
+ timer_interrupt_enable(timer, TIMER_INT_CH2);
|
|
|
+ nvic_irq_enable(ENC_TIMER_IRQ, ENC_I_EXIT_IRQ_PRIORITY, 0);
|
|
|
|
|
|
/* TIMER2 counter enable */
|
|
|
timer_enable(timer);
|
|
|
@@ -141,7 +151,7 @@ void enc_intf_z_counter(void) {
|
|
|
|
|
|
/* TIMER configuration */
|
|
|
timer_struct_para_init(&timer_initpara);
|
|
|
- timer_initpara.prescaler = TIM_CLOCK/PWM_TIME_CLK - 1;
|
|
|
+ timer_initpara.prescaler = 0;
|
|
|
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
|
|
|
timer_initpara.counterdirection = TIMER_COUNTER_UP;
|
|
|
timer_initpara.period = 65535;
|
|
|
@@ -157,20 +167,20 @@ void enc_intf_z_counter(void) {
|
|
|
timer_icinitpara.icfilter = CONFIG_PWM_FILTER_NR;
|
|
|
timer_input_capture_config(timer, ENC_I_TIMER_CHAN, &timer_icinitpara);
|
|
|
|
|
|
- /* slave mode selection: TIMER */
|
|
|
- timer_input_trigger_source_select(timer, TIMER_SMCFG_TRGSEL_CI0FE0);
|
|
|
- timer_slave_mode_select(timer, TIMER_SLAVE_MODE_RESTART);
|
|
|
-
|
|
|
/* select the master slave mode */
|
|
|
- timer_master_slave_mode_config(timer, TIMER_MASTER_SLAVE_MODE_ENABLE);
|
|
|
+ timer_master_slave_mode_config(timer,TIMER_MASTER_SLAVE_MODE_ENABLE);
|
|
|
+ /* TIMER1 update event is used as trigger output */
|
|
|
+ timer_master_output_trigger_source_select(timer,TIMER_TRI_OUT_SRC_CH0); //ch0 as tirgger out to encoder timer
|
|
|
|
|
|
/* auto-reload preload enable */
|
|
|
timer_auto_reload_shadow_enable(timer);
|
|
|
- /* clear channel 0 interrupt bit */
|
|
|
+#if 0
|
|
|
+ /* clear channel 0 interrupt bit */
|
|
|
timer_interrupt_flag_clear(timer, ENC_I_TIMER_INT_FLG);
|
|
|
/* channel 0 interrupt enable */
|
|
|
timer_interrupt_enable(timer, ENC_I_TIMER_IRQ_CH);
|
|
|
nvic_irq_enable(ENC_I_TIMER_IRQ, ENC_I_EXIT_IRQ_PRIORITY, 0);
|
|
|
+#endif
|
|
|
/* TIMER2 counter enable */
|
|
|
timer_enable(timer);
|
|
|
#endif
|
|
|
@@ -180,21 +190,26 @@ __weak void ENC_TIMER_Overflow(void) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+__weak void ENC_ABI_IRQHandler(u32 count) {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
void ENC_TIMER_IRQHandler(void) {
|
|
|
if (SET == timer_interrupt_flag_get(ENC_TIMER, TIMER_INT_FLAG_UP)) {
|
|
|
timer_interrupt_flag_clear(ENC_TIMER, TIMER_INT_FLAG_UP);
|
|
|
ENC_TIMER_Overflow();
|
|
|
}
|
|
|
+ if (SET == timer_interrupt_flag_get(ENC_TIMER, TIMER_INT_CH2)) {
|
|
|
+ timer_interrupt_flag_clear(ENC_TIMER, TIMER_INT_FLAG_CH2);
|
|
|
+ ENC_ABI_IRQHandler(TIMER_CH2CV(ENC_TIMER));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
-__weak void ENC_ABI_IRQHandler(void) {
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
void ABI_I_IRQHandler(void) {
|
|
|
#ifdef ENC_I_IRQ
|
|
|
- ENC_ABI_IRQHandler();
|
|
|
+ ENC_ABI_IRQHandler(TIMER_CNT(ENC_TIMER));
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
@@ -203,7 +218,9 @@ void ENC_I_IRQHandler(void) {
|
|
|
if(SET == timer_interrupt_flag_get(ENC_I_TIMER, ENC_I_TIMER_INT_FLG)){
|
|
|
/* clear channel 0 interrupt bit */
|
|
|
timer_interrupt_flag_clear(ENC_I_TIMER, ENC_I_TIMER_INT_FLG);
|
|
|
- ENC_ABI_IRQHandler();
|
|
|
+#if 0
|
|
|
+ ENC_ABI_IRQHandler(TIMER_CNT(ENC_TIMER));
|
|
|
+#endif
|
|
|
}
|
|
|
#endif
|
|
|
}
|