EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

[AVR club] Trouble getting functions recognized

Started by "chu...@lippmeier.com [avrclub]" February 19, 2017
I'm trying to get on board with Atmel Studio 7. That is, trying to use a more professional environment than Arduino Sketches. I have a good book "The AVR Microcontrollerand Embedded Systems" by Mazidi. The edition I have refers to Atmel Studio 6.
I've downloaded and installed Atmel Studion 7 on my Win7 computer and I wrote my first project using a function i.e. delay_ms(d).
The problem is that whether I put the function inside main() or outside main() in the file or if I #include and try to use the library, I can't get the finished build to recognize the delay function. The debugger even just skips right over it. I'm setting and clearing PORTC with the delay function following each action on PORTC. When I put the o'scope on a PORTC pin it jst toggles at 200uS (processor speed) The only way I've been able to make a delay is to just code a for loop inline. Any ideas?
Chuck Lippmeier
the code in delay function removed by optimizer

---In a..., wrote :

I'm trying to get on board with Atmel Studio 7. That is, trying to use a more professional environment than Arduino Sketches. I have a good book "The AVR Microcontrollerand Embedded Systems" by Mazidi. The edition I have refers to Atmel Studio 6.
I've downloaded and installed Atmel Studion 7 on my Win7 computer and I wrote my first project using a function i.e. delay_ms(d).
The problem is that whether I put the function inside main() or outside main() in the file or if I #include and try to use the library, I can't get the finished build to recognize the delay function. The debugger even just skips right over it. I'm setting and clearing PORTC with the delay function following each action on PORTC. When I put the o'scope on a PORTC pin it jst toggles at 200uS (processor speed) The only way I've been able to make a delay is to just code a for loop inline. Any ideas?
Chuck Lippmeier
The problem is for optimization. The code that you write in delay function , erased by optimizer
I remember having this issue years ago. I think I compiled with no optimization. That prevented the compiler ignoring the seemingly useless instructions. Someone on this list helped me out. Hopefully they are still around.
I'm not sure why it worked but I tried replacing the <> brackets with quotes
around the includes and now everything works. The website
www.MicroDigitalEd.com had an example delay program and it used the quote so
I tried it and it worked.

The weird thing though is that now even the non-library delay functions
work.

The book doesn't mention it but the microdigitaled sample program calls for
defining the clock frequency by using the #define F_CPU 8000000UL just
before the #include "util/delay.h". That also cleared a warning.

Chuck Lippmeier
I always build software delay loops around an assembly call of one or more NOP instructions. I’ve never had a problem with it being optimized away ( I guess it doesn’t optimize out assembly).
Clark Martin
A designated driver on the information Super Highway

> On Feb 20, 2017, at 4:00 AM, 'Chuck Lippmeier' c...@lippmeier.com [avrclub] wrote:
>
> I’m not sure why it worked but I tried replacing the <> brackets with quotes around the includes and now everything works. The website www.MicroDigitalEd.com had an example delay program and it used the quote so I tried it and it worked.
>
> The weird thing though is that now even the non-library delay functions work.
>
> The book doesn’t mention it but the microdigitaled sample program calls for defining the clock frequency by using the #define F_CPU 8000000UL just before the #include “util/delay.h”. That also cleared a warning.
>
>
>

The 2024 Embedded Online Conference