Wednesday, June 21, 2017

1. Introduction
- Inblinky demo we use delay() function to make the LED blink. In this demo we will replcae delay() function by using Timer (this is hardware timer). Using Timer we can schedule when a task need to be started and repeat or not. Applying to this demo, when the Timer is timeout we will change the current state of LED (ON to OFF to ON) every 1 second.2. Hardware

Figure: ESP32 connect to LED

Connection:
[ESP32 IO14 and ESP32 GND to LED]3. Software
In order to use Timer we will use the functions:"hw_timer_t * timerBegin(uint8_t num, uint16_t divider, bool countUp)"+ num: is order of Timer. We only have 4 timers so the order can be 0,1,2,3.+ divider: it is a prescaler. To make 1 second scheduler, we will use divider value is 80. ESP32 main clock is 80MHZ so every tick will take T = 1/(80MHZ/80) = 1 microsecond. We need 1000000 ticks for 1 second.+ countUp: if it is true the timer will count up and vice versa."void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge)"+ fn: is the callback function that will be invoked when timer timeout and timer interrupt will be invoked.
+ edge: if it is true, an alarm will generate an edge type interrupt."void timerAlarmWrite(hw_timer_t *timer, uint64_t alarm_value, bool autoreload)"
+ alarm_value: we set it to 1000000 as calculated above
+ autoreload: if it is true, timer will repeat."void timerAlarmEnable(hw_timer_t *timer)": enable the Timer.