So ich bins nochmal...
und 4 Stunden (und einem Atmega8 weniger) später funzt es...ich hab es jetzt hinbekommen alle 3 PWM Ausgänge ins Laufen zu bekommen...also bei mir funzt es mal. Ich hab alles sehr einfach gehalten, dass wenn noch jemand Probleme hat er sich vielleicht daran orientieren kann, falls es denn richtig ist. Vielleicht könnte ja mal der Ahnung hat drüberschauen und nen Statement abgeben....
Hier der KOT
Code:
/* PWM on Atmega8
Enjoy it :-)
Hardware:
Atmega8 PDIP
Switch at PB0
1 x switch at PB0 for dimming and test
1 x LED at PB1 for (OCR1A)
1 x LED at PB2 for (OCR1B)
1 x LED at PB3 for (OCR2)
1 x LED at PC0 for Switch (when switching LED on, no need!)
*/
#include <avr/io.h>
#include <util/delay.h>
int main (void)
{
DDRB &= ~(1<<PB0); //set PB0 input (switch)
PORTB |= (1<<PB0); //set PB0 Pull up on
DDRB |= (1<<PB1); //set PB1 output (PWM OCR1A)
PORTB |= (1<<PB1); //set PB1 Pull up on
DDRB |= (1<<PB2); //set PB2 output (PWM OCR1B)
PORTB |= (1<<PB2); //set PB2 Pull up on
DDRB |= (1<<PB3); //set PB3 output (PWM OCR2)
PORTB |= (1<<PB3); //set PB3 Pull up on
DDRC |= (1<<PC0); //set PC0 output (LED)
// Timer1 init for PWM on Pin PB2 and PB1
TCCR1A = 0x00; // stop T/C1
TCCR1A = (1<<WGM10) //set PWM phase correct mode 8 bit
|(1<<COM1A1) //clear OCR1A on compare match when up-counting
|(1<< CS10) //no prescaler, start timer1/A-L
|(1<<COM1B1); //clear OCR1B on compare match when up-counting
TCCR1B = (1<< CS10); //no prescaler, start timer1/B-H
// Timer2 init for PWM on Pin PB3
TCCR2 = 0x00; //stop T/C2
TCCR2 = (1<<WGM20) //set PWM phase correct mode 8 bit
|(1<< CS20) //no prescaler, start timer2
|(1<<COM21); //clear OC2 on compare match when up-counting
OCR1A = 0; //start value of OCR1A
OCR1B =10; //start value of OCR1B
OCR2 = 0; //start value of OCR2
while(1)
{
if (!(PINB & (1 << PB0))) //if PB0 is low then (switch)
{
PORTC |= (1 << PC0); //set PC0 high (LED on)
OCR1A ++; //inc OCR1A
OCR1B --; //dec OCR1B
OCR2 ++; //inc OCR2
_delay_ms(1000); //delay time for switch
}
else //else
{
PORTC &= ~(1 << PC0); //set PC0 low (LED off)
}
// reset procedure* (*I know I need no 3 queues but...)
if (OCR1A >=10)
{
OCR1A = 0;
}
if (OCR1B <=0)
{
OCR1B = 10;
}
if (OCR2 >=10)
{
OCR2 = 0;
}
}//while(1)
return 0;
}//int main (void)
Danke
Finwe0815
Lesezeichen