2
\$\begingroup\$

I just built an AVRISP with an old Arduino Nano (ATmega328p), and I tried to flash a simple blink program onto an ATmega328 (non-picopower). The first time I flashed the program, everything worked out great — the 1000ms on and 1000ms off interval were as I expected. However, I changed the off interval to 100ms, and suddenly the period was almost 9 seconds in total — about 8 seconds on and .8 seconds off. Flashing the original 1000ms on and off intervals resulted in an elongated period as well.

I am using the Makefile from a simple blink tutorial; the only thing I've changed is the port designation and MCU. Given that, I believe that the issue lies in my ISP... but what could cause an initial success, then repeated failure? If you need any more information (header or hex dump, etc.) then let me know and I'll be happy to oblige.

\$\endgroup\$
2
\$\begingroup\$

The problem is that your definition of F_CPU doesn't match the hardware. On MCUs fresh from Atmel the CKDIV8 fuse (which divides the CPU clock by 8) is programmed, so be sure to unprogram it if needed if you haven't already.

\$\endgroup\$
  • \$\begingroup\$ Wouldn't an F_CPU mismatch affect only the blink frequency but not the duty cycle? The 50% blink duty cycle changed to ~90% after programming the second time. \$\endgroup\$ – JRobert May 30 '14 at 20:17
  • \$\begingroup\$ @JRobert: "However, I changed the off interval to 100ms ..." "... the only thing I've changed is the [...] MCU. \$\endgroup\$ – Ignacio Vazquez-Abrams May 30 '14 at 20:37
  • \$\begingroup\$ Forgive the amateur followup, but...I took your advice, and it definitely seems that F_CPU is the culprit. I deprogrammed CKDIV8 and then set F_CPU to 20000000 (m328's run at 20MHz). However, now it blinks far too fast - what did I do wrong? \$\endgroup\$ – TSL May 31 '14 at 6:02
  • \$\begingroup\$ Ah, nevermind - didn't generate clean headers. Thank you for the advice! \$\endgroup\$ – TSL May 31 '14 at 6:07
  • \$\begingroup\$ @IgnacioVazquez-Abrams: Right - missed that. \$\endgroup\$ – JRobert May 31 '14 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.