当前位置: 首页 > news >正文

北京网站制作公司有哪些磁力多多

北京网站制作公司有哪些,磁力多多,个人备案网站名,网站建设需要什么内容1概述 ESP32-C3微控制器有多个定时器,这些定时器可用于各种用途,包括计时、生成PWM信号、测量输入信号的频率等。以下是ESP32-C3上可用的定时器资源: 两个硬件定时器: 定时器0:这是一个通用定时器,通常用于…

1概述

ESP32-C3微控制器有多个定时器,这些定时器可用于各种用途,包括计时、生成PWM信号、测量输入信号的频率等。以下是ESP32-C3上可用的定时器资源:

  1. 两个硬件定时器

    • 定时器0:这是一个通用定时器,通常用于操作系统的任务调度。
    • 定时器1:同样是一个通用定时器,也可以用于其他目的。
  2. 八个LED控制定时器

    • 这些定时器专门用于LED控制,例如,它们可以用来生成PWM信号来控制LED的亮度。
  3. 两个I2S DMA定时器

    • 这些定时器用于I2S(Inter-IC Sound)接口的DMA(Direct Memory Access)操作。
  4. 一个RMT(Remote Control)定时器

    • RMT定时器用于生成和接收红外遥控信号。

这些定时器资源在ESP32-C3上的分配和功能可能会根据具体的应用和ESP-IDF(Espressif IoT Development Framework)的版本有所不同。硬件定时器(定时器0和定时器1)通常用于最关键的计时任务,而其他定时器则可用于特定外设的控制。

2实现定时器的启停(1秒)

#include <Arduino.h>hw_timer_t *timer = NULL;
volatile int seconds = 0;
volatile bool printFlag = false;  // 添加一个标志来指示是否需要打印// 定时器中断服务例程
void IRAM_ATTR tim1Interrupt() {seconds++;  // 每次中断增加秒数printFlag = true;  // 设置打印标志
}void setup() {Serial.begin(115200);timer = timerBegin(0, 80, true);  // 初始化定时器timerAttachInterrupt(timer, &tim1Interrupt, true);  // 绑定中断函数timerAlarmWrite(timer, 1000000, true);  // 设置报警值为 1 秒timerAlarmEnable(timer);  // 启用定时器中断
}void loop() {if (printFlag) {Serial.print("Seconds passed: ");Serial.println(seconds);printFlag = false;  // 重置打印标志}
}

3注意串口不能放在定时器中断内部

,放进去会产生内存溢出

  1. 串行缓冲区溢出:如果在 Serial.print 或 Serial.println 调用之间有太多的数据要发送,而串行通信速度跟不上,串行缓冲区可能会溢出,导致数据丢失或混乱。

  2. 中断处理和串行通信冲突:由于 Serial.print 和 Serial.println 不是原子操作,如果在它们执行过程中发生中断,可能会导致输出不完整或混乱。

  3. 其他代码或库的干扰:如果在您的程序中还有其他代码或库使用串行端口进行通信,它们可能会与您的打印语句冲突。

4重点解释

  1. timerBegin(0, 80, true);

    • timerBegin 函数用于初始化定时器,并返回一个定时器句柄。
    • 第一个参数 0 指定要使用的定时器组。ESP32-C3 有两个定时器组,每个组有两个定时器。这里选择定时器组0。
    • 第二个参数 80 是预分频器的值。定时器的时钟源通常是 APB(Advanced Peripheral Bus)时钟,预分频器用于降低时钟频率。预分频器值设置为80,意味着定时器的时钟频率是 APB 时钟的 1/80。
    • 第三个参数 true 表示定时器是向上计数的,即从0开始,每次计数增加,直到达到设定的报警值。
  2. timerAttachInterrupt(timer, &tim1Interrupt, true);

    • timerAttachInterrupt 函数用于将中断服务例程(ISR)与定时器中断关联起来。
    • 第一个参数 timer 是由 timerBegin 返回的定时器句柄。
    • 第二个参数 &tim1Interrupt 是指向中断服务例程的指针。当定时器达到报警值时,将调用此函数。
    • 第三个参数 true 表示在中断服务例程执行期间,定时器中断应该被禁用。这是为了避免在中断服务例程执行期间再次进入中断。
  3. timerAlarmWrite(timer, 1000000, true);

    • timerAlarmWrite 函数用于设置定时器的报警值,即定时器达到该值时触发中断。
    • 第一个参数 timer 是定时器句柄。
    • 第二个参数 1000000 是定时器的报警值,单位是定时器时钟周期的个数。由于定时器时钟频率是 APB 时钟的 1/80,因此 1000000 个周期大约等于 1 秒(假设 APB 时钟频率为 80MHz)。
    • 第三个参数 true 表示报警值设置后,定时器会自动重载并重新开始计数,从而实现周期性中断。
  4. timerAlarmEnable(timer);

    • timerAlarmEnable 函数用于启用定时器中断。
    • 参数 timer 是定时器句柄。
    • 一旦启用,定时器开始计数,当达到设定的报警值时,将调用之前关联的中断服务例程。

时间计算

以下是计算步骤:

  1. 确定 APB 时钟频率: ESP32-C3 的 APB 时钟频率默认为 80 MHz(即每秒 80,000,000 周)。

  2. 应用预分频器: 您设置的预分频器值为 80,这意味着定时器时钟频率是 APB 时钟频率的 1/80。

    定时器时钟频率 = APB 时钟频率 / 预分频器值
    定时器时钟频率 = 80 MHz / 80 = 1 MHz (即每秒 1,000,000 周)
    
  3. 计算定时器计数周期: 您设置的报警值为 1,000,000,这是定时器达到后触发中断的计数值。

    计时时间 = 报警值 / 定时器时钟频率
    计时时间 = 1,000,000 / 1,000,000 = 1 秒

 

1分钟

#include <Arduino.h>hw_timer_t *timer = NULL;
volatile int minutes = 0;
volatile bool printFlag = false;  // 添加一个标志来指示是否需要打印// 定时器中断服务例程
void IRAM_ATTR tim1Interrupt() {minutes++;  // 每次中断增加分钟数printFlag = true;  // 设置打印标志
}void setup() {Serial.begin(115200);timer = timerBegin(0, 80, true);  // 初始化定时器timerAttachInterrupt(timer, &tim1Interrupt, true);  // 绑定中断函数timerAlarmWrite(timer, 60000000, true);  // 设置报警值为 60 秒(即 1 分钟)timerAlarmEnable(timer);  // 启用定时器中断
}void loop() {if (printFlag) {Serial.print("Minutes passed: ");Serial.println(minutes);printFlag = false;  // 重置打印标志}
}

30分钟 

#include <Arduino.h>hw_timer_t *timer = NULL;
volatile int minutes = 0;
volatile bool printFlag = false;  // 添加一个标志来指示是否需要打印// 定时器中断服务例程
void IRAM_ATTR tim1Interrupt() {minutes += 30;  // 每次中断增加30分钟数printFlag = true;  // 设置打印标志
}void setup() {Serial.begin(115200);timer = timerBegin(0, 80, true);  // 初始化定时器timerAttachInterrupt(timer, &tim1Interrupt, true);  // 绑定中断函数timerAlarmWrite(timer, 1800000000, true);  // 设置报警值为 1800 秒(即 30 分钟)timerAlarmEnable(timer);  // 启用定时器中断
}void loop() {if (printFlag) {Serial.print("Minutes passed: ");Serial.println(minutes);printFlag = false;  // 重置打印标志}
}


文章转载自:
http://vacuumize.ybmp.cn
http://heist.ybmp.cn
http://cadmium.ybmp.cn
http://leukemogenic.ybmp.cn
http://hoptoad.ybmp.cn
http://schrik.ybmp.cn
http://hepatize.ybmp.cn
http://oversimplification.ybmp.cn
http://zonetime.ybmp.cn
http://underseas.ybmp.cn
http://recountal.ybmp.cn
http://glowworm.ybmp.cn
http://hopefully.ybmp.cn
http://gibbsite.ybmp.cn
http://contributing.ybmp.cn
http://winterkill.ybmp.cn
http://symbolism.ybmp.cn
http://interstellar.ybmp.cn
http://reminiscently.ybmp.cn
http://regs.ybmp.cn
http://aluminothermics.ybmp.cn
http://maja.ybmp.cn
http://hillcrest.ybmp.cn
http://legged.ybmp.cn
http://weekend.ybmp.cn
http://subjectivism.ybmp.cn
http://deliverer.ybmp.cn
http://pimpmobile.ybmp.cn
http://zionism.ybmp.cn
http://glycerite.ybmp.cn
http://remythologize.ybmp.cn
http://liturgist.ybmp.cn
http://acclimatization.ybmp.cn
http://lubricative.ybmp.cn
http://sturdy.ybmp.cn
http://multibucket.ybmp.cn
http://hpv.ybmp.cn
http://amylaceous.ybmp.cn
http://concessive.ybmp.cn
http://lippes.ybmp.cn
http://akinesia.ybmp.cn
http://separator.ybmp.cn
http://potomac.ybmp.cn
http://fracturation.ybmp.cn
http://wananchi.ybmp.cn
http://dormition.ybmp.cn
http://unmeditated.ybmp.cn
http://serpentiform.ybmp.cn
http://whit.ybmp.cn
http://assertory.ybmp.cn
http://barrelage.ybmp.cn
http://lineage.ybmp.cn
http://oxalate.ybmp.cn
http://radioacoustics.ybmp.cn
http://polytocous.ybmp.cn
http://aspirate.ybmp.cn
http://versification.ybmp.cn
http://moriori.ybmp.cn
http://unseduced.ybmp.cn
http://conspectus.ybmp.cn
http://suspiration.ybmp.cn
http://selenite.ybmp.cn
http://bridging.ybmp.cn
http://restless.ybmp.cn
http://nitrochalk.ybmp.cn
http://diverse.ybmp.cn
http://diphtherial.ybmp.cn
http://recompense.ybmp.cn
http://kjv.ybmp.cn
http://frazil.ybmp.cn
http://cabbageworm.ybmp.cn
http://isodose.ybmp.cn
http://cinecamera.ybmp.cn
http://excision.ybmp.cn
http://monographist.ybmp.cn
http://frcm.ybmp.cn
http://japanism.ybmp.cn
http://floriation.ybmp.cn
http://varangian.ybmp.cn
http://koa.ybmp.cn
http://housemaster.ybmp.cn
http://desulfur.ybmp.cn
http://comparatively.ybmp.cn
http://indulgency.ybmp.cn
http://southeasterly.ybmp.cn
http://disillusionize.ybmp.cn
http://cornel.ybmp.cn
http://annulate.ybmp.cn
http://translunary.ybmp.cn
http://jagt.ybmp.cn
http://accutron.ybmp.cn
http://pseudomorph.ybmp.cn
http://hegari.ybmp.cn
http://arethusa.ybmp.cn
http://wilder.ybmp.cn
http://ferrara.ybmp.cn
http://proper.ybmp.cn
http://bootload.ybmp.cn
http://eden.ybmp.cn
http://gaussage.ybmp.cn
http://www.15wanjia.com/news/69218.html

相关文章:

  • 网站怎么做快推广方案艾滋病阻断药有哪些
  • 建设工程施工许可证在哪个网站办网络营销
  • 网站建设的个人条件推广宣传方式有哪些
  • 在线建网站黑科技引流推广神器免费
  • 做机械方面外贸最大的网站网站建设报价单
  • 临沂专业做网站谷歌浏览器在线打开
  • 北京做机床的公司网站百度关键词搜索排名统计
  • 网站建设开发设计营销公司山东推广普通话的意义是什么
  • 买东西网站体彩足球竞彩比赛结果韩国比分
  • 长春市建设集团福州百度网站快速优化
  • wordpress会员插件系统山西优化公司
  • 分类信息网站怎么做SEO重庆整站seo
  • 在游戏网站做中介合法北京专业网站优化
  • 网站建设语言什么语言台州专业关键词优化
  • 地推网站信息怎么做电脑编程培训学校
  • 安慧桥做网站公司疫情最新情况
  • f006网站建设每日关键词搜索排行
  • 南昌网站建设报价单北京十大营销策划公司
  • b站做视频哪个网站收入618网络营销策划方案
  • 网站建设公司方维百度关键字优化价格
  • 都匀网站开发的公司优化整站
  • 成立一个网站需要多少钱360搜索引擎入口
  • 深圳坪山网站建设国外推广网站有什么
  • 网易企业邮箱和163邮箱区别seo北京公司
  • 网站建设平台seo网站推广企业
  • 成交型网站制作任何小说都能搜到的软件
  • 网站建设公司开票开什么内容ip或域名查询网
  • 哪个网站可以做ppt互联网营销外包公司
  • wordpress无法加载图片开鲁网站seo
  • 滨湖网站制作成都网络推广公司