基于单片机pwm脉冲频率检测

该代码实现了PWM键的读取功能,通过GPIO中断来捕获信号。在中断服务程序中,使用计数器检测PWM脉冲的周期,从而判断PWM的频率。当接收到信号开始和结束的标志时,记录脉冲数并计算时间间隔。此外,还包含了一个测试函数用于打印计数值。

/*

 * pwm_key_read.c

 *

 *  Created on: 2023Äê7ÔÂ10ÈÕ

 *      Author: luo

 */

#include "pwm_key_read.h"

#include "all.h"

#include "MyPrintf.h"

#define T_100us_CNT  19230   //100000ns/5.2ns=19230.7

#define T_10us_CNT  1923   //10000ns/5.2ns=1923.07

#define T_12us_CNT  2307   //12000ns/5.2ns=2307

#define T_500us_CNT  96154  

PWM_KEY_t Pwm_Key;

uint32_t pwm_frc_cnt_buf[MAX_PWM_BUF_LEN];

uint32_t over_time_cnt_time_buf[MAX_PWM_BUF_LEN];


 

//============================add by luo 23-0719 test input pwm frequany========================================

//excute in gpio intruupt

static uint8_t pwm_get_step;

void pwmGpioIsr()

{

  static uint32_t pre_time_systik_10us=0;

  static uint16_t i;

  static uint32_t pwm_cnt=0;

  static uint8_t pwm_H_cnt,pwm_L_cnt;

  static uint32_t   pre_systik_cnt,diff_cnt,diff_cnt1;

  static uint32_t   systik_cnt_start=0,over_time_cnt=0;

  uint32_t cur_time;

  static bool led_flg;

  if(PWM_INTR_CHECK)

  {

    PWM_INTR_CLEAR1;

    PWM_INTR_CLEAR0;

    //----------test speed------------

    #if 1

    led_flg^=1;

    if(led_flg)

    //if(PWM_H_L_CHECK)

    {

        GPIO_Init_way1(GPIO_P1

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值