ESP32-S3 Arduino Version3.4 Timer #10605
harvey9408
started this conversation in
Question - Community Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In ESP32-S3 Arduino Version3.4 libraries,the timer channel is not specified in the function “timerBegin()” .
So,How do I turn on both timers at the same time? The following is my code, but it frequently crashes and restarts after booting.
//////////////////////////////////////////////////////////////////////////////////////
#include "timer.h"
#include "pmut.h"
volatile uint8_t timer_flag = 0;
hw_timer_t *timer0 = NULL;
hw_timer_t *timer1 = NULL;
volatile uint64_t t_pmut_start = 0;
/**
@brief 定时器TIMX定时中断初始化函数
@note
@param val: 自动重装值
@param t_clk: 时钟预分频数
@RetVal 无
*/
void tim0_int_init(uint32_t val, uint32_t t_clk)
{
// 初始化定时器对象,返回值为结构体指针
timer0 = timerBegin(t_clk); // 定义定时器时钟频率
timerAttachInterrupt(timer0, &onTimerISR0); // 定义目标定时器结构体指针,定时器中断回调函数
// 使能定时器
timerAlarm(timer0, val, true, 0); // 定义目标定时器结构体指针,计数值,自动重装载
}
void tim1_int_init(uint32_t val, uint32_t t_clk)
{
// 初始化定时器对象,返回值为结构体指针
timer1 = timerBegin(t_clk); // 定义定时器时钟频率
}
/**
*/
void IRAM_ATTR onTimerISR0(void)
{
if(timer_flag == 0) // 开始发送脉冲的时候,记录初始时间
{
t_pmut_start = micros();
}
PMUT_TOGGLE(); //
timer_flag++;
if(timer_flag == 16) // 输出8个40kHz周期脉冲
{
timerEnd(timer0); // 暂停计数器,等数据处理完之后再重启计数器
}
}
void IRAM_ATTR onTimerISR1(void)
{
tim0_int_init(25, 2000000);
Beta Was this translation helpful? Give feedback.
All reactions