I'm trying to understand how timers work in this board.
I want to make a simple led blink after X amount of microseconds and then keep the led on for X amount of microseconds
stimer_t _timer;
void setup() {
_timer.timer = TIM3; //84Mhz
TimerHandleInit(&_timer, 60000, ??);
attachIntHandle(&_timer,TimerTestIsr);
}
volatile bool isOn = false;
static void TimerTestIsr(stimer_t *timer) {
UNUSED(timer);
//just to mesure time
previusTime = nowTime;
nowTime = micros();
if (isOn == false) {
digitalWrite(LedPin, HIGH);
isOn = true;
setTimerCounter(&_timer,(65535 - 1234)); //so the counter will start from 64301 till 65535 is 1234
}
else {
//on the next trigger it will shutdown the led
digitalWrite(LedPin, LOW);
isOn == false;
}
}
As I understand the timer can go up to 65535 and then overflows to trigger the interrupt. But I'm strugling to understand how to set the prescaler for 1us or 1ms or 1sec. So what I want to do exactly is set the prescaler so every time the counter increase its 1us or what ever time I want. So if the counter is 50000 I want this to be a delay of 50000us.
Best Answer
I think I solved that, but I had to mix some functions because for some reason I wasn't able to trigger the interrupt by setting TIM registers only