1

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. The PWM output is on PB6 and I can test it digitally so I am not worried about the hardware setup of the buzzer.

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.

I have tried several different PWM setups and even have a second timer running to complete other tasks.

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!

1 Answers1

0

Finally managed a fix coming back after a few months, a simple clean fixed the issue.