使用 PIC 测量 PWM 输入的占空比?
我正在尝试为 PIC24F 单片机编写一个程序,可以测量脉宽调制输入信号的占空比。有人这样做过吗?最好的方法是什么?
I am trying to write a program for a PIC24F mcu that can measure the duty cycle of a pulse width modulated input signal. Has anyone done this? What would be the best approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能具体取决于您所使用的 PIC24 器件,但某些甚至可能所有 PIC24 器件都包含具有输入捕获功能的定时器硬件(请检查器件的数据手册)。当配置为输入捕获时,这将在输入转换中将定时器计数器值复制到寄存器,然后生成中断。通常,在中断处理程序中,您将复制输入捕获寄存器并为下一个转换设置输入捕获,一旦获得前三个转换,您就可以计算占空比,然后在每次转换时更新它,或者与其他转变相比,复杂性可能会稍微低一些。
It may depend on exactly which PIC24 part you are using, but some and possibly all PIC24 parts include timer hardware with input capture capability (check your part's data sheet). When configured for input capture, this will copy the timer counter value to a register in an input transition, and then generate an interrupt. Typically, in the interrupt handler, you would copy the input capture register and set the input capture up for the next transition, once you have the first three transitions, you can calculate the duty-cycle, and thereafter update it on every transition, or with perhaps a little less complexity every other transition.
如果您有以下条件,则此问题的可能性更简单:
然后只需测量与占空比线性相关的输出电压。
There is a simpler possibility for this problem if you have:
Then just meassure the output voltage which is linearly dependent on your duty cycle.