Hallo,
danke für die Antworten ich meine 180° Phasenverschiebung und nicht Invertierung.
Wollte es mit dem Phase-Correct PWM Mode machen aber leider geht das nicht so,
weil das Register mit dem ich die Frequenz einstelle das gleiche ist mit dem ich den einen Impuls machen möchte:
"Note that in this mode, only output B can be used for PWM; OCRA cannot be used both as the top value and the PWM compare value."
(http://www.righto.com/2009/07/secret...duino-pwm.html)
Dachte ich könnte vllt einfach einen Interrupt auslösen wenn ich die obere Grenze erreiche und einen Pin toggeln.
Ist zwar nicht optimal aber besser als beide pulse in Software zu erzeugen.
Leider funktioniert mein Programm nicht, da ich nicht in die isr rein komme.
kann mir jemand meinen Fehler sagen?
Code:
// A sketch that creates an 250 kHz 6-bit resolution PWM with varying duty cycle
#include <avr/io.h>
#include <util/delay.h>
void setup()
{
Serial.begin(115200);
pinMode(3, OUTPUT); // Output pin for OCR2B
pinMode(2, OUTPUT);
// Set up the 250 kHz output
TCCR2A = bit(COM2A1) | bit(COM2B1) | bit(WGM21) | bit(WGM20);
TCCR2B = bit(WGM22) | bit(CS20);
TIMSK2 |= (1 << OCIE2A); // enable timer compare interrupt
OCR2A = 63;
OCR2B = 0;
sei();//allow interrupts
}
ISR(Timer2_COMPA_vect) // timer compare interrupt service routine
{
PORTD |= 0x4;
PORTD &= ~0x4;
}
void loop()
{
}
Lesezeichen