找回密码
 立即注册
×

00:00:00

您有一张0.1元限时体验卡,马上领取获得VIP尊享特权。

15W408AS PCA捕获测频率,只能600Hz-180KHz,指导

2025-8-26 11:19 来自 Printy陈 发布 @ 综合讨论

总思路是:PCA中断后记录捕获数据6次,包括中断PCA计数组(6位)、PCA溢出数组(6位),然后关断PCA捕获,将数据处理计算出频率。现在可以在600Hz-180Khz,低频问题,应该是溢出没有处理好,但高频是怎么回事,头大,外部晶振已经是35Mhz,我用串口调试助手打印,发现PCA停止不了,中断次数不是0-5,而是很大。


//此版本可以基本测量频率,35MHz时钟 1T 最高可测到190Khz,再高频率就不对了,以下是源代码,理论来讲35Mhz,怎么也得捕获M级的频率了。
measurement_active = 0;  // 暂停捕获 我用CR=0,CMOD &= ~(1 << 0);都试过PCA关断不了,index 数据很大。
串口信息如下Capture index: 1536                    Capture index: 256                    Capture index: 512                    Capture index: 768                    Capture index: 1024                    Capture index: 1280                    Capture index: 1536                    Capture index: 256                    Capture index: 512                    Capture index: 768                    Capture index: 1024                    Capture index: 1280                    Capture index: 1536                    Capture index: 256                    Capture index: 512                    Capture index: 768                    Capture index: 1024                    Capture index: 1280                    Capture index: 1536                    Capture index: 256

#include <STC15.h>
#include <intrins.h>
#include <stdio.h>

// 引脚定义
sbit RS = P3^2;
sbit RW = P3^3;
sbit EN = P3^4;
sbit LED_IND = P3^7;
#define DATA_PORT P1

// 全局变量 - 优化内存使用
volatile unsigned long pca_overflow_count = 0;
volatile bit new_capture = 0;
volatile unsigned char capture_index = 0;     // 当前捕获索引
volatile bit capture_complete = 0;           // 6次捕获完成标志
volatile bit measurement_active = 1;          // 测量激活标志

// 6次捕获数据存储 - 移到xdata段节省DATA空间
volatile unsigned int xdata capture_values;      // 6次捕获值
volatile unsigned long xdata overflow_counts;    // 6次溢出计数

// 捕获处理变量
volatile unsigned long last_capture_value = 0;
volatile unsigned long overflow_at_last_capture = 0;
volatile bit first_capture = 1;

unsigned char display_buffer;  // 优化:刚好8字符,节省1字节
unsigned char i;
// 串口初始化 - 使用定时器2作为波特率发生器
void uart_init() {
    // 设置串口引脚
    P3M0 &= ~(1 << 0);  // P3.0 输入
    P3
  • 最近查阅:

免责声明:

本平台旨在开源共享精神,请勿发布敏感信息,任何违法信息我们将移交公安机关;

QQ|手机版|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-9-16 16:07 , Processed in 0.086238 second(s), 48 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

返回顶部