ISR(TIMER1_OVF_vect) is not compiling ?

Hello, back again with the next question ! :slight_smile:

I try to make a Geigercounter and I am using Timer1 on PinD5 to count the pulses of the tube. So far so good.
But if I want to measure somthing that is radioaktive, my counter will overflow quickly and gets negativ. How can I manage that the timer sets itself to sero on owerflow to prevent going negativ ?
Then I can count into a long var and add the value of the counter after it´s overflow.
I tried to find some examples but they are not working for me because ,
ISR(TIMER1_OVF_vect) will not compile. I just get a compiler message that nobody understands.

I hate the error messages of the compiler, they are as usless as shit ! I don´t know why this can´t be done better ? They could be more preciesly and specific.

Anyways it says: Compilation error: expected unqualified-id before string constant

It looks to me the compiler doesn´t like the command ISR(TIMER1_OVF_vect) {} and I don´t know why.

How can I set the Timer1 to Zero on overflow and add the value to another var ? Any ideas ?

Cheers

But it doesn't just say that; it also tells you exactly where that occurred file name, line number, and column number - plus a little pointer to it.

Post the code, and the full compiler output - copy & paste; use the <CODE/> button.

Post the message in its entirety, along with the offending code, and forum members will explain it to you.

1 Like

What board are you compiling for?

This construction is valid only for a boards, based AVR controllers, such as Uno, Nano, Mega. But It seems that you tried to use it to the different Arduino family

1 Like

Indeed.

In this case, the construct becomes completely meaningless, so it's unsurprising that the compiler gives an apparently meaningless message - because it is just completely confused!

1 Like

Ok guys ! Thanks for your help !
This is the code that´s gonna be my Geigercounter one day. (hopefully) :slight_smile:

By the way, I am using a Arduino Nano for this project !!!

Code:

#include <Arduino.h>
#include <U8g2lib.h>
#include <I2C_RTC.h>
#include <avr/interrupt.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

static DS3231 RTC;

   //Display SSD1309 128X64 OLED
   U8G2_SSD1309_128X64_NONAME0_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);  


//Radioaktiv immage for Startup
#define cross_width 50
#define cross_height 47
static const unsigned char radioaktiv[] PROGMEM = {
  0x00, 0x00, 0xF0, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x03, 
  0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x0F, 
  0xC0, 0x3F, 0x00, 0x00, 0x00, 0xFC, 0x01, 0x00, 0xFE, 0x00, 0x00, 0x00, 
  0x7E, 0x00, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x1F, 0x00, 0x00, 0xE0, 0x03, 
  0x00, 0x80, 0x07, 0x00, 0x00, 0x80, 0x07, 0x00, 0xC0, 0x03, 0x00, 0x00, 
  0x00, 0x0F, 0x00, 0xE0, 0x41, 0x00, 0x00, 0x08, 0x1E, 0x00, 0xF0, 0xE0, 
  0x00, 0x00, 0x1C, 0x3C, 0x00, 0x70, 0xF0, 0x01, 0x00, 0x3E, 0x38, 0x00, 
  0x38, 0xF8, 0x03, 0x00, 0x7F, 0x70, 0x00, 0x3C, 0xFC, 0x07, 0x80, 0xFF, 
  0xF0, 0x00, 0x1C, 0xFC, 0x0F, 0xC0, 0xFF, 0xE0, 0x00, 0x1C, 0xFE, 0x1F, 
  0xE0, 0xFF, 0xE1, 0x00, 0x0E, 0xFE, 0x3F, 0xF0, 0xFF, 0xC1, 0x01, 0x0E, 
  0xFF, 0x3F, 0xF0, 0xFF, 0xC3, 0x01, 0x0E, 0xFF, 0x1F, 0xE0, 0xFF, 0xC3, 
  0x01, 0x07, 0xFF, 0x0F, 0xC3, 0xFF, 0x83, 0x03, 0x87, 0xFF, 0xCF, 0xCF, 
  0xFF, 0x87, 0x03, 0x07, 0xFC, 0xC7, 0x8F, 0xFF, 0x80, 0x03, 0x07, 0xE0, 
  0xE7, 0x9F, 0x1F, 0x80, 0x03, 0x07, 0x00, 0xE6, 0x9F, 0x01, 0x80, 0x03, 
  0x07, 0x00, 0xC0, 0x0F, 0x00, 0x80, 0x03, 0x07, 0x00, 0xC0, 0x0F, 0x00, 
  0x80, 0x03, 0x07, 0x00, 0x00, 0x03, 0x00, 0x80, 0x03, 0x07, 0x00, 0x00, 
  0x00, 0x00, 0x80, 0x03, 0x0E, 0x00, 0x60, 0x18, 0x00, 0xC0, 0x01, 0x0E, 
  0x00, 0xE0, 0x1F, 0x00, 0xC0, 0x01, 0x0E, 0x00, 0xF0, 0x3F, 0x00, 0xC0, 
  0x01, 0x1C, 0x00, 0xF0, 0x3F, 0x00, 0xE0, 0x00, 0x1C, 0x00, 0xF0, 0x3F, 
  0x00, 0xE0, 0x00, 0x3C, 0x00, 0xF0, 0x3F, 0x00, 0xF0, 0x00, 0x38, 0x00, 
  0xF8, 0x7F, 0x00, 0x70, 0x00, 0x70, 0x00, 0xF8, 0x7F, 0x00, 0x38, 0x00, 
  0xF0, 0x00, 0xF8, 0x7F, 0x00, 0x3C, 0x00, 0xE0, 0x01, 0xF8, 0x7F, 0x00, 
  0x1E, 0x00, 0xC0, 0x03, 0xFC, 0xFF, 0x00, 0x0F, 0x00, 0x80, 0x07, 0xFC, 
  0xFF, 0x80, 0x07, 0x00, 0x00, 0x1F, 0xC0, 0x0F, 0xE0, 0x03, 0x00, 0x00, 
  0x3E, 0x00, 0x00, 0xF8, 0x01, 0x00, 0x00, 0xFC, 0x01, 0x00, 0xFE, 0x00, 
  0x00, 0x00, 0xF0, 0x0F, 0xC0, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 
  0x0F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 
  0xF8, 0x3F, 0x00, 0x00, 0x00, 
    };

  //Sculls and Bones immage for Startup
  #define cross_width 46
  #define cross_height 35
  static const unsigned char totenkopf01[] PROGMEM = {
  0x00, 0x00, 0xFC, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x3F, 0x00, 0x00, 
  0x00, 0x80, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x01, 0x00,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x00, 0x00, 0x00, 0x00, 0x1E, 
  0x3C, 0x00, 0x00, 0x00, 0x00, 0x1C, 
};

//Batterie state immage flatt
 #define cross_width 13
 #define cross_height 6
 static const unsigned char batt_flatt[] PROGMEM = {
0xFE, 0x1F, 0x02, 0x10, 0x03, 0x10, 0x03, 0x10, 0x02, 0x10, 0xFE, 0x1F, 
};

//Batterie state immage 90%
 #define cross_width 13
 #define cross_height 6
 static const unsigned char batt_10[] PROGMEM = {
  0xFE, 0x1F, 0x02, 0x18, 0x03, 0x18, 0x03, 0x18, 0x02, 0x18, 0xFE, 0x1F, 
};

//Batterie state immage 20%
 #define cross_width 13
 #define cross_height 6
 static const unsigned char batt_20[] PROGMEM = {
  0xFE, 0x1F, 0x02, 0x1C, 0x03, 0x1C, 0x03, 0x1C, 0x02, 0x1C, 0xFE, 0x1F, 
};

//Batterie state immage 30%
 #define cross_width 13
 #define cross_height 6
 static const unsigned char batt_30[] PROGMEM = {
  0xFE, 0x1F, 0x02, 0x1E, 0x03, 0x1E, 0x03, 0x1E, 0x02, 0x1E, 0xFE, 0x1F, 
};

//Batterie state immage 40%
 #define cross_width 13
 #define cross_height 6
 static const unsigned char batt_40[] PROGMEM = {
  0xFE, 0x1F, 0x02, 0x1F, 0x03, 0x1F, 0x03, 0x1F, 0x02, 0x1F, 0xFE, 0x1F, 
};

//Batterie state immage 50%
 #define cross_width 13
 #define cross_height 6
 static const unsigned char batt_50[] PROGMEM = {
  0xFE, 0x1F, 0x82, 0x1F, 0x83, 0x1F, 0x83, 0x1F, 0x82, 0x1F, 0xFE, 0x1F, 
};

//Batterie state immage 60%
 #define cross_width 13
 #define cross_height 6
 static const unsigned char batt_60[] PROGMEM = {
  0xFE, 0x1F, 0xC2, 0x1F, 0xC3, 0x1F, 0xC3, 0x1F, 0xC2, 0x1F, 0xFE, 0x1F, 
};

//Batterie state immage 70%
 #define cross_width 13
 #define cross_height 6
 static const unsigned char batt_70[] PROGMEM = {
  0xFE, 0x1F, 0xE2, 0x1F, 0xE3, 0x1F, 0xE3, 0x1F, 0xE2, 0x1F, 0xFE, 0x1F, 
};

//Batterie state immage 80%
 #define cross_width 13
 #define cross_height 6
 static const unsigned char batt_80[] PROGMEM = {
  0xFE, 0x1F, 0xF2, 0x1F, 0xF3, 0x1F, 0xF3, 0x1F, 0xF2, 0x1F, 0xFE, 0x1F, 
}; 

//Batterie state immage 90%
 #define cross_width 13
 #define cross_height 6
 static const unsigned char batt_90[] PROGMEM = {
  0xFE, 0x1F, 0xFA, 0x1F, 0xFB, 0x1F, 0xFB, 0x1F, 0xFA, 0x1F, 0xFE, 0x1F, 
}; 

//Batterie state fully charged
 #define cross_width 13
 #define cross_height 6
 static const unsigned char batt_full[] PROGMEM = {
   0xFE, 0x1F, 0xFE, 0x1F, 0xFF, 0x1F, 0xFF, 0x1F, 0xFE, 0x1F, 0xFE, 0x1F, 
};

//Buzzer immage for Buzzer on/off
 #define cross_width 7
 #define cross_height 11
 static const unsigned char buzz[] PROGMEM = {
  0x43, 0x45, 0x49, 0x79, 0x11, 0x11, 0x11, 0x79, 0x49, 0x45, 0x43,

}; 
//Speaker immage for Speaker on/off
 #define cross_width 7
 #define cross_height 12
 static const unsigned char speaker01[] PROGMEM = {
  0x03, 0x07, 0x0F, 0x1F, 0x7F, 0x7F, 0x7F, 0x7F, 0x1F, 0x0F, 0x07, 0x03,
};

int long CounterVar = 0;
int hour = 0;
int minute = 0;
int second = 0;
int RTCoff = 0;
const int button1 = 2;
const int button2 = 3;
const int button3 = 4;
const int speaker = 6;
const int buzzer = 7;
const int flashLED = 12;
const int vbatt = A0;
int Analogval = 0;


void setup(void) {

    //Timer1 as Counter:
   //noInterrupts();
   TCCR1A = 0;           // Init Timer1A
   TCCR1B = 0;           // Init Timer1B
   TCCR1B |= B00000111;  // External Clock on T1 PinB5 (RISING)
   TIMSK1 |=  (1 << TOIE1);  
   TCNT1 = 0; 
   //interrupts(); // enable all interrupts

    u8g2.begin();        // runs Display lib. 
    RTC.begin();         // startup RTC
    RTC_check();         // check RTC comunication and Display state on startup
    delay(1500);        
    intro();             // Display intro Logo radioaktiv/totenkopf on starup
    delay(2500);
   
   pinMode(button1,INPUT);    //button one :
   pinMode(button2,INPUT);    //button two:
   pinMode(button3,INPUT);    //button three:
   pinMode(speaker, OUTPUT);  //Speaker on/off
   pinMode(buzzer, OUTPUT);   //Buzzer on/off
   pinMode(flashLED, OUTPUT); //FlashLed on/off
}

void loop(void) {
        
        ISR(TIMER1_COMPA_vect)  //That´s the spot where the Hamster starts to hobble !
         {
        CounterVar ++ ;
         }

       if (RTC.isRunning()) { //If RTC state is OK set RTCoff to 1 Else set 2
        RTCoff = 1;
      } else {
        RTCoff = 2;
      }
       u8g2.clearBuffer();					// clear the internal memory
       battery();                   //Display Battery immage in right upper corner
       time();                      //Display the Time on top left
       counting();                  //Counting pulses of the tube SBM20

         u8g2.drawXBMP(107, 8, 7, 11, buzz);        // Draw Bitmap
         u8g2.drawXBMP(107, 20, 7, 12, speaker01);  // Draw Bitmap
        
       u8g2.sendBuffer();					// transfer internal memory to the display

        

       if (digitalRead(button1) == HIGH) {   //test for Buttons and test to set Timer 1 to zero
       // clockset();
       digitalWrite(flashLED, HIGH);
       TCNT1 = 0;
      } 
      else {
       digitalWrite(flashLED, LOW);
      }
  
   }

void RTC_check() {   //Check the RTC and show state on Startup

     u8g2.clearBuffer();					// clear the internal memory
        
     if (RTC.isRunning()) { 
      RTCoff = 1;
     u8g2.setFont(u8g2_font_6x13B_tf);
     u8g2.setCursor(10,15);
     u8g2.print("RTC DS_3231 status:");

     u8g2.setFont(u8g2_font_9x15B_tf);
     u8g2.setCursor(55,40);
     u8g2.print("OK!");
      
    }else {
      RTCoff = 2;

    u8g2.setFont(u8g2_font_6x13B_tf);
    u8g2.setCursor(10,15);
    u8g2.print("RTC DS_3231 status:");

    u8g2.setFont(u8g2_font_9x15B_tf);
    u8g2.setCursor(30,40);
    u8g2.print("MISSING!");

    }
    u8g2.sendBuffer();					// transfer internal memory to the display
}

void time() {    // Format RTC time for Display: 00:00:00
       
     char stunden[8];
     sprintf(stunden,"%02i",RTC.getHours());

     char minuten[8];
     sprintf(minuten,"%02i",RTC.getMinutes());

     char sekunden[8];
     sprintf(sekunden,"%02i",RTC.getSeconds());

     // make a string : display.println(zeit) !
     String zeit = String(stunden) + ":" + String(minuten) + ":" + String(sekunden);
     
     // switch case for the RTC check
     switch (RTCoff) {
  case 1:
     u8g2.setFont(u8g2_font_courB10_tf);   // set font
     u8g2.setCursor(10,10);                //position for text
     u8g2.print(zeit);                     // print (zeit) to Display
    break;
  case 2:
    u8g2.setFont(u8g2_font_6x13B_tf);
      u8g2.setCursor(10,10);
      u8g2.print("RTC failure!");                           
    break;
     }
} 

void counting() {  //Counting pulses of tube SBM20 by Timer1
     
     char count[8];
     sprintf(count,"%02i",TCNT1);
     u8g2.setFont(u8g2_font_courB10_tf);   // set font
     u8g2.setCursor(55,40);                //position for text
     u8g2.print(count); 

         u8g2.setFont(u8g2_font_6x13B_tf);
         u8g2.setCursor(20,50);
         u8g2.print(CounterVar);
    }

void intro() {   // Intro on Startup

 //show radioaktiv symbol on startup for 2.5 seconds
 u8g2.clearBuffer();					                // clear the internal memory
 
 u8g2.drawXBMP(12, 8, 50, 47, radioaktiv);    // Draw Bitmap
 u8g2.drawXBMP(70, 14, 46, 35, totenkopf01);  // Draw Bitmap

 u8g2.sendBuffer();					                  // transfer internal memory to the display
 
}

void clockset() {           // Test how to set the RTC by buttons
     hour = RTC.getHours();
     hour = hour +1;
     if (hour > 23) {
     hour = 0;
}
     RTC.setHours(hour);
     delay(400); 
}


void battery() {                    //Monitoring Battery state:
     Analogval = analogRead(vbatt);

     if (Analogval < 100) {
     u8g2.drawXBMP(115, 0, 13, 6, batt_flatt);  // Draw Bitmap
}
     if (Analogval >= 100) {
     u8g2.drawXBMP(115, 0, 13, 6, batt_10);  // Draw Bitmap
}
     if (Analogval >= 200) {
     u8g2.drawXBMP(115, 0, 13, 6, batt_20);  // Draw Bitmap
}
     if (Analogval >=  300) {
     u8g2.drawXBMP(115, 0, 13, 6, batt_30);  // Draw Bitmap
}
     if (Analogval >= 400) {
     u8g2.drawXBMP(115, 0, 13, 6, batt_40);  // Draw Bitmap
}
     if (Analogval >= 500) {
     u8g2.drawXBMP(115, 0, 13, 6, batt_50);  // Draw Bitmap
}
     if (Analogval >= 600) {
     u8g2.drawXBMP(115, 0, 13, 6, batt_60);  // Draw Bitmap
}
     if (Analogval >= 700) {
     u8g2.drawXBMP(115, 0, 13, 6, batt_70);  // Draw Bitmap
}
     if (Analogval >= 800) {
     u8g2.drawXBMP(115, 0, 13, 6, batt_80);  // Draw Bitmap
}
     if (Analogval >= 900) {
     u8g2.drawXBMP(115, 0, 13, 6, batt_90);  // Draw Bitmap
}
     if (Analogval > 1000) {
     u8g2.drawXBMP(115, 0, 13, 6, batt_full);  // Draw Bitmap
}
}


Which Nano??? Arduino Nano Family

Are you using the following board (Fig-1)?
image
Figure-1:

Sorry, there are a lot of problems in your code. The very first thing is that the C language does not allow functions to be defined inside other functions:

this is the reason for the error that started the thread

Besides this, there are other problems here.
For example, you can't set the same macro more than once - they simply won't work:

In general, before proceeding I recommend to review basic syntax concepts such as procedures, functions, code blocks, variable definitions and constants.

1 Like

Which "Arduino Nano", exactly?
There are several which all have the name "Nano", use different processors:

Yes that´s the one ! Atmega 328P ! :slight_smile:

Atmega 328P !

What do you mean I can´t set the same macro more than once ?

I know I´m still a bloody beginner in C programming and the code is not the best yet. :slight_smile: But I´m working on it.
That´s why I decided to make this Geigercounter project. A good way to learn.
When I was 11 I got an Atari800XL 8bit Comuter. That was the moment I started coding in Basic for the first time. I just discovered Arduino about 5 years ago.
I only made small programms. But now I want more. :slight_smile: So I have to learn more about it.
I´m also struggling with all those () {} ; symbols. It is so anoying. :slight_smile: But all in all it´s good fun. I am just amazed to see the Bitmaps I created by myself on the Display.
It is still a long way to go anyways. After I have my code I have to solder that stuff onto a ciruit board and 3Dprint a housing for it.

So If you can give me some tips for coding I would really apriciate it !

Thanks !!!

Now, tell me few things which are essential to design an accurate TC1 (Timer/Counter 1 of ATmega328P MCU of NANO Board) based counter:
1. Without any radioactive source/jig around the Geiger Counter, how much environment/background count you expect over a minute?

2. Do you have a radioactive Test Jig which when brought to the proximity of the Geiger Counter -- how much count you expect over a minute?

Ok. I will explaine what i want to do.
I want to create differen types of measurement methodes.

One is to count the pulses of the tube within a second and display it.
Then,
count the pulses of the tube within 10 seconds, 30 seconds and a minute and display it.

Now, if I take my peace of uranium ore and hold it next to the tube, TCNT1 is overflowing within 20 seconds. :slight_smile: The ore has more than 100.000 counts per minute.
Therefore I thought I have to set the timer1 to zero on it´s overflow that it stays positiv, that I can add it into another var.
Do you know what I mean ? :slight_smile:
I also want to measure for an hour. This can create a big number if you have a surce that gives like 100.000 counts per minute.
In this case the timer will overflow many times.

Is it 100.000 (decimal point) hundred or 100,000 (comma punctuation) one hundred thousand?

Measuring for an hour or for a day -- is not a problem. There is a way to handle the counter overflow?

Have you corrected the issues flagged in Post #10?

Not yet ! I´m working on it.

I don´t know what you mean. ? the "endif" in post 10 ?
If I delete it I get an error from the compiler.