HiRes Timer example?
Posted: Tue Apr 19, 2016 4:02 pm
Hello all,
I try to setup a microsecond timer, but I can't get it work.
Independent from setting the 4th param in ets_timer_arm() to 0 or 1, timeout is always 1000ms and not as expected 1000 µs.
Any idea?
Thanks in advance
- StevieBread -
I try to setup a microsecond timer, but I can't get it work.
Independent from setting the 4th param in ets_timer_arm() to 0 or 1, timeout is always 1000ms and not as expected 1000 µs.
Code: Select all
#include "user_interface.h"
#include "osapi.h"
#include "ets_sys.h"
ETSTimer MyHwTimer;
// ------------------------------
void MyTimerFunc(void* pTimerArg)
// ------------------------------
{
static bool bOn = false;
bOn = !bOn;
digitalWrite(14, bOn ? 1 : 0);
}
// --------------------------------------------
void setup()
// --------------------------------------------
{
system_timer_reinit();
pinMode(14, OUTPUT); // configure GPIO14 as output
digitalWrite(14, 0); // LED on
ets_timer_setfn(&MyHwTimer, MyTimerFunc, NULL);
ets_timer_arm_new(&MyHwTimer, 1000, 1, 0); // this results in 1000 ms
//ets_timer_arm_new(&MyHwTimer, 1000, 1, 1); // and this is also 1000 ms
}
// --------------------------------------------
void loop()
// --------------------------------------------
{
}
Any idea?
Thanks in advance
- StevieBread -