- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can anyone answer?
Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I believe one of our developers commented that such small intervals will affect the reliability of the overall system...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi boont,
boont による書き込み:
I believe one of our developers commented that such small intervals will affect the reliability of the overall system...
I already read the article.
It was mentioned about PWM mainly.
Do you have small sample code using hw_timer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will have to consult my developers in our weekly call on this issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you boont,
I hope your developers will give help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Excellent news. Thanks for reporting the results to to forum.