ESP32定时器例程解析

/*定时器组例子:有两组定时器,每组有两个

*/


#include <stdio.h>

#include "esp_types.h"

#include "freertos/FreeRTOS.h"

#include "freertos/task.h"

#include "freertos/queue.h"

#include "soc/timer_group_struct.h"

#include "driver/periph_ctrl.h"

#include "driver/timer.h"


#define TIMER_DIVIDER    16 // 分频

#define TIMER_SCALE     (TIMER_BASE_CLK / TIMER_DIVIDER) // 转换为秒计数

#define TIMER_INTERVAL0_SEC (3.4179) // 定时器1时间间隔

#define TIMER_INTERVAL1_SEC (5.78) // 定时器2时间间隔

#define TEST_WITHOUT_RELOAD 0    // 不进行重装载

#define TEST_WITH_RELOAD   1    // 进行重装载


/*

 * A sample structure to pass events

 * from the timer interrupt handler to the main program.

 */

typedef struct {

  int type; // the type of timer's event

  int timer_group;

  int timer_idx;

  uint64_t timer_counter_value;

} timer_event_t;


xQueueHandle timer_queue;


/*

 * A simple helper function to print the raw timer counter value

 * and the counter value converted to seconds

 */

static void inline print_timer_counter(uint64_t counter_value)

{

  printf("Counter: 0x%08x%08x\n", (uint32_t) (counter_value >> 32),

                  (uint32_t) (counter_value));

  printf("Time : %.8f s\n", (double) counter_value / TIMER_SCALE);

}


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值