Hi,
I'm having fun programming LED scripts on an ATTiny, and I am observing a very strange behaviour that boils down to this simple test case:
void setup() {
pinMode(0, OUTPUT);
}
void loop() {
for (int i = 0; i <= 255; i++) {
analogWrite(0, i);
delay(10);
}
analogWrite(0, 0);
delay(1000);
}
As you can see, the output (connected to a simple LED) ramps up from 0 to 100% in about 2.5s, then drops abruptly and leaves the led off for 1s, and does that all over again.
However, running this code causes a visible flash of random duration at the beginning of the ramp: See this video.
Conditions:
- ATTiny85V (reproductible with two different chips)
- Arduino IDE v1.6
- Attiny cores 1.5 from Google Code Archive - Long-term storage for Google Code Project Hosting.
The scope shows that when starting the ramp loop, we get a first PWM cycle with a variable (and sometimes very high) duty cycle:
I thought maybe calling analogWrite with a value of 0 triggers a special behaviour (like turning PWM off without resetting some registers), which would cause the first "non-zero" analogWrite at the beginning of the ramp to start with the previous settings, so I tried to add an "analogWrite(0, 1)" just after the "for" loop, but nothing changed.
Then I added a 1ms delay between that "analogWrite(0, 1)" and "analogWrite(0,0)". On the scope, I can clearly see one PWM period with a very small duty-cycle at the end of the ramp, but still, the flash happens. Here you can see the "analogWrite(0,1)" in action during 1ms:
Then I increased that delay to 10ms, and then only the flash disappeared completely: Here is the end and the beginning of the ramp:
Is that a known issue ?
Any idea of why that happens and how to get rid of that "flash" in a clean way ?
Best regards,
Vicne






