Skip to content

Commit

Permalink
#32 Setting the US trigger pulse offset and duration inside the 01bsp…
Browse files Browse the repository at this point in the history
…_us_ranging.c file
  • Loading branch information
trifuns committed Jun 21, 2022
1 parent 8f82166 commit d94f55f
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions projects/01bsp_us_ranging/01bsp_us_ranging.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* @brief This is a short example of how to do Ultrasound ranging with HC-SR04 sensor on the DotBot board.
* This code currently works on nRF52840. To use the code on DotBot you need to define different GPIO for US sensor ON and READ pin (trigger and echo) in hc_sr04.c
* The result of the US ranging is passed in the us_callback as the us_reading parameter
*
* @copyright Inria, 2022
*
Expand All @@ -16,7 +17,11 @@
#include "hc_sr04.h"


//=========================== defines =========================================
//=========================== defines ===========================================

// Defines for setting up the trigger pulse width and frequency
#define PULSE_DURATION_MS 0.01
#define PULSE_OFFSET_MS 200

//=========================== prototypes =========================================

Expand All @@ -25,41 +30,42 @@ void timer_callback(void); // callback for timer0 after pulse_of

//=========================== variables =========================================

typedef struct {
NRF_TIMER_Type *timer0; // Pointer to the TIMER structure used for triggering US sensor
NRF_TIMER_Type *timer1; // Pointer to the TIMER structure used for reading the range on the US sensor
} app_vars_t;

NRF_TIMER_Type *timer0; // variable for passing the Timer for sensor trigger
NRF_TIMER_Type *timer1; // variable for passing the Timer for sensor echo measurement

static app_vars_t app_vars;

//=========================== main =========================================

/**
* @brief The program starts executing here.
*/
int main(void) {

timer0 = NRF_TIMER0;
timer1 = NRF_TIMER1;
app_vars.timer0 = NRF_TIMER0;
app_vars.timer1 = NRF_TIMER1;

// uncomment if using this code on DotBot Turn ON the DotBot board regulator
//db_board_init();
db_board_init();

// initilize the US sensor, set callback and chose the timers
hc_sr04_init(&us_callback, &timer_callback, timer0, timer1);
// start ranging
hc_sr04_start();
hc_sr04_init(&us_callback, &timer_callback, app_vars.timer0, app_vars.timer1);

// initial timer settings for the trigger pulse - we can call this function if we want to change the parameters of the pulse
hc_sr04_on_set_trigger(PULSE_DURATION_MS, PULSE_OFFSET_MS);

// start high frequency clock needed for PPI
hfclk_init();

// start ranging
hc_sr04_start();

while (1) {

while (1) {
__WFE();
__SEV();
__WFE();

}

// one last instruction, doesn't do anything, it's just to have a place to put a breakpoint.
__NOP();
}
Expand All @@ -69,9 +75,7 @@ int main(void) {
* The code ends up here every time a new measurement is taken. The new measurement is stored in us_reading argument
*/
void us_callback(uint32_t us_reading) {

__NOP();

}

/**
Expand All @@ -80,9 +84,7 @@ void us_callback(uint32_t us_reading) {
* We could change the pulse_offset_ms here by writting a new value to timer0->CC[0] and timer0->CC[1]
*/
void timer_callback(void) {

__NOP();

}


Expand Down

0 comments on commit d94f55f

Please sign in to comment.