readtimecount()

Discussion about writing software for VS1005 and the VSOS Operating System. Also posts about VS1005-related hardware design and device drivers should be posted here.
Post Reply
vinayslone
Senior User
Posts: 38
Joined: Tue 2020-11-10 12:34

readtimecount()

Post by vinayslone » Tue 2020-12-22 9:21

Hello vlsi team,

I am using VS1005 developer board,

I am using ReadTimeCount() function value to create debounce delay !

1.) i want to know what value does it return ?
2.) Is it in millisecond ?
3.) If not then please share any provision to make it in milliseconds !

Thankyou !

Hannu
Senior User
Posts: 133
Joined: Mon 2016-05-30 11:54

Re: readtimecount()

Post by Hannu » Tue 2020-12-22 16:43

vinayslone wrote:
Tue 2020-12-22 9:21
Hello vlsi team,

I am using VS1005 developer board,

I am using ReadTimeCount() function value to create debounce delay !

1.) i want to know what value does it return ?
2.) Is it in millisecond ?
From audio.h:

Code: Select all

/** Return time since startup in TIMER_TICKS (milliseconds). */
u_int32 ReadTimeCount(void);
3.) If not then please share any provision to make it in milliseconds !

Code: Select all

#define NUMBER_OF_BUTTONS 10
u_int16 buttons[NUMBER_OF_BUTTONS] = { 0x00, 0x01, 0x02, /* GPIO0_0..2 */ 0x10, 0x11 /* GPIO1_0..1*/
}, prevState, unProcessedButtons;

void readButtons() {
  u_int16 i, *pin = buttons, bit = 1;
  for(i = 0; i < NUMBER_OF_BUTTONS; i++) {
    u_int16 state = GpioReadPin(*pin++);
    
    if(state && ! (prevState & bit)) {
      Forbid();
      unProcessedButtons |= bit; /* rising edge sensitive */
      Permit();
    }
    if (state) prevState |= bit;
    else prevState &= ~bit;
    bit <<= 1;
  }
}
void proc() {
  u_int16 i, bit = 1;
  for (i = 0; i < NUMBER_OF_BUTTONS; i++) {
    if (unProcessedButtons & bit) {
      DoSomething();
      Forbid();
      unProcessedButtons &= ~bit; /* Now it's processed */
      Permit(); 
    }
    bit <<= 1;
  }
}
I would give something like readButtons() to cyclic be executed by the cyclic task with 10 Hz or similar speed. (see cyclic demo code in roots and sources)
and then in main ui loop I would make something like proc() to process. Please keep stack and cpu time usage small cyclic task context. The unProcessedButtons variable is the only shared resource between the tasks.

Post Reply