Wrapping the receive configuration functions together
This commit is contained in:
parent
2c96ee7848
commit
c7902a1722
@ -69,7 +69,7 @@ void ultrasonic_pwm_out_cycles(const uint8_t cycles);
|
||||
void ultrasonic_transmit_delay(const uint16_t micro_second);
|
||||
void recevice_exti_config(void);
|
||||
void ultrasonic_echo_timer_config(void);
|
||||
|
||||
void ultrasonic_recevice_config(void);
|
||||
uint16_t calculate_distance(uint32_t us_value);
|
||||
|
||||
#endif //ULTRASONIC_DRIVER_H
|
||||
|
@ -123,12 +123,9 @@ void TIMER15_IRQHandler(void) {
|
||||
if (timer_interrupt_flag_get(TIMER15, TIMER_INT_FLAG_UP) == SET)
|
||||
{
|
||||
timer_interrupt_flag_clear(TIMER15, TIMER_INT_FLAG_UP);
|
||||
|
||||
exti_interrupt_enable(EXTI_0); // turn on hardware external input interrupt
|
||||
|
||||
timer_counter_value_config(TIMER16, 0);
|
||||
timer_enable(TIMER16); // turn on timer to calculate the first ultrasonic echo time
|
||||
|
||||
timer_disable(TIMER15);
|
||||
}
|
||||
}
|
||||
@ -137,13 +134,8 @@ void EXTI0_1_IRQHandler(void) {
|
||||
if (exti_interrupt_flag_get(EXTI_0) == SET)
|
||||
{
|
||||
exti_interrupt_flag_clear(EXTI_0);
|
||||
|
||||
capture_value = timer_channel_capture_value_register_read(TIMER16, TIMER_CH_0);
|
||||
|
||||
// printf("aaa\n");
|
||||
|
||||
timer_disable(TIMER16);
|
||||
|
||||
exti_interrupt_disable(EXTI_0);
|
||||
}
|
||||
}
|
@ -27,10 +27,7 @@ int main(void)
|
||||
systick_config();
|
||||
/* configure ultrasonic board hardware */
|
||||
ultrasonic_transmit_config();
|
||||
|
||||
ultrasonic_transmit_delay(TIME_CORRECTION_US);
|
||||
recevice_exti_config();
|
||||
ultrasonic_echo_timer_config();
|
||||
ultrasonic_recevice_config();
|
||||
|
||||
/* ---------- debug start ---------- */
|
||||
|
||||
|
@ -132,8 +132,8 @@ void ultrasonic_transmit_delay(const uint16_t micro_second) {
|
||||
timer_initpara.repetitioncounter =0;
|
||||
timer_init(US_TRAN_DELAY_TIMER, &timer_initpara);
|
||||
|
||||
timer_auto_reload_shadow_enable(US_TRAN_DELAY_TIMER); //使能自动影子重载
|
||||
timer_interrupt_enable(US_TRAN_DELAY_TIMER, TIMER_INT_UP); // 使能自动重载中断
|
||||
timer_auto_reload_shadow_enable(US_TRAN_DELAY_TIMER);
|
||||
timer_interrupt_enable(US_TRAN_DELAY_TIMER, TIMER_INT_UP);
|
||||
nvic_irq_enable(TIMER15_IRQn, 1U);
|
||||
}
|
||||
|
||||
@ -170,10 +170,16 @@ void ultrasonic_echo_timer_config(void) {
|
||||
timer_icinitpara.icpolarity = TIMER_IC_POLARITY_BOTH_EDGE;
|
||||
timer_icinitpara.icselection = TIMER_IC_SELECTION_INDIRECTTI;
|
||||
timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;
|
||||
timer_icinitpara.icfilter = 0x03; // 设置滤波器
|
||||
timer_icinitpara.icfilter = 0x03;
|
||||
timer_input_capture_config(US_ECHO_TIMER, US_ECHO_CH, &timer_icinitpara);
|
||||
}
|
||||
|
||||
void ultrasonic_recevice_config(void) {
|
||||
ultrasonic_transmit_delay(TIME_CORRECTION_US);
|
||||
recevice_exti_config();
|
||||
ultrasonic_echo_timer_config();
|
||||
}
|
||||
|
||||
uint16_t calculate_distance(uint32_t us_value) {
|
||||
uint16_t distace = (TIME_CORRECTION_US + us_value) * 17;
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user