[英]ATMEGA32U4 PWM issue
I am developing a simple program to run a buzzer in AVR on a Teensy 2.0 (ATMEGA32u4) and I am having great difficulty getting the PWM output to work.我正在开发一个简单的程序来在 Teensy 2.0 (ATMEGA32u4) 上运行 AVR 中的蜂鸣器,我很难让 PWM output 工作。 The PWM output is on PB6 and I can test it digitally so I am not worried about the hardware setup of the buzzer. PWM output 在 PB6 上,我可以对其进行数字测试,所以我不担心蜂鸣器的硬件设置。
Eventually, the PWM will have a 50% duty cycle and the frequency will modulate, however, I am more concerned I am not getting any output at this point.最终,PWM 将具有 50% 的占空比并且频率将进行调制,但是,我更担心此时我没有得到任何 output。
I have tried several different PWM setups and even have a second timer running to complete other tasks.我尝试了几种不同的 PWM 设置,甚至还运行了第二个计时器来完成其他任务。
Here is my setup and program skeleton:这是我的设置和程序框架:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
void button_handler(void);
void setup(void)
{
cli(); // Disable interrupts
// Set sysclk to 16 MHz
CLKPR = (1<<CLKPCE); // Prescaler change enable
CLKPR = 0x00; // Set prescaler to zero
DDRB = (1<<DDB6); // configure PORT B6 (buzzer) as output
// initliase timer1
// Fast PWM, TOP = OCR1A, Update OCR1B at TOP, TOV1 flag set on TOP
// Clear OC1B on compare match, set OC1B at TOP
// clkI/O/1 (No prescaling)
TCCR1A = (1<<COM1B1)|(1<<WGM11)|(1<<WGM10);
TCCR1B = (1<<WGM13)|(1<<WGM12)|(1<<CS10);
OCR1A = 1023; // Setup PWM Registers
OCR1B = 511; // 50% duty cycle
sei(); // Enable interrupts
}
int main(void)
{
setup(); // initialise device
for (;;)
{
// runs led blinking on PORTD, removed for simplicity
}
}
Really struggling to see where I am going wrong so any help would be much appreciated!真的很难看到我哪里出错了,所以任何帮助都将不胜感激!
Finally managed a fix coming back after a few months, a simple clean fixed the issue.几个月后终于设法修复了,一个简单的清理解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.