Compare commits
2 Commits
2c96ee7848
...
646ca87981
Author | SHA1 | Date | |
---|---|---|---|
646ca87981 | |||
c7902a1722 |
@ -5,7 +5,7 @@
|
|||||||
- [x] 超声驱动信号(300KHz 50%duty 5cycles)发送
|
- [x] 超声驱动信号(300KHz 50%duty 5cycles)发送
|
||||||
- [x] PA2/PA3配置为USART0
|
- [x] PA2/PA3配置为USART0
|
||||||
- [x] LED配置存活状态闪烁
|
- [x] LED配置存活状态闪烁
|
||||||
- [ ] 超声反射回波接受与精准计时
|
- [x] 超声反射回波接受与精准计时
|
||||||
|
|
||||||
- 超声波反射回来后到sensor成功接收,GPIO上的反应主要分为两部分,
|
- 超声波反射回来后到sensor成功接收,GPIO上的反应主要分为两部分,
|
||||||
1. 超声波在发送时产生的余震,24V下大概为230us,12V下大概为210us。(前面所说的时间均为比较保守的时间)
|
1. 超声波在发送时产生的余震,24V下大概为230us,12V下大概为210us。(前面所说的时间均为比较保守的时间)
|
||||||
@ -14,3 +14,5 @@
|
|||||||
- [x] 产生一个210-230us可调节的准确延时。(TIMER15配置为1us计一个数,设置重载为需要的时间,产生中断即可。)
|
- [x] 产生一个210-230us可调节的准确延时。(TIMER15配置为1us计一个数,设置重载为需要的时间,产生中断即可。)
|
||||||
- [x] 在产生指定时间的中断服务函数中,开启EXTI0(PA0,sensor信号接收引脚),开启TIMER14(计时计数器,1us计一个数,计算接收到外部中断的时间)
|
- [x] 在产生指定时间的中断服务函数中,开启EXTI0(PA0,sensor信号接收引脚),开启TIMER14(计时计数器,1us计一个数,计算接收到外部中断的时间)
|
||||||
- [ ] 在外部中断服务函数中,产生一个事件或中断,进入到TIMER14的中断
|
- [ ] 在外部中断服务函数中,产生一个事件或中断,进入到TIMER14的中断
|
||||||
|
- [ ] TIMER14不存在F4x系列,改用TIMER16.
|
||||||
|
- [x] 放弃上述流程,多一层中断层,直接在EXTI0的中断服务函数中,直接读取TIMER16的CH_0计数值。
|
@ -69,7 +69,7 @@ void ultrasonic_pwm_out_cycles(const uint8_t cycles);
|
|||||||
void ultrasonic_transmit_delay(const uint16_t micro_second);
|
void ultrasonic_transmit_delay(const uint16_t micro_second);
|
||||||
void recevice_exti_config(void);
|
void recevice_exti_config(void);
|
||||||
void ultrasonic_echo_timer_config(void);
|
void ultrasonic_echo_timer_config(void);
|
||||||
|
void ultrasonic_recevice_config(void);
|
||||||
uint16_t calculate_distance(uint32_t us_value);
|
uint16_t calculate_distance(uint32_t us_value);
|
||||||
|
|
||||||
#endif //ULTRASONIC_DRIVER_H
|
#endif //ULTRASONIC_DRIVER_H
|
||||||
|
@ -123,12 +123,9 @@ void TIMER15_IRQHandler(void) {
|
|||||||
if (timer_interrupt_flag_get(TIMER15, TIMER_INT_FLAG_UP) == SET)
|
if (timer_interrupt_flag_get(TIMER15, TIMER_INT_FLAG_UP) == SET)
|
||||||
{
|
{
|
||||||
timer_interrupt_flag_clear(TIMER15, TIMER_INT_FLAG_UP);
|
timer_interrupt_flag_clear(TIMER15, TIMER_INT_FLAG_UP);
|
||||||
|
|
||||||
exti_interrupt_enable(EXTI_0); // turn on hardware external input interrupt
|
exti_interrupt_enable(EXTI_0); // turn on hardware external input interrupt
|
||||||
|
|
||||||
timer_counter_value_config(TIMER16, 0);
|
timer_counter_value_config(TIMER16, 0);
|
||||||
timer_enable(TIMER16); // turn on timer to calculate the first ultrasonic echo time
|
timer_enable(TIMER16); // turn on timer to calculate the first ultrasonic echo time
|
||||||
|
|
||||||
timer_disable(TIMER15);
|
timer_disable(TIMER15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,13 +134,8 @@ void EXTI0_1_IRQHandler(void) {
|
|||||||
if (exti_interrupt_flag_get(EXTI_0) == SET)
|
if (exti_interrupt_flag_get(EXTI_0) == SET)
|
||||||
{
|
{
|
||||||
exti_interrupt_flag_clear(EXTI_0);
|
exti_interrupt_flag_clear(EXTI_0);
|
||||||
|
|
||||||
capture_value = timer_channel_capture_value_register_read(TIMER16, TIMER_CH_0);
|
capture_value = timer_channel_capture_value_register_read(TIMER16, TIMER_CH_0);
|
||||||
|
|
||||||
// printf("aaa\n");
|
|
||||||
|
|
||||||
timer_disable(TIMER16);
|
timer_disable(TIMER16);
|
||||||
|
|
||||||
exti_interrupt_disable(EXTI_0);
|
exti_interrupt_disable(EXTI_0);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,10 +27,7 @@ int main(void)
|
|||||||
systick_config();
|
systick_config();
|
||||||
/* configure ultrasonic board hardware */
|
/* configure ultrasonic board hardware */
|
||||||
ultrasonic_transmit_config();
|
ultrasonic_transmit_config();
|
||||||
|
ultrasonic_recevice_config();
|
||||||
ultrasonic_transmit_delay(TIME_CORRECTION_US);
|
|
||||||
recevice_exti_config();
|
|
||||||
ultrasonic_echo_timer_config();
|
|
||||||
|
|
||||||
/* ---------- debug start ---------- */
|
/* ---------- debug start ---------- */
|
||||||
|
|
||||||
|
@ -132,8 +132,8 @@ void ultrasonic_transmit_delay(const uint16_t micro_second) {
|
|||||||
timer_initpara.repetitioncounter =0;
|
timer_initpara.repetitioncounter =0;
|
||||||
timer_init(US_TRAN_DELAY_TIMER, &timer_initpara);
|
timer_init(US_TRAN_DELAY_TIMER, &timer_initpara);
|
||||||
|
|
||||||
timer_auto_reload_shadow_enable(US_TRAN_DELAY_TIMER); //使能自动影子重载
|
timer_auto_reload_shadow_enable(US_TRAN_DELAY_TIMER);
|
||||||
timer_interrupt_enable(US_TRAN_DELAY_TIMER, TIMER_INT_UP); // 使能自动重载中断
|
timer_interrupt_enable(US_TRAN_DELAY_TIMER, TIMER_INT_UP);
|
||||||
nvic_irq_enable(TIMER15_IRQn, 1U);
|
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.icpolarity = TIMER_IC_POLARITY_BOTH_EDGE;
|
||||||
timer_icinitpara.icselection = TIMER_IC_SELECTION_INDIRECTTI;
|
timer_icinitpara.icselection = TIMER_IC_SELECTION_INDIRECTTI;
|
||||||
timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;
|
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);
|
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 calculate_distance(uint32_t us_value) {
|
||||||
uint16_t distace = (TIME_CORRECTION_US + us_value) * 17;
|
uint16_t distace = (TIME_CORRECTION_US + us_value) * 17;
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user