Hi Paul,
Yes, you are right, the timers/tickers are only really designed for us-second durations; they all use a shared running 32-bit modulo counter running at 1us/tick, so whilst you can use as many timers as you want at any time to time/trigger things, the delay for a particular tick/timeout can't be greater than approximately 30 minutes (2^31/1x10^6 seconds) .
For minutes/hours, the real time clock/time functionality is a good bet, as it is designed to work on seconds and foreverer(!).
Note, the real-time clock can't trigger an interrupt using the mbed API unfortunately. This reminds me that it was discussed and some ideas for an API but it never got added to the todo list; would be interesting if it would achieve what you want, as it probably should be:
In the mean time to get something working, there are probably a couple of solutions depending on desires of quickest vs. neatest:
- Set a ticker to tick every minute, and in the handler, check the realtime clock using time()
- Write to the underlying RTC peripheral's match registers to setup an interrupt to be triggered (i.e. dive in to the LPC17xx User Manual/Low Level)
Hope that is helpful, and would be interested in your feedback,
Simon
Hi,
I'm new to mbed and its been a very long time since I wrote any c/c++ too. I'm having some issues with understanding the Ticker.
I am trying to make something which reads a sensor every hour and post it over HTTP. But...I can't make the Ticker fire every hour. I removed all the sensor code and the HTTPClient code, but it still doesn't work. Instead what is happening is that the handler is called first one hour after startup, and thereafter every 25mins, 15seconds. Can anyone tell me why?
As a slightly different note, eventually I need to be able to make a callback happen at a certain time, no matter what the startup time, for example if I wanted to turn on some lights at 9pm every day and off again at 12pm. I read in another post that Tickers don't work for more than 1hr 11min so I realise that I could calculate the time offset between now and 9pm, but I still can't attach that delay to a ticker by the sound of it.
TIA, Paul