How to use 100us interval timer?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I want to attach 2x2 LED matrix to a BCM20737, and implement dynamic lighting.

The following simple code works correctly using with bleapptimer_startFineTimer, but does not work using with hw_timer because the callback function is not called.


I want to use hw_timer because the function shiftRow must be called in 100us interval.

Let me know how to use 100us interval timer.


#define USE_HW_TIMER

// 2x2 LED matrix: 1 is on, 0 is off

static UINT8 matrix[2][2] = {

    { 1, 0 },

    { 0, 1 }

};

// GPIO pins connected to LED matrix

static int col_pins[2] = {2, 13};

static int row_pins[2] = {27, 25};

// row (anode) to light

static int prev_row;

static int next_row;

static void shiftRow() {

    // LOW: previous row (anode)

    int pin = row_pins[prev_row];

    gpio_setPinOutput(pin / 16, pin % 16, GPIO_PIN_OUTPUT_LOW);

    // LOW: cathode of current row

    int col;

    for (col = 0; col < 2; col++) {

        UINT8 val = matrix[next_row][col];

        pin = col_pins[col];

        gpio_setPinOutput(pin / 16, pin % 16, val ? GPIO_PIN_OUTPUT_LOW: GPIO_PIN_OUTPUT_HIGH);

    }

    // HIGH: current row

    pin = row_pins[next_row];

    gpio_setPinOutput(pin / 16, pin % 16, GPIO_PIN_OUTPUT_HIGH);

    prev_row = next_row;

    if (++next_row >= 2)

        next_row = 0;

   

#ifdef USE_HW_TIMER

    hw_timer_start(100);

#endif

}

static void test2x2() {

#if USE_HW_TIMER

    hw_timer_register_timer_expired_callback(shiftRow);

    hw_timer_start(100);

#else

    bleapptimer_startFineTimer(shiftRow, 1);

#endif

}

0 Likes
1 Solution
Anonymous
Not applicable

Hi moicci


As promised, we got the sample code for you.  However do keep in mind that 100us timer will cause you many problems. 


void app_register_callback_and_start_timer(void)

{

       // Register callback to be invoked when it times out.

       hw_timer_register_timer_expired_callback((HW_TIMER_EXPIRED_CALLBACK_FN)timer2_timeoutCallback);

       // Start the timer, set to expire in 100mS

       hw_timer_start(100000);

}

void timer2_timeoutCallback(void)

{

    // ISR context callback when timer expires. Serialize callback to app thread.

    bleappevt_serialize(appirtx_irTxTimerCallback, NULL);

}

int appirtx_irTxTimerCallback(void* unused)

{

    // Timer expired. Restart the HW timer to expire in 100ms.

    hw_timer_start(100000);

    return BLE_APP_EVENT_NO_ACTION;

}


Best,

Kevin

View solution in original post

11 Replies
Anonymous
Not applicable

Can anyone answer?

Thank you in advance.

0 Likes

I believe one of our developers commented that such small intervals will affect the reliability of the overall system...

BCM20737S Timer Module

0 Likes
Anonymous
Not applicable

Hi boont,

boont による書き込み:

I believe one of our developers commented that such small intervals will affect the reliability of the overall system...

BCM20737S Timer Module

I already read the article.

It was mentioned about PWM mainly.

Do you have small sample code using hw_timer?

0 Likes

I will have to consult my developers in our weekly call on this issue.

0 Likes
Anonymous
Not applicable

Thank you boont,

I hope your developers will give help!

0 Likes
Anonymous
Not applicable

Hi moicci,

As boont said in an earlier post, using a 100us timer could cause you some problems. However, we are working on getting the sample code.

-Kevin

0 Likes
Anonymous
Not applicable

Hi moicci


As promised, we got the sample code for you.  However do keep in mind that 100us timer will cause you many problems. 


void app_register_callback_and_start_timer(void)

{

       // Register callback to be invoked when it times out.

       hw_timer_register_timer_expired_callback((HW_TIMER_EXPIRED_CALLBACK_FN)timer2_timeoutCallback);

       // Start the timer, set to expire in 100mS

       hw_timer_start(100000);

}

void timer2_timeoutCallback(void)

{

    // ISR context callback when timer expires. Serialize callback to app thread.

    bleappevt_serialize(appirtx_irTxTimerCallback, NULL);

}

int appirtx_irTxTimerCallback(void* unused)

{

    // Timer expired. Restart the HW timer to expire in 100ms.

    hw_timer_start(100000);

    return BLE_APP_EVENT_NO_ACTION;

}


Best,

Kevin

Anonymous
Not applicable

Good Morning, kwang,

Thank you for the sample code.

Although my evaluation board is now broken.

I will try to test your code when the new board would come.

moicci

0 Likes

moicci

So did you have a chance to check out Kevin's code?

0 Likes
Anonymous
Not applicable

My new evaluation board was arrived and I tested Kevin's code.

I succeeded to use hw_timer and my callback called repeatedly.

Thank you, boont and kevin!

Excellent news.  Thanks for reporting the results to to forum.

0 Likes