Inverting PWN - error

Hello guys,

I am facing this odd issue. According to the Arduino Mega datasheet if I set both COMxA0 and COMxA1 to 1, I should get an inverted PWM with frequency 1 Hz.

The problem is that I am getting no output.

const byte DIR = 6;  // Timer 4 "A" output: OC4A --> 1 Hz

void setup() {
pinMode (DIR, OUTPUT);

int myEraserDir = 7;             // this is 111 in binary and is used as an eraser
TCCR4B &= ~myEraserDir;   // this operation (AND plus NOT),  set the three bits in TCCR4B to 0

TCCR4A = _BV(COM4A1)| _BV(COM4A0)| _BV(WGM41) | _BV(WGM40); // COM4A1 and COM4A0 for inverted PWM ; WGM40, WGM41, WGM42, WGM43 for fast PWM mode
TCCR4B = _BV(WGM43) | _BV(WGM42)| _BV(CS42)| _BV(CS40); // CS42 and CS40 for prescaler (:1024) ; 16MHz/1024=15625Hz
OCR4A =  7815;          // 15625Hz/1Hz=15625 (50% duty--> 7812.5)
}  // end of setup

void loop()
{ }

if x represents the duration of the PWM pulse wouldn't 255-x be the inverted output?

gcjr:
if x represents the duration of the PWM pulse wouldn't 255-x be the inverted output?

"x" represents the timer. In this case I wanna PWM output from pin 6 that is controlled by Timer 4.

Therefore, COM4A0 and COM4A1

by x i meant the value to analogWrite()

I am not using analog write........ I am getting a PWM with direct port adressing. Moreover i need a digital signal in output

I am facing this odd issue. According to the Arduino Mega datasheet if I set both COMxA0 and COMxA1 to 1, I should get an inverted PWM with frequency 1 Hz.

Not in the Mode you are using. You have selected Mode 15(all 4 WGM bits set) which is fast pwm to OCR4A

Look at the table posted in your other thread, and read the note at the bottom about the special case when OCR4A is TOP.

The only alternating high low hardware output with the Mode you have selected is the toggle with only the 0 bit selected.