attiny24/A PWM problem [solved: write wrong register]

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

Hi guys

I was trying to program an attiny24 to generate a 50Hz PWM signal on pin 8(PA5/OC1B), but I got nothing, could someone have a look at my codes please, thanks a lot!

Here is my code:

#define F_CPU 1000000UL

#include 
#include 

int main(void)
{
	

	OCR1A = 20000;		//set top count for timer1
	TCCR0A |= (1<<COM1B1);			//clear OC1B on match, set on bottom
	
	/* set timer1 to Fast PWM mode, top value = OCR1A */
	TCCR0A |= (1<<WGM10) | (1<<WGM11);
	TCCR0B |= (1<<WGM12) | (1<<WGM13);
	
	TCCR0B |= (1<<CS10);			//no pre-scaler

	OCR1B = 1000;
	DDRA |= (1<<PA5);

    while(1)
    {
	
    }
}

Zhuhua Wu - Electronic Engineering Student

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

You are setting the OCR registers for timer 1, but the other registers for timer 0.

Regards,
Steve A.

The Board helps those that help themselves.

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

me, I did this again, I actually stuck on this for over half hour.

Thanks Steve

Zhuhua Wu - Electronic Engineering Student