Attiny88 Setting up PWM outputs

Go To Last Post
18 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, 

How do i set up OCR0A, OCR0B, OCR1A, OCR1B all as outputs

phase correct mode

8x prescalar

 

Thank you

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How do i set up OCR0A, OCR0B, OCR1A, OCR1B all as outputs

By looking at the datasheet  ---have you?

 

Not to be too snarky, but the tables for the timer show all the settings.  The WGM bits control whether the pins themselves change based on timer responses 

Search the datasheet for WGM & you will be in golden luck garden

for example ,section 12.11.1

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Thu. May 6, 2021 - 12:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes this is my setup so far...

 

    //ATtiny88 datasheet, page 140
    
    //Compare Output Mode, Set to 'Phase Correct PWM Mode' mode
    TCCR1A |= (1 << COM1A1) | (1 << COM1B1)); //OCR1A, OCR1B
    
    //Waveform Generation Mode, (Phase Correct 8-bit PWM)
    TCCR1A |= (1 << WGM10); //OCR1A, OCR1B
        
    //Prescaler
    TCCR1B |= (1 << CS11); // clock /8 = (~ KHz)

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This will set Phase correct PWM on PB1 and PB2 pins.

 

int main(void)
{
    TCCR1A |= (1 << COM1A0) | (1 << COM1A1) | (1 << COM1B0) | (1 << COM1B1);
    TCCR1A |= (1 << WGM10);
    TCCR1B |= (1 << CS11);

    OCR1A = 127;
    OCR1B = 127;

    DDRB |= (1 << PB1) | (1 << PB2);

    while (1)
    {
    }
}

I think you are missing to set the pins to output mode.

Last Edited: Thu. May 6, 2021 - 01:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Heisen wrote:
I think you are missing to set the pins to output mode.

+1!

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Heisen wrote:

This will set Phase correct PWM on PB1 and PB2 pins.

 

I think you are missing to set the pins to output mode.

 

How about pins PD6 and PD5.

 

I had pins in output mode

 

    DDRB |= ( 1 << PB2 );            // LED is an output (PB2)
    DDRB |= ( 1 << PB1 );            // LED is an output (PB1)
    DDRD |= ( 1 << PD6 );            // LED is an output (PD6)
    DDRD |= ( 1 << PD5 );            // LED is an output (PD5)

Last Edited: Thu. May 6, 2021 - 03:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does attiny88 support Phase correct PWM on pins PD6 and PD5? 

Last Edited: Thu. May 6, 2021 - 03:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Heisen wrote:

Does attiny88 support Phase correct PWM on pins PD6 and PD5? 

 

Yes, OC0A & OC0B can be set to phase correct

Last Edited: Thu. May 6, 2021 - 04:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ZeusCannon wrote:
I had pins in output mode

???  So, we are to guess what code you are using?  Post a complete test program; tell how you are testing; tell what you observe.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include <avr/io.h>

#ifndef F_CPU
#define F_CPU 8000000UL			// Define software reference clock
#endif

void Init_ports(void)
{
	// Enable Pull-Up Resistors on Unused Pins
	PORTB = ((1 << PINB0) | (1 << PINB3) | (1 << PINB4) | (1 << PINB5) | (1 << PINB6) | (1 << PINB7));
	PORTC = ((1 << PINC0) | (1 << PINC1) | (1 << PINC2) | (1 << PINC3) | (1 << PINC4) | (1 << PINC5));
	PORTD = ((1 << PIND0) | (1 << PIND1) | (1 << PIND2) | (1 << PIND3) | (1 << PIND4));

	DDRB |= ( 1 << PB2 );			// LED is an output (PB2)
	DDRB |= ( 1 << PB1 );			// LED is an output (PB1)
	DDRD |= ( 1 << PD6 );			// LED is an output (PD6)
	DDRD |= ( 1 << PD5 );			// LED is an output (PD5)
}

void PWM_setup (void)
{
	// See ATtiny88 datasheet, page 126

	//Compare Output Mode, Set to 'Phase Correct PWM Mode' mode
	TCCR1A |= ((1 << COM1A0) | (1 << COM1A1) | (1 << COM1B0) | (1 << COM1B1)); //OCR1A, OCR1B

	//Waveform Generation Mode, (Phase Correct PWM)
	TCCR1A |= (1 << WGM10); //OCR1A, OCR1B

	//Prescaler x8
	TCCR1B |= (1 << CS11); // clock /8 = (~ KHz)
}

int main (void)
{
	Init_ports();
	PWM_setup();

	OCR0B = 15;
	OCR0A = 100;
	OCR1A = 180;
	OCR1B = 255;

	while(1)
	{}

	return(0);
}

 

Only OCR1A is working.

I tested the other pins, they have no outputs on the pins.

So im guessing its the PWM setup 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I am not wrong, on attiny88 phase correct PWM is only supported on timer1. Only OCR1A and OCR1B will work.

In your PWM_setup function, the code only setups phase correct PWM for two pins only, which are PB1 and PB2.

Last Edited: Thu. May 6, 2021 - 06:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Regular pwm (fast pwm) is very suitable for most things.  Rapidly varying motor speed (such as bridge drive transistors) appreciates phase-correct type

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Heisen wrote:

If I am not wrong, on attiny88 phase correct PWM is only supported on timer1. Only OCR1A and OCR1B will work.

In your PWM_setup function, the code only setups phase correct PWM for two pins only, which are PB1 and PB2.

You are correct, the only OCR pins are OCR1a/b, to timer0 has not pwm output pins.

Jim

That leaves only softPWM via software if the OP wants to use T0 for pwm.

PS:  Has the OP confused a mega88 for the tiny88?  Please clarify what AVR you are using.

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

Last Edited: Thu. May 6, 2021 - 07:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

i am using Attiny88-AU with Atmel Studio, i can use Fast PWM instead, how do i set up.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

What DS are you looking at?

 

Your pin out is for an ATmega88!!!  not an Attiny88, are you looking at the correct datasheet?

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

Last Edited: Thu. May 6, 2021 - 07:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

PS:  Has the OP confused a mega88 for the tiny88?  Please clarify what AVR you are using.

 

YUP! was using the mega88 datasheet instead of the tiny88. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ZeusCannon wrote:
YUP! was using the mega88 datasheet instead of the tiny88. 

No sweat, it's not like we all have not done that ourselves.   Good hunting!

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I need 4 separate PWM outputs

Since the Atmega88A has 4 PWM outputs, i will order some and program and update here. 

I even design my board based off the Atmega88A, which is a good thing! Just had the wrong chip currently

 

Thanks!!