UNKNOWN ERROR WITH >= OPERATOR

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, I am encountered by a vague error (at least for me). 

 

when i change if(pass_count == 4)  to if(pass_count >= 4) it starts giving me two errors

 

Severity    Code    Description    Project    File    Line
Error        recipe for target 'main.o' failed    GccApplication3    C:\Users\abn\Documents\Atmel Studio\7.0\GccApplication3\Debug\Makefile    86

 

Severity    Code    Description    Project    File    Line
Error        __builtin_avr_delay_cycles expects a compile time integer constant    GccApplication3    d:\new folder\7.0\toolchain\avr8\avr8-gnu-toolchain\avr\include\util\delay.h    187
 

I am using ATMEGA8A with a crystal oscillator of 11.0592MHz and have adjusted fuses accordingly.

This topic has a solution.
Last Edited: Fri. Mar 15, 2019 - 09:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please show the code which is generating this error.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for replying Mike. Basically, i am working on finger print lock system. Total code is very long but hopes this will be enough for you.

The moment I changed the '==' to '>=' i got these two errors and if I change it back too '==' error is gone.


int pass_count=0;
int wrong_delay;
char wrong_delay_str[4];

if(pass_count >= 4)
     {
      LCD_Clear();
      wrong_delay = 5000 + (pass_count-4)*1000;
      sprintf(wrong_delay_str, "%d", (wrong_delay/1000));
      LCD_String("Wait for ");
      LCD_String(wrong_delay_str);
      LCD_String(" sec");
      _delay_ms(wrong_delay);
      LCD_Command(0x01); //to clear
      
     }

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

_delay_ms() requires that the delay is a known constant at compile time. When you compare with ==, the compiler will optimize wrong_delay to always be 5000. When you compare with >=, wrong_delay can't be optimized to a constant. This is why it's complaining about " __builtin_avr_delay_cycles expects a compile time integer constant". _delay_ms() uses __builtin_avr_delay_cycles.

Electronics Technician in R&D, my only friends are ATMEGA, PIC32, and STM32.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Any solution then how to make increasing delay if someone is writing the wrong password again and again.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could use separate consecutive delays. For instance: If pass_count >= 4, you could have it _delay_ms(5000) once, then use a loop to _delay_ms(1000) for every pass_count above 4

Electronics Technician in R&D, my only friends are ATMEGA, PIC32, and STM32.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In a situation like this, copy the entire error string from the compiler message text into your URL address line and hit enter.  This will call your browser's affiliated search engine (usually Google) on the error message text.   Someone has probably had this error before and requested help on the web.

 

In this case, " __builtin_avr_delay_cycles expects a compile time integer constant " brings a dialog from www.stack Overflow.com where a sequence of short delay loops of fixed length is called instead of using a variable as the parameter for _delay_ms().

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use a wrapper.

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can do something like

 

if(pass_count >= 4)
     {
      LCD_Clear();
      wrong_delay = 5000 + (pass_count-4)*1000;
      sprintf(wrong_delay_str, "%d", (wrong_delay/1000));
      LCD_String("Wait for ");
      LCD_String(wrong_delay_str);
      LCD_String(" sec");
      _delay_ms(5000);
      for (int secs = pass_count-4; secs > 0; secs--){
        _delay_ms(1000);  
      }
      LCD_Command(0x01); //to clear
      
     }

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could also do it with a switch statement aswell