本文介绍了为什么VirtualWire与Arduino/ATmega328引脚D10中的PWM信号冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试了我使用类似Arduino的板和ATmega328制作的硬件原型后,我注意到RF库 VirtualWire 禁用引脚D10中的PWM信号. 为什么?

After debugging a hardware prototype I'm making with an Arduino-like board and ATmega328, I noticed that the RF library VirtualWire disables PWM signal in pin D10. Why is that?

如果我注释掉下面的代码位,则D10引脚上的AnalogWrite(PWM)再次起作用:

If I comment out the bit of code below, analogWrite (PWM) on pin D10 works again:

setup() {
  ...
  vw_set_rx_pin(2);
  vw_setup(2000);    // Bits per sec
  vw_rx_start();       // Start the receiver PLL running

  analogWrite(10, 180);
  ...
}

推荐答案

VirtualWire通过OCR1A在计时器1上使用CTC,这会完全禁用OC1A(在D9上)和OC1B(在D10上)的PWM操作,并阻止OC1A自由运行. OC1B仍然可以使用,但只能在CTC规定的模式下以VirtualWire设置为计时器的速率使用.

VirtualWire uses CTC on timer 1 via OCR1A, which both completely disables PWM operation for OC1A (on D9) and OC1B (on D10) and prevents OC1A from operating freely. OC1B is still usable, but only in the modes prescribed by CTC at the rate programmed into the timer by VirtualWire.

这篇关于为什么VirtualWire与Arduino/ATmega328引脚D10中的PWM信号冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 19:49