Electronic – ATTINY85 pin doesn’t go fully LOW when in PWM

avrpwm

I have connected 3 LEDs to ATTINY85 (PWM mode). Each LED is connected with NPN3904 and 68 ohm resistor to the PB0, PB1 or PB5 port.

Everything works great, except for some reason when I set the OCR0A or OCR0B values to 0, nether will go fully LOW, but instead will continue to give out a weak signal, while setting OCR1B to 0 works as expected and PB5 goes fully LOW:

enter image description here

Code:

#define F_CPU 8000000

#include <avr/io.h>
#include <util/delay.h>

void main()
{
    DDRB   = 1 << DDB4   | 1 << DDB1   | 1 << DDB0;
    TCCR0A = 2 << COM0A0 | 2 << COM0B0 | 3 << WGM00;
    TCCR0B = 0 << WGM02  | 1 << CS00;
    TCCR1  = 0 << PWM1A  | 0 << COM1A0 | 1 << CS10;
    GTCCR  = 1 << PWM1B  | 2 << COM1B0;

    for (;;)
    {
        OCR0A = 0x00;
        OCR0B = 0x00;
        OCR1B = 0x00;

        _delay_ms( 1000 );

        OCR0A = 0xFF;
        OCR0B = 0xFF;
        OCR1B = 0xFF;

        _delay_ms( 1000 );
    }
}

I have rotated all the components and tested with VCC in the range from 2.7v to 3.5v but still the same result occurs. The issue seems to be tied to the PB0 and PB1 pins specifically. Any hints on what am I missing? Thanks!

Best Answer

In datasheet of this mcu is this behaviour explained and also hints at how to change it.

If the OCR0A is set equal to BOTTOM, the output will be a narrow spike for each MAX+1 timer clock cycle. Setting the OCR0A equal to MAX will result in a constantly high or low output (depending on the polarity of the output se t by the COM0A[1:0] bits.)

Meaning that they cant reach 0% PWM, but they can reach 100%. For your aplication you can then invert outputs and invert meaning in code.

OCR0A = 0x00; //fully on
OCR0A = 0xFF; //fully off

This will turn off LED completely.