4 years ago.

Updating Ticker Value on every call

I need a ticker with initially loaded with 40 usec.

after each call i need to update the ticker to for example x,y,.... usec.

can any one give some idea on this..

Note: I need to implement with ticker only. please.

1 Answer

4 years ago.

Why with a ticker? A timeout would make more sense.

A Timeout is a ticker which will only fire once. In the function that gets called you can then set a new timeout for your next required length of time.

Yes, pls find the below code for understanding of what I am needed:

Variable.attach_us(&ISR_1, 40); In this for every one Ticker call, 40 should be changed to 30, 20 or some value etc.,

I understood the point.

Please find the attached code , what I am asking:

<<code title=update ticker/timeout rate>>

  1. include "mbed.h" <<variable declaration: Timeout X; void y(void) { }

int main() { x.attach_us(&y, 30) }>>

now, I need this 30 to be changed every time, till I reach some value. This should be implemented in y, along with some other operations in y.

Please help me.

posted by Rk c 19 Jan 2018

Timeout myTimeout;

volatile int lastTimeout = 40; 

void onTimeout(void) { 
  switch (lastTimeout) {  // find the next timeout time
    case 40: lastTimeout = 30; break;
    case 30: lastTimeout = 20; break;
    case 20: lastTimeout = 10; break;
    default: lastTimeout = 40; break;  // if some value other than those above use 40.
  }
  myTimeout.attach_us(&onTimeout, lastTimeout);  // set the timeout

   // do stuff
}

main () {
  myTimeout.attach_us(&onTimeout, lastTimeout);

  while(1) {
  }
}

On a side note, you've been asking questions for a while now, all about fairly basic stuff.

One or two simple questions like this are fine but please in the future please make an attempt yourself and then ask for help posting what you have so far rather than just saying "I don't know how to do this, please do it for me."

posted by Andy A 19 Jan 2018