Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

ATTINY13 PWM

2 posters

Go down  Message [Page 1 of 1]

1ATTINY13 PWM Empty ATTINY13 PWM Fri Sep 11, 2020 8:05 am

Chuck



Hi, I am trying to create a PWM on Attiny13, but it fail (PB0 pin - silent). What wrong? Thx.
ATTINY13 PWM Tiny1310

Code:

#define F_CPU 1200000UL

#include <avr/io.h>
#include <avr/interrupt.h>

#define PWM_PIN PB0
#define LED_PIN PB4
#define BUTTON1_PIN PB2 //+
#define BUTTON2_PIN PB3 //-

int
main(void)
{
    //TCCR0A  = ((1<<WGM00) | (1<<WGM01) | (1 << COM0A1)) ; // Fast PWM mode 3, Clear OC0A on Compare Match, set OC0A at TOP
    TCCR0A |= (1<<COM0A1);
    TCCR0A |= (1<<WGM01)|(1<<WGM00); //FAST PWM
    TCCR0B |= (0<<CS02)|(1<<CS01)|(0<<CS00); //F = F_CPU/(N * 256);   F= 1200000Hz/(8*256)= 585.94 Hz  //prescaler 8

    // i/o
    DDRB |=(1<<PWM_PIN);
    PORTB&=~(1<<PWM_PIN);

    //Led
    DDRB |=(1<<LED_PIN);
    PORTB&=~(1<<LED_PIN);

    //Buttons
    DDRB &=~(1<<BUTTON1_PIN);
    PORTB|=(1<<BUTTON1_PIN);

    DDRB &=~(1<<BUTTON2_PIN);
    PORTB|=(1<<BUTTON2_PIN);

    volatile uint8_t PWM = 0;
    OCR0A = PWM;

    while (1)
    {
        if ((PINB & (1<<BUTTON1_PIN))==0)   //ADD +
        {
            if (PWM< 254)
            {
                PWM++;
            }
            while ((PINB & (1<<BUTTON1_PIN))==0)
            {
            }
        }

        if ((PINB & (1<<BUTTON2_PIN))==0)   //SUB -
        {
            if (PWM>1)
            {
                PWM--;
            }

            while ((PINB & (1<<BUTTON2_PIN))==0)
            {
            }
        }

        if (OCR0A>9)
        {
            PORTB |=(1<<LED_PIN);
        }
        else
        {
            PORTB&=~(1<<LED_PIN);
        }

        OCR0A = PWM;
    }
}

2ATTINY13 PWM Empty Re: ATTINY13 PWM Fri Sep 11, 2020 4:43 pm

arcachofo

arcachofo

Hi.

Looks like that is a bug affecting tiny13.
It will be solved for next release.
It should work with other tinys, for example tiny25.

Thank you for reporting.

Chuck likes this post

3ATTINY13 PWM Empty Re: ATTINY13 PWM Mon Sep 14, 2020 12:41 pm

Chuck



Thanks! It work with tiny25/45/85.

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum