In your app’s main loop()
  HeartbeatTimer();
The Heartbeat Function
//*******************************
//*******************************
//********** HEARTBEAT **********
//*******************************
//*******************************
void HeartbeatTimer (void)
{
  static uint8_t Heartbeat10msTimer = 0;
  static uint64_t heartbeat_last_1ms_time = 0;


  while ((esp_timer_get_time() - heartbeat_last_1ms_time) >= 1000)      //esp_timer_get_time() provides uS since startup
  {

    //-------------------------------
    //----- HEARTBEAT EVERY 1mS -----
    //-------------------------------
    heartbeat_last_1ms_time += 1000;


    //<<<< Do every 1mS things here


    //-- Toggle pin # test --
    //static uint8_t Toggle = 0;
    //Toggle^= 1;
    //gpio_set_level(GPIO_NUM_4, Toggle);


    Heartbeat10msTimer++;
    if (Heartbeat10msTimer >= 10)
    {
      //-------------------------------
      //----- 10mS HEARTBEARTBEAT -----
      //-------------------------------
      Heartbeat10msTimer = 0;
    
    
      //<<<< Do every 10mS things here
    
    
    } //if (Heartbeat10msTimer > 10)

  }
}
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *