Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Can't use util/delay.h on c++ in Avrstudio v6

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
zhihu
Posts: 1
Joined: 2017-10-23 05:46

Can't use util/delay.h on c++ in Avrstudio v6

#1 Post by zhihu »

I'm just new with microcontrollers and I'm hoping someone could help me understand this. I'm using an AVRStudio 6 and an AVRDragon. Watched some tutorials on basic programming.

Here's the code:

#include <util/delay.h>
int main(void) {
_delay_ms(30);
}
What I can't understand is when I made a new avrgcc c project it works well. But as a c++ fan, I made a new project using avrgcc c++ and the code won't work. The error message is as follows:

2. 'fabs' was not declared in this scope
3. 'ceil' was not declared in this scope
4. 'fabs' was not declared in this scope
5. 'ceil' was no declared in this scope
I tried those codes in my avrsudio v6 by avrgcc c++ program and the warning #1 goes away but the other 4 warnings are still there? If I use avrgcc c there are no problems. What must I do so I could do this with avrgcc c++? Can anyone help me understands whats going on? Thanks a lot guys!

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

Re: Can't use util/delay.h on c++ in Avrstudio v6

#2 Post by reinob »

zhihu wrote:I'm just new with microcontrollers and I'm hoping someone could help me understand this. I'm using an AVRStudio 6 and an AVRDragon. Watched some tutorials on basic programming.

Here's the code:

#include <util/delay.h>
int main(void) {
_delay_ms(30);
}
What I can't understand is when I made a new avrgcc c project it works well. But as a c++ fan, I made a new project using avrgcc c++ and the code won't work. The error message is as follows:

2. 'fabs' was not declared in this scope
3. 'ceil' was not declared in this scope
4. 'fabs' was not declared in this scope
5. 'ceil' was no declared in this scope
I tried those codes in my avrsudio v6 by avrgcc c++ program and the warning #1 goes away but the other 4 warnings are still there? If I use avrgcc c there are no problems. What must I do so I could do this with avrgcc c++? Can anyone help me understands whats going on? Thanks a lot guys!
I don't know how that _delay_ms() function is defined, but it could be a macro using math functions without bothering to #include <math.h>

You'll have to do it yourself then..

User avatar
pylkko
Posts: 1802
Joined: 2014-11-06 19:02

Re: Can't use util/delay.h on c++ in Avrstudio v6

#3 Post by pylkko »

Is this on Debian 9.2?

You need to include the math header file.

That is, only delay will not suffice.
first include math.h and then util/delay.h

or add the include math to the delay.h file header

8 bit avr is a really primitive architecture with no floating point math (FPU) so people often try to avoid doing math...

However, just take a look at how difficult and complex it is using c++ on avr (google around) and you wil get an idea of why barely anyone uses it, or at least some avoid. I wouldn't, but then again I don't know what you are doing.

http://www.atmel.com/webdoc/avrlibcrefe ... splus.html

Aaaapestaart
Posts: 2
Joined: 2018-04-08 10:50

Re: Can't use util/delay.h on c++ in Avrstudio v6

#4 Post by Aaaapestaart »

The functions from util/delay.h should compile into tight loops.
All floating point operations are supposed to be done at compile time.

This might have to do with a too low (or no) optimiation level for the C++ compiler.
Try adding "-Os" while compiling.

AVRfreaks is probably a much better place for AVR related questions.

Post Reply