NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » delay.c issues with the 328p

December 07, 2009
by n3ueaEMTP
n3ueaEMTP's Avatar

OK, I got these snazzy new 328s the other day & got around to using them last evening at work, Everything complied fine & the program worked like a charm. I get home this morning and changed the code slightly and now the program will not compile. Here's what the error looks like:

screen shot

The only physical component changes are the addition of the LCD. I'm using the same laptop so the computer may not be the problem. I'm hesitant to change delay.c because it worked fine until now.
Here is what I've tried:

  1. Replacing the 328 with a 168 and the 168 complies without a problem.

  2. I've reverted back to the code that worked last evening (everything compiled well with the 168, no luck with the 328)

  3. Removed the LCD

  4. Restarted my computer

  5. Tried a different 328(the second 328 worked well with the initialload program that was installed by the NerdKits staff. I could read the Congratulations screen).

  6. Tried to compile a different program (trafficlight.c) on the 328, same problem as with previous program.

I've followed the directions to change the makefile for the 328 as well as adding #include "../libnerdkits/io_328p.h" to the programs. What confuses me the most is that it worked fine last evening at work, the only difference (as best I can tell) is the environment (home vs work). I'm assuming I've done something wrong but cannot figure out what it is, any ideas?

December 07, 2009
by jbremnant
jbremnant's Avatar

The error seems to indicate that you don't have delay.h in libnerdkits directory. Did you check whether you have the header file (delay.h) in the same dir as delay.c?

December 07, 2009
by tech20
tech20's Avatar

just to say, i have noticed that delay.c/.h is incompatible with any clock frequency other than the one of the crystal included in the nerdkit. You can use a code mod and some stricter coding guidelines (define F_CPU every time). You can try this code if you can't figure it out and define F_CPU if it's mot already.

#include <inttypes.h>
#include "delay.h"
#include <util/delay.h>

// delay_us(...):
// delays a given number of microseconds
inline void delay_us(uint16_t us) {
  _delay_us(us);
}

// delay_ms(...):
// delays a given number of milliseconds
void delay_ms(uint16_t ms) {
  _delay_ms(ms);
}
December 07, 2009
by n3ueaEMTP
n3ueaEMTP's Avatar

Problems Solved, THANK YOU!!!!

It turns out that I needed to add lcd.h & uart.h as well.

Chris B. n3ueaEMTP

December 07, 2009
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi n3ueaETMP,

Not sure why it was broken as "delay.h" includes a definition for NOP, but I'm glad to hear you got things working.

tech20, your suggestion about using the avr-libc _delay_us and _delay_ms functions is interesting, but be aware that there are a few caveats to using them -- the big one being that "the delay time must be an expression that is a known constant at compile-time". Our delay functions did not have such a constraint. (In fact, since the delay_ms and delay_us things are themselves functions, I'm not sure that the compiler is smart enough to know that delay at compile-time.)

Mike

Post a Reply

Please log in to post a reply.

Did you know that you can turn a $20 digital scale into a live weight sensor using our kit with a few extra parts? Learn more...