没有“计数器"的计数在微控制器中是可能的吗? [英] Counting without "counter" in microcontroller is Possible?

查看:25
本文介绍了没有“计数器"的计数在微控制器中是可能的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,我是微控制器领域的新手,想知道在不使用计数器的情况下是否无法对事件进行计数,我的意思是通过监视连接到事件生成器的引脚.我问这个问题是因为目前我想计算传感器的频率我已经使用 DSO(数字存储示波器)检查了它的频率,它(DSO)说它的频率是 98khz 但是我们现在都知道 8 位计数器的最大值是 255 那么它是如何可能的......传感器连接到PB0(TCNT0/Atmega16的计数器0)......请帮忙

Hello friends i am new in microcontroller domain wants to know is this not possible to counts an events without using counter i mean by monitoring the pin which is connected to the the event generator.i am asking this question because presently i want to calculate the frequency of sensor i have already checked it frequency by using DSO(Digital storage oscilloscope) and it(DSO) says its frequency is 98khz but as we all now that the maximum value of an 8 bit counter is 255 then how it is possible......The sensor is connected to PB0(TCNT0/Counter 0 of Atmega16) .........please help

推荐答案

您可以通过 2 种不同的方式来实现.第一个是使用预分频器.例如,您可以将其设置为 1024,这样每 1024 次触发 PB0(或者正确的术语是什么,自从我处理 MCU 以来已经有一段时间了)计数器增加 1.所以基本上计数器将每隔KHz(大约).

You can do it 2 different ways. The 1st is using the prescaler. You can set it to 1024 for example so every 1024th time PB0 is triggered(or what ever the correct term is, it has been a while since I dealt with MCUs) the counter is incremented by 1. So essentially the counter would be counting every KHz (approximately).

第二种方法是不使用预分频器,而是设置 MCU,这样每次计数器溢出时,您都会将其他寄存器加 1,并且每次该寄存器溢出时,您都会将另一个寄存器加 1.使用 8 位定时器和那些2 个额外的 8 位寄存器,您最多可以数到 16,777,215.我实际上更喜欢第二种方法,但可能只有我一个人这样做:)

The 2nd way is using no prescaler but to set the MCU so that every time the counter overflows you increment some other register by 1, and every time that register overflows you increment another register by 1. Using the 8 bit timer and those 2 additional 8 bit registers you can count up to 16,777,215. I actually prefer this 2nd method but I am probably alone in this : )

还有 Greybeard &Andy Brown 关于 stm32 和微处理器标签是正确的,你应该删除它们.

Also Greybeard & Andy Brown are right about the stm32 and microprocessor tags, u should remove them.

这篇关于没有“计数器"的计数在微控制器中是可能的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆