PWM Control and IO Ports on Butterfly

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

Greetings Folks, I'm using the AVR Butterfly (Atmega169), and I'm trying to control a PWM I've created using switches connected to PORTB. My code isn't working. My signal is constantly on and can't be changed. Does anyone see my problem or know a better way of doing this? Thanks.

#include

int main (void)
{DDRB = 0x20;

while (1)
{

if (PINB & 0x01)
{
TCCR1A = (1<<COM1A1) | (1<<COM1B1) | (1<<WGM10);
TCCR1B = (1<<CS10);
OCR1A = 125;
}

else if (PINB & 0x02)
{ if (PINB & 0x04)
{ TCCR1A = (1<<COM1A1) | (1<<COM1B1) | (1<<WGM10);
TCCR1B = (1<<CS10);
OCR1A = 125;
}
}

else
{TCCR1A = (0<<COM1A1) | (0<<COM1B1) | (0<<WGM10);
TCCR1B = (0<<CS10);
}

}

}

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

Do you realise that the output of compare1A is on pin OC1A (Portb.1)?
Set this pin as output and use another pin for button.

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

jbelk7, don't start a new thread while the previous is still active and the subject is quite the same.
I will lock this one.

Read the sticky posts in the top of each forum to get familiar with their purpose.

You may find the Tutorial Forum a very helpfull one: sticky posts AND threads.

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

Topic locked