remove timer switch, switch PWMs to inverted mode

This commit is contained in:
ccppi 2024-03-05 09:25:08 +01:00
parent 28dc9144c6
commit 6306f8a8f9

62
main.c
View File

@ -11,39 +11,6 @@ typedef struct
unsigned char b;
int time_hold;
}rgbval;
void toogletimer()
{
static timer=1;
if(timer==0)
{
TCCR0A &= ~((1<<COM0A1) | (1<<COM0B1));// |(1<<WGM01) | (1<<WGM00));
TCCR1 &= ~(1<<COM1A0);
GTCCR &= ~(1<<COM1B1);
}
else if(timer==1)
{
DDRB = (1 << PB0 )|(1<<PB1)|(1<<PB4);
TCCR0A = (1<<WGM01)|(1<<WGM00)|(1<<COM0A1)|(1<<COM0B1); //mode
TCCR0B = (1<<CS01);//|(1<<CS02); //frequency /8
//
TCCR1 = (1<<COM1A0)|(1<<CTC1)|(1<<CS12)|(1<<CS10);//|(1<<CS11)|(1<<CS13); //frequency
GTCCR = (1<<PWM1B)|(1<<COM1B1); //mode + overrun clear
OCR1C = 255; // clear timer at 255
//######PWM_VALUE$
//timer 0
OCR0A = 128;
OCR0B = 1;
//timer 1
OCR1B = 1;
//######Configure Pullups
PORTB |= (1<<PB2);
}
timer = 1-timer;
}
int main (void) { // (2)
@ -58,7 +25,6 @@ int main (void) { // (2)
int r,g,b = 0;
int set=0;
int input=0;
int stop_timer=3;
//system_clock prescaler
//#######OC0A auf ausgang
@ -66,13 +32,11 @@ int main (void) { // (2)
//#######Timer0-setup#####
TCCR0A = (1<<WGM01)|(1<<WGM00)|(1<<COM0A1)|(1<<COM0B1); //mode
TCCR0B = (1<<CS01);//|(1<<CS02); //frequency /8
//
// PLLCSR |= (1 << PLLE) | (1 << PCKE);
//######Timer1-setup
TCCR1 = (1<<COM1A0)|(1<<CTC1)|(1<<CS12)|(1<<CS10);//|(1<<CS11)|(1<<CS13); //frequency
GTCCR = (1<<PWM1B)|(1<<COM1B1); //mode + overrun clear
TCCR1 = (1<<COM0A0)|(1<<COM0A1)|(1<<COM0B0)|(1<<COM0B1)|(1<<CTC1)|(1<<CS12)|(1<<CS10);//|(1<<CS11)|(1<<CS13); //frequencyi //iinverting PWM because 0 dtc not possible
GTCCR = (1<<PWM1B)|(1<<COM1B1)|(1<<COM1B0); //mode + overrun clear, Set on compare match
OCR1C = 255; // clear timer at 255
//######PWM_VALUE$
//timer 0
@ -83,7 +47,6 @@ int main (void) { // (2)
//######Configure Pullups
PORTB |= (1<<PB2);
while(1)
{
@ -107,22 +70,9 @@ int main (void) { // (2)
if(i2==6)
{
i2=0;
stop_timer=1;
}
//cycle through and stop pwm at value 0
if(stop_timer==1)
{
toogletimer();
stop_timer=0;
//PORTB &= ~((1<<PB0) | (1<<PB1) | (1<<PB4));
}
else if(stop_timer==0)
{
stop_timer=3;
toogletimer();
}
if(i2>0)
{
//Visual feedback "mode change"
for(i3=0;i3<i2;i3++)
{
@ -132,14 +82,11 @@ int main (void) { // (2)
_delay_ms(30);
}
}
}
else if((input & (1<<PB2) != 0))
else if(((input & (1<<PB2)) != 0))
{
set=0;
}
if(i2>0)
{
if(r < pattern[i2][i+1].r) {r++;}
if(r > pattern[i2][i+1].r) {r--;}
if(g < pattern[i2][i+1].g) {g++;}
@ -154,7 +101,6 @@ if(i2>0)
if(r == pattern[i2][i+1].r && g == pattern[i2][i+1].g && b == pattern[i2][i+1].b) break;
}
}
}
}