So im working on a school project and the professor forces us to use the build in timers of the atmega chip to create a PWM-signal to control 3 servo’s. After a lot of research and a lot of programming and debugging i managed to activate and set all three timers and utilize 2 of them.
After i finished utilizing the 3rd one i tried to compile and got the error massage “return status 1”
Code:
#define servo1 9
#define servo2 10
#define servo3 11
unsigned char flag0 = 0;
unsigned char flag1 = 0;
unsigned char flag2 = 0;
unsigned int tijd0_2 = 36; // tweede globale, tweede tijd ; x ms hoog ; 2 = 0 graden ; 1 = ongeveer 90 graden
unsigned int tijd0_1 = 320-tijd0_2;
unsigned int tijd1_2 = 36; // tweede globale, tweede tijd ; x ms hoog ; 2 = 0 graden ; 1 = ongeveer 90 graden
unsigned int tijd1_1 = 320-tijd1_2;
unsigned int tijd2_2 = 36; // tweede globale, tweede tijd ; x ms hoog ; 2 = 0 graden ; 1 = ongeveer 90 graden
unsigned int tijd2_1 = 320-tijd2_2;
void setup()
{
Serial.begin(9600);
pinMode(servo1, OUTPUT);
pinMode(servo2, OUTPUT);
pinMode(servo3, OUTPUT);
// initialize timer1
noInterrupts(); // disable all interrupts
TCCR0A = 0;
TCCR0B = 0;
// 2Hz preload value
TCNT0 = 34286; // preload timer 65536-16MHz/256/2Hz first trip value (berekening is belangrijk!)
TCCR0B |= (1 << CS12) | (1 << CS10); // 1024 prescaler
TIMSK0 |= (1 << TOIE1); // enable timer overflow interrupt
TCCR1A = 0;
TCCR1B = 0;
// 2Hz preload value
TCNT1 = 34286; // preload timer 65536-16MHz/256/2Hz first trip value (berekening is belangrijk!)
TCCR1B |= (1 << CS12) | (1 << CS10); // 1024 prescaler
TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt
TCCR2A = 0;
TCCR2B = 0;
// 2Hz preload value
TCNT2 = 34286; // preload timer 65536-16MHz/256/2Hz first trip value (berekening is belangrijk!)
TCCR2B |= (1 << CS12) | (1 << CS10); // 1024 prescaler
TIMSK2 |= (1 << TOIE1); // enable timer overflow interrupt
interrupts(); // enable all interrupts
}
/*
ISR(TIMER0_OVF_vect) // interrupt service routine that wraps a user defined function supplied by attachInterrupt
{
if (flag0)
{
digitalWrite(servo1, HIGH);
flag0 = 0;
TCNT0 = 65536 - tijd0_2; // preload timer with next wait value
Serial.println("iets");
}
else
{
digitalWrite(servo1, LOW);
flag0 = 1;
TCNT0 = 65536 - tijd0_1; // preload timer with next wait value
}
}
*/
ISR(TIMER1_OVF_vect) // interrupt service routine that wraps a user defined function supplied by attachInterrupt
{
if (flag1)
{
digitalWrite(servo2, HIGH);
flag1 = 0;
TCNT1 = 65536 - tijd1_2; // preload timer with next wait value
Serial.println("iets");
}
else
{
digitalWrite(servo2, LOW);
flag1 = 1;
TCNT1 = 65536 - tijd1_1; // preload timer with next wait value
}
}
ISR(TIMER2_OVF_vect) // interrupt service routine that wraps a user defined function supplied by attachInterrupt
{
if (flag2)
{
digitalWrite(servo3, HIGH);
flag2 = 0;
TCNT2 = 65536 - tijd2_2; // preload timer with next wait value
Serial.println("iets");
}
else
{
digitalWrite(servo3, LOW);
flag2 = 1;
TCNT2 = 65536 - tijd2_1; // preload timer with next wait value
}
}
void loop()
{
//funcites
}
The commented function is the one causing trouble, as you can see its identical to the other 2 functions utilizing the timer, with exeption to the needed changes in the variables.
I have no idea how to fix this and my project is due on teusday. i’d be great if some of you codewizards can help me out here.
PS: some of the commented out calculations are wrong due to me being sloppy, i’m aware of this and will fix it when i pick this up again