Soo i was doing code for ultrasonic distance sensor for a school project and I just cant get rid of compiling errors. Something is wrong with the Overflow ISR since when I comment it out it compiles successfully.
Code :
int a=0,b=0,i=0;
float udaljenost;
char u;
void setup() {
DDRB=0b00000001; //PB.0=trig pin, PB.1=echo pin
Serial.begin(9600);
cli();
TCCR0A = 0;// set entire TCCR2A register to 0
TCCR0B = 0;// same for TCCR2B
TCNT0 = 0;//initialize counter value to 0
// set compare match register for 10 microseconds increments
OCR0A = 160;// = (16*10^6) * 10*10^(-6))
// turn on CTC mode
TCCR0A |= (1 << WGM01);
// Set CS01 and CS00 bits for 1 prescaler
TCCR0B |= (1 << CS00);
// enable timer compare interrupt
//TIMSK0 |= (0 << OCIE0A);
sei();
}
ISR(TIMER0_OVRF_vect){
i++;
}
ISR(TIMER0_COMPA_vect){
b=1;
}
void loop() {
if(a==0 && b==0){
PORTB|=0b00000001;
TCNT0=0;
TIMSK0 |= (1 << OCIE0A); // palimo CTC prekid
a=1;
}
if(a==1 && b==1){
PORTB&=0b11111110;
TIMSK0 &= ( 1 & (0 << OCIE0A)); // gasimo CTC int
while( (PORTB && 0b00000010) == 0){
}
TCNT0=0;
TIMSK0 |= (1 << TOIE0); // Palimo overflow interrupt
while( (PORTB && 0b00000010) > 0){
if(i==69){
i=0;
TCNT0=0;
udaljenost=0;
break;
}
}
TIMSK0 = 0; //gasimo interrupte
udaljenost = ( 340* (i * 256) + TCNT0 ) / (16 * 10^6); // 340 * broj taktova / takt procesora
udaljenost = (int)(udaljenost * 100);
if (udaljenost = 0){
Serial.println("Pogresno ocitanje!");
a=0;
b=0;
i=0;
TIMSK0 = 0; //gasimo interrupte
TCNT0=0;
udaljenost=0;
}
else {
Serial.print("Udaljenost : ");
Serial.print(udaljenost);
Serial.println(" cm");
a=0;
b=0;
i=0;
TIMSK0 = 0; //gasimo interrupte
TCNT0=0;
udaljenost=0;
}
}
Serial.println(analogRead(A0));
}
Here is the error shown with code compiled as shown :
In file included from C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:30:0,
from sketch\Ultrazvucni_senzor_s_timerima.ino.cpp:1:
D:\jura\Arduino\Ultrazvucni_senzor_s_timerima\Ultrazvucni_senzor_s_timerima.ino: In function 'void TIMER0_OVRF_vect()':
D:\jura\Arduino\Ultrazvucni_senzor_s_timerima\Ultrazvucni_senzor_s_timerima.ino:32:5: warning: 'TIMER0_OVRF_vect' appears to be a misspelled signal handler, missing __vector prefix [-Wmisspelled-isr]
ISR(TIMER0_OVRF_vect){
^
In function 'TIMER0_OVRF_vect':
D:\jura\Arduino\Ultrazvucni_senzor_s_timerima\Ultrazvucni_senzor_s_timerima.ino:32:1: warning: 'TIMER0_OVRF_vect' appears to be a misspelled signal handler, missing __vector prefix [-Wmisspelled-isr]
ISR(TIMER0_OVRF_vect){
^
Skica koristi 3414 bytes (10%) od prostora za program. Maximum je 32256 bajtova.
Globalne promjenjljive koriste 228 bajtova (11%) RAM-a, ostalo je 1820 bajtova za lokalne promjenjljive. Maximim je 2048 bajtova.
It “compiles” successfully (white letters show as usually), but it doesn’t seem to work.