eebhoi01
Advanced Member level 4
Hi,
I really can't understand why I don't have any output. I'm kinda frustrated.
Okay, I am planning to do a very simple LED fading using atmega328p via Atmel Studio. Below is my code, I used the 8-bit timer using TCCR0A control register. I also set WGM02 in TCCR0B so OCR0A will be the TOP value of the TCNT. Can anyone help me why I am not getting any output? I already defined the DDR but still no luck. Any help is highly appreciated. Thanks in advance.
I really can't understand why I don't have any output. I'm kinda frustrated.
Okay, I am planning to do a very simple LED fading using atmega328p via Atmel Studio. Below is my code, I used the 8-bit timer using TCCR0A control register. I also set WGM02 in TCCR0B so OCR0A will be the TOP value of the TCNT. Can anyone help me why I am not getting any output? I already defined the DDR but still no luck. Any help is highly appreciated. Thanks in advance.
Code:
#define F_CPU 16000000UL
#include <[COLOR="#000000"]avr/io.h>[/COLOR]
#include <[COLOR="#000000"]util/delay.h>[/COLOR]
void initPWM()
{
TCCR0A |= 1,,WGM01 | 1,,WGM00 | 1,,COM0A0;
TCCR0B |= 1,,WGM02;
DDRB |= 1,,PINB1;
}
void setPWMOut(int dutycycle)
{
OCR0A = dutycycle;
}
int main (void)
{
int brightness = 0;
int fadeAmount = 5;
initPWM();
while(1)
{
setPWMOut(brightness);
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 255)
{
fadeAmount = -fadeAmount;
}
_delay_ms(30);
}
}
Last edited by a moderator: