Two 22pF capacitors for the crystal oscillator. One 0.1uF capacitor for decoupling between Vcc and ground.
The crystal oscillator is optional. If you don't have one, you don't need the two 22pF capacitors.
If you have a 20MHz crystal, you still need the 22pF caps.
You will also need a different bootloader, or the extra 25% speed will make millis() and micros() run faster and also screw up the UART speeds, so you won't be able to download code.
This add-in to the IDE will let you select different speeds, 20 MHz is one of them. You will have to burn the bootloader so the fuses are set to use external crystal and the 20 MHz is used.
CrossRoads:
If you have a 20MHz crystal, you still need the 22pF caps.
You will also need a different bootloader, or the extra 25% speed will make millis() and micros() run faster and also screw up the UART speeds, so you won't be able to download code.
This add-in to the IDE will let you select different speeds, 20 MHz is one of them. You will have to burn the bootloader so the fuses are set to use external crystal and the 20 MHz is used.
I need to count down in seconds, with "per second" accuracy and a range from 1 second to 30 minutes (or even 60 minutes) Would the build-in oscillator be accurate enough for this, or do I absolutely need an external crystal?
And, will the 22pf capacitors I have work for decoupling, without a crystal, or are they not needed then?
6v6gt:
Two 22pF capacitors for the crystal oscillator. One 0.1uF capacitor for decoupling between Vcc and ground.
The crystal oscillator is optional. If you don't have one, you don't need the two 22pF capacitors.
22pF won't do much for decoupling, you need the 0.1uF. One on VCC, one on AVCC.
The internal 8MHz RC oscillator may be good enough for the range you are measuring. Off the shelf, it can be several percent off from 8 MHz, you may not notice that in an hour. It can also be tuned, there's a calibration byte you can set. I've never tried and always use 16 MHz crystals in my designs.
CrossRoads:
22pF won't do much for decoupling, you need the 0.1uF. One on VCC, one on AVCC.
The internal 8MHz RC oscillator may be good enough for the range you are measuring. Off the shelf, it can be several percent off from 8 MHz, you may not notice that in an hour. It can also be tuned, there's a calibration byte you can set. I've never tried and always use 16 MHz crystals in my designs.
I want to run a count down timer, so I don't think there'll be time for "drifting", as the timer will be reset every couple minutes. I guess I could "reset" it via a push button switch hard wired to the reset pin
Reset will not be needed.
Use micros() to capture start time and elapsed time, when elapsed time exceeds event duration you are done.
void loop(){
currentTime = micros();
elapsedTime = currentTime - previousTime;
if (elapsedTime >=oneSecond){ // oneSecond defined as 1000000UL, 1 million microseconds. Will have ~ 4uS accuracy
// update one second display or something
previousTime = previousTme + oneSecond; // set up for next time period
}
Add some code to read start button, end button, whatever.
CrossRoads:
Reset will not be needed.
Use micros() to capture start time and elapsed time, when elapsed time exceeds event duration you are done.
void loop(){
currentTime = micros();
elapsedTime = currentTime - previousTime;
if (elapsedTime >=oneSecond){ // oneSecond defined as 1000000UL, 1 million microseconds. Will have ~ 4uS accuracy
// update one second display or something
previousTime = previousTme + oneSecond; // set up for next time period
}
Add some code to read start button, end button, whatever.
Well, since this is a countdown timer, there will be a button to reset the timer
If you don’t use the recommended decoupling capacitors, reliable operation is not guaranteed and the circuit may not work at all.
I recommend that you splurge, and buy a few 100 nF (0.1 uF) capacitors, or salvage them from some junked electronics. They are required, so you will find them just about everywhere.
You need 0.1uf ceramic capacitors to ensure reliable operation. You'll also need it if you want to do serial programming via a bootloader and have the autoreset functionality (instead of having to have a perfectly timed press of reset) - the dtr-autoreset circuit needs a 0.1uf cap, and you'll also need them if you ever want to work with any digital integrated circuit in the future as well (basically every IC needs a decoupling cap, 0.1uf is almost always what they need).
You can buy 100x 0.1uf through-hole ceramic caps on ebay for under $2 shipped, or for like $6 from digikey/mouser (not counting shipping).
They're in everything, used everywhere, and probably the single electronic component you'll use more than any other in hobby electronics. Buy some.
DrAzzy:
You need 0.1uf ceramic capacitors to ensure reliable operation. You'll also need it if you want to do serial programming via a bootloader and have the autoreset functionality (instead of having to have a perfectly timed press of reset) - the dtr-autoreset circuit needs a 0.1uf cap, and you'll also need them if you ever want to work with any digital integrated circuit in the future as well (basically every IC needs a decoupling cap, 0.1uf is almost always what they need).
You can buy 100x 0.1uf through-hole ceramic caps on ebay for under $2 shipped, or for like $6 from digikey/mouser (not counting shipping).
They're in everything, used everywhere, and probably the single electronic component you'll use more than any other in hobby electronics. Buy some.
I'm not in the USA or UK, so getting stuff off eBay takes upto 3 months, and it quite expensive where I am. But I have managed to get some capacitors
You will also need a different bootloader, or the extra 25% speed will make millis() and micros() run faster and also screw up the UART speeds, so you won't be able to download code.
For Bd 4800 and 9600, the errors for both 16 MHz and 20 MHz oscillations are the same (0.2%).There should not be any problem to upload the codes at these baud rates.
There is not problem to upload the code if the correct bootloader is used (F_CPU is hard coded) or if the UART speed is screwed up. CrossRoads is right.
However, once the sketch is inside and it was compiled for 20MHz, it will work as expected. Millis, micros include.
GolamMostafa:
For Bd 4800 and 9600, the errors for both 16 MHz and 20 MHz oscillations are the same (0.2%).There should not be any problem to upload the codes at these baud rates.
Ironically I am having problems uploading code to the chip. I got the bootloader laoded but can't get the blink sample loaded at all. Not sure if it's electronics related, or software, yet.
This is the error I get (with debugging enabled)
Arduino: 1.6.5 (Windows 8.1), Board: "ATmega328P Stand Alone (Arduino as ISP)"
Sketch uses 2,386 bytes (7%) of program storage space. Maximum is 32,768 bytes.
Global variables use 206 bytes of dynamic memory.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM3 -b19200 -Uflash:w:C:\Users\Rudi\AppData\Local\Temp\build1354893621707715878.tmp/Blink.cpp.hex:i
avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch
System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"
Using Port : COM3
Using Programmer : stk500v1
Overriding Baud Rate : 19200
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x15
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x15
AVR Part : ATmega328P
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : STK500
Description : Atmel STK500 Version 1.x firmware
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x02
avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x10
Hardware Version: 1992112261
Firmware Version: -41313155.-2
Topcard : STK502
Vtarget : 1.8 V
Varef : 0.0 V
Oscillator : Off
SCK period : 0.1 us
avrdude: stk500_initialize(): (b) protocol error, expect=0x10, resp=0x01
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x10
avrdude done. Thank you.
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
I followed this tutorial, since I have an Arduino Nano as well (I don't have an UNO)
Using Arduino IDE 1.6.5, with the following changes made to boards.txt: