6 months ago
ULTRASONIC INTERFACE USING TIMER
Posted bybalaji0 points 4 repliesHi Dialog,
Our product is obstacle detection for Blind People. To upgrrade to BLE based device we choose DA14531 module.
Componets are ultrasonic sensor , buzzer , haptic vibrator , battery.
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
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();
ADC Configuration
// 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_attenuator = ADC_INPUT_ATTN_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 ?
Regards,
BALAJI
Attachment | Size |
---|---|
Ultrasonic_Burst_&Echo_MDO_output_images | 792.47 KB |
6 months ago
Hi Balaji,
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(); }
请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阅读。请share what modifications should be done in order to replicate this in the ble_app_barebone example. Are you using any of the available sleep modes?
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.5micro second ISR timer but , when i checkded with MDO for eachadc_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
Hi Balaji,
Thanks for your question online. Let me check it and I’ll get back to you with my comments.
Thanks, PM_Dialog