ULTRASONIC INTERFACE USING TIMER

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at https://www.dialog-semiconductor.com/support . We’ll be fixing bugs / optimising the searching and tagging over the coming days.
5 posts / 0 new
Last post
balaji
Offline
Last seen: 12 months 11 hours ago
Joined: 2019-12-06 06:48
ULTRASONIC INTERFACE USING TIMER

Hi 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, 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();

 

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

 

PM_Dialog
Offline
Last seen: 2 months 2 weeks ago
Staff
Joined: 2018-02-08 11:03
Hi Balaji,

Hi Balaji,

Thanks for your question online. Let me check it and I’ll get back to you with my comments.

Thanks, PM_Dialog

PM_Dialog
Offline
Last seen: 2 months 2 weeks ago
Staff
Joined: 2018-02-08 11:03
i Balaji,

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();
}

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?

You should be able to read inside the ISR. Please 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

balaji
Offline
Last seen: 12 months 11 hours ago
Joined: 2019-12-06 06:48
Hi Dialog,

Hi Dialog,

Its actually a timer latency problem. I read Adc_smple inside 12.5 micro second ISR timer but , when i checkded with MDO for each adc_get_sample() API with correction it takes 60 micro 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.

PM_Dialog
Offline
Last seen: 2 months 2 weeks ago
Staff
Joined: 2018-02-08 11:03
Hi Balaji,

Hi Balaji,

Thanks for your indication and glad that you got it working. If you have any follow up question, please raise a new forum thread.

Thanks, PM_Dialog