I tried a AVR demo for a rising & falling tone output (files attached).
In older versions (e.g. 0.4.15-RC7) the sound output works fine, in 0.5.16-RC8 there seems no PWM output on the pin available.
In older versions (e.g. 0.4.15-RC7) the sound output works fine, in 0.5.16-RC8 there seems no PWM output on the pin available.
- Code:
// Deklarationen ==============================================================
// Festlegung der Quarzfrequenz
#ifndef F_CPU // optional definieren
#define F_CPU 12288000UL // ATmega 328 mit 12,288 MHz Quarz
#endif
// Include von Header-Dateien
#include <avr/io.h> // I/O Konfiguration (intern weitere Dateien)
#include <util/delay.h> // Definition von Delays (Wartezeiten)
// Konstanten
#define MIN_PER 59 // minimale Periodendauer in "Timerticks"
#define MAX_PER 255 // maximale Periodendauer in "Timerticks"
#define WAIT_TIME 2000 // Wartezeit zwischen Flanken in ms
// Makros
#define SET_BIT(PORT, BIT) ((PORT) |= (1 << (BIT))) // Port-Bit Zustand setzen
#define CLR_BIT(PORT, BIT) ((PORT) &= ~(1 << (BIT))) // Port-Bit Zustand loeschen
#define TGL_BIT(PORT, BIT) ((PORT) ^= (1 << (BIT))) // Port-Bit Zustand wechseln (toggle)
// Funktionsprototypen
// Hauptprogramm ==============================================================
int main()
{
DDRB |= (1<<DDB0); // Port B, Pin 0 (zur LED) auf Ausgang
DDRD |= (1<<DDD5); // Port D, Pin 5 (zum Buzzer) auf Ausgang
TCCR0A = (1<<WGM01) |(1<<COM0B0); // CTC Mode waehlen und Toggle Mode aktivieren
TCCR0B = (1<<CS01 | 1<<CS00); // Timer-Vorteiler /64
OCR0A = MAX_PER; // Start mit tiefstem Ton
while(1) // Start der unendlichen Schleife
{
for (OCR0A=MAX_PER; OCR0A>MIN_PER; OCR0A--) // Frequenz erhöhen
{
_delay_ms(10); // in Schritten von 10ms
}
_delay_ms(WAIT_TIME); // Wartezeit hohe Frequenz
TGL_BIT(PORTB,DDB0);
for (OCR0A=MIN_PER; OCR0A<MAX_PER; OCR0A++) // Frequenz absenken
{
_delay_ms(10); // in Schritten von 10 ms
}
_delay_ms(WAIT_TIME); // Wartezeit niedrige Frequenz
TGL_BIT(PORTB,DDB0);
} // Ende der unendlichen Schleife
}
// Funktionen =================================================================
- Attachments
- example2.zip
- You don't have permission to download attachments.
- (2 Kb) Downloaded 1 times