6 months ago
ULTRASONIC INTERFACE USING TIMER
Posted by巴拉吉0 points 4 repliesHi Dialog,
Our product is obstacle detection for Blind People. To upgrrade to BLE based device we choose DA14531 module.
主要由超声波传感器、蜂鸣器、触觉振动器、电池组成。
I'm trying to interface the following Ultrasonic sensor 400 S/T R 100. To generate 40 KHz burst of pulses, I configured timer 0 without PWM. I created a counter inside ISR of timer to generate transmission pulse. which I did it successfully(Refer attachment). Now after a delay of 1ms inside ISR , I'm calling adc_get_sample() function. From there I determine distance based on ultrasonic sensor principle. After running few iterations in keil debug mode .It got stuck in
static inline void dlg_error_isr(void)
{
ASSERT_WARNING(0);
}
in rwble.cThe project which is choose is BLE Barbone project. I have attached Trigger pulse generated with echo I got when obstacle is placed at 50 cm. As you can see the time interval is 3ms when coverted to distance is approx 51 cm. I have series of queries to implement this in code,
1. I'm not able to read ADC sample inside ISR.
2. What is the accuracy of your ADC ? w.r.to precision in milli voltage.
3. Even when I run an ISR without any above functionality, I'm not able to connect to BLE scanner app.
Timer Configuration
// Enable the Timer0/Timer2 input clock
timer0_2_clk_enable();
timer0_init(TIM0_CLK_FAST, PWM_MODE_ONE, TIM0_CLK_NO_DIV);
// Set the Timer0/Timer2 input clock division factor to 2, so8 MHz input clock
定时器0\u 2\u clk\u div\u set(&clk\u div\u config);
// reload value for 12.5 micro second(T = 1/8 MHz * RELOAD_12.5_US = 0.125 * 100 = 12.5 micro second)
timer0_set_pwm_on_counter(TIMER_ON);
timer0_set_pwm_high_counter(NO_PWM);
定时器0\设置\脉宽调制\低电平\计数器(无\脉宽调制);
// register callback function for SWTIM_IRQn irq
timer0_register_callback(burst_user_callback_function);
// enable SWTIM_IRQn irq
timer0_enable_irq();
ADC配置
// adc configuration
adc_offset_calibrate(ADC_INPUT_MODE_SINGLE_ENDED);
adc_config_t echo_pin_cfg =
{
.input_mode = ADC_INPUT_MODE_SINGLE_ENDED,
.input = ADC_INPUT_SE_P0_6,
.smpl_time_mult = 2,
.continuous = false,
.interval_mult = 0,
.input衰减器=ADC\U input\U ATTN\U 4X,
.chopping = false,
.oversampling = 0
};
adc_init(&echo_pin_cfg);
Could you assist me in integrating this sensor. I need to know how can I run a Timer ISR and BLE service at same time ?
当做,
BALAJI
Attachment | Size |
---|---|
Ultrasonic_Burst_&Echo_MDO_output_images | 792.47 KB |
6 months ago
你好,巴拉吉,
I am trying to replicate this behavior in the ble-app_barebone example of the SDK. So far I am using in order to toggle a gpio in the callback function:
// Timer0 settings #define NO_PWM 0x0 #define TIMER_ON 100 static tim0_2_clk_div_config_t clk_div_config = { .clk_div = TIM0_2_CLK_DIV_2 }; static uint8_t counter = 0; static void burst_user_callback_function(void) { counter++ ; if ( 2 == counter ) { if (GPIO_GetPinStatus(LED_PORT, LED_PIN)) { GPIO_SetInactive(LED_PORT, LED_PIN); } else { GPIO_SetActive(LED_PORT, LED_PIN); } } } void timer_0(void) { // Enable the Timer0/Timer2 input clock timer0_2_clk_enable(); timer0_init(TIM0_CLK_FAST, PWM_MODE_ONE, TIM0_CLK_NO_DIV); // Set the Timer0/Timer2 input clock division factor to 2, so 8 MHz input clock timer0_2_clk_div_set(&clk_div_config); // reload value for 12.5 micro second (T = 1/8 MHz * RELOAD_12.5_US = 0.125 * 100 = 12.5 micro second) timer0_set_pwm_on_counter(TIMER_ON); timer0_set_pwm_high_counter(NO_PWM); timer0_set_pwm_low_counter(NO_PWM); // register callback function for SWTIM_IRQn irq timer0_register_callback(burst_user_callback_function); // enable SWTIM_IRQn irq timer0_enable_irq(); }
Please let me know if I have any misconfiguration. Could you please share the burst_user_callback_function() function that you are using in your application code?
你应该能够阅读ISR内部的信息。请分享为了在ble\u app\u barebone示例中复制这一点,应该做哪些修改。您是否使用任何可用的睡眠模式?
The accuracy of the ADC is given into the datasheet – please check Table 23.
Thanks, PM_Dialog
6 months ago
Hi Dialog,
Its actually a timer latency problem. I read Adc_smple inside12.5微秒的ISR定时器,但是,当我检查了MDO的每一个adc_get_sample() API与修正60micro seconds. As of now there is no isue. Thanks for your suggestion. I will post in this same thread in future if any issue pops up.
Bcoz of this timer issue the BLE connection got blocked. Now its resolved.
6 months ago
你好,巴拉吉,
Thanks for your question online. Let me check it and I’ll get back to you with my comments.
Thanks, PM_Dialog