PWM didn't work on Atmega8

Hi, im trying to use my PWM pins in atmega8. According to the image below, atmega8 has 3 PWM pins (9, 10 and 11) So, I created simple test for checking this pwm pins, I connected LED with resistor and I pushed code with analogWrite(9, 254); instruction and nothing happen. If i use digitalWrite(9, HIGH) the LED is working. Also i measured voltage when i’m using analogWrite(9, 254) and its about ~0.35V. If I use 255 value instead of 254 in analogWrite, LED is working. I searched google but I can’t find any usefull informations.

Arduino-To-Atmega8-Pins.png

Might be better to post your whole code instead of the single line.
Other posts I have read on this forum say you don’t need to do pinMode when using a pin for analogue write but this may not be the case on older cores as used in the mega8. Did you set pin 9 to output?
Do you have a current limiting resistor on the LED else you may damage the arduino pin the LED is connected to. How is the LED wired?

I always set pinModes, my whole code

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

}

void loop() {
analogWrite(9, 254);
}

and circuit below

evelan: I always set pinModes, my whole code

Nothing stands out to me as to why that should not work. If I get chance tomorrow I will dig out a mega8 and try the same test.

Okey, thanks Im waiting for results. In meanwhile I will try burn bootloader on my other mega8 and check the same code and circuit

EDIT So I burned bootloader again on both mega8 and now I think it works fine, but if I put mega8 to my project it behaves as said before. I think (even I'm sure) it because I have weak power filtration (but in my opinion it looks quite well) :~

I can confirm it works for me and you also don’t need the pinMode command to set a analogWrite pin to output.
Attached is an image that shows the simple setup. The LED is pulsing as per the sketch.
For you LED to work as expected when not in the final circuit points to a wiring error. Can you post the full final circuit your testing in that does not work?

void setup() {
//  pinMode(9, OUTPUT);
}

void loop() {
  for(byte x = 0; x < 255; x++){
   analogWrite(9, x);
   delay(5);
  }
}