5.7. Programming faster
If you are developing code for an AVR microcontroller, you might need to program it dozens or hundreds of times before the code is good. This section gives tips on how to program your AVR quickly so that you can be more productive.
If you are programming from Atmel Studio, you should try using the F5 key as described in Section 5.2.1. Then you can just press the F5 key to save, build, and program.
If you are using AVRDUDE or GNU Make from the command line, you should know that most shells allow you to press the up arrow to go back to the last command you ran. So you can press up arrow followed by Enter to very quickly run the last command. You should also learn the shortcut key for saving a file in your text editor (often Ctrl+S), and learn your operating system’s shortcut key for switching Windows (often Alt+Tab). Then you can just press a quick sequence of keystrokes to save, switch to the terminal, program the AVR, and switch back.
Setting the ISP frequency
You should make sure to set the ISP Frequency setting on your programmer to the highest value that the AVR can handle. The ISP Frequency setting has a large effect on how fast the programmer sends commands to the AVR. The rest of this section talks about how to determine a good frequency and configure your programmer to use it.
For most or all AVRs:
- The ISP Frequency should be less than 1/4 of the target clock frequency if the target clock frequency is less than 12 MHz.
- The ISP Frequency should be less than 1/6 of the target clock frequency if the target clock frequency is greater than or equal to 12 MHz.
These rules apply to most or all AVRs with an ISP interface. If you want to, you can check to see if these rules apply to your AVR by looking for information about the minimum low and high periods for the serial clock (SCK) input in the “Serial Downloading” or “Serial Uploading” section of your AVR’s datasheet.
Here are some recommended values for typical setups:
|ISP Frequency||Atmel Studio
|20 MHz||3000 kHz(2)||1.843 MHz||-B 0.5|
|16 MHz||2400 kHz(2)||1.843 MHz||-B 0.5|
|12 MHz||1714 kHz(2)||1.843 MHz||-B 0.5|
|8 MHz||1714 kHz(2)||1.843 MHz||-B 0.5|
|4 MHz||750 kHz(2)||1.843 MHz||-B 0.5|
|1 MHz||114 kHz(3)||115.2 kHz||-B 4|
|32.768 kHz||6.98 kHz(3)||7.008 kHz||-B 123|
(1): If the programmer is already configured to use the specified ISP Frequency, you do not need to supply this option to AVRDUDE, but you probably should just in case.
(2): You should select this frequency using the programmer’s configuration software, so that the programmer will use it instead of the 1.843 MHz frequency requested by Atmel Studio and AVRDUDE.
(3): Optional setting: the Atmel Studio and AVRDUDE settings will configure the programmer to use this frequency or a nearby frequency that will also work.
The Pololu USB AVR Programmer v2.x emulates the STK500 programmer from Atmel, which supports 255 different frequencies. Atmel Studio and AVRDUDE only know about those 255 frequencies, and their user interfaces allow you to select one. The fastest frequency the STK500 supports is 1.843 MHz. If you try to select that frequency in AVRDUDE or Atmel Studio, then the programmer will actually use its Max ISP Frequency, a configurable setting which defaults to 1714 kHz.
The ISP Frequency column above lists ISP frequencies supported by the Pololu USB AVR Programmer v2.x which are appropriate for programming an AVR with the specified clock frequency. You can select these ISP frequencies using the
--freq option to
pavr2cmd or you can select them in the configuration utility. Just click the arrow on the “ISP Frequency” input, select the frequency you want to use, and then click “Apply Settings” to apply the settings to the device.
The Atmel Studio Setting column above shows the frequency you should select in Atmel Studio if you are using Atmel Studio to program. Atmel Studio will always set the ISP frequency of the programmer, whether you are using the F5 key to program, or using the Device Programming dialog. If you are using F5 to program, you should check the “Tool” section of your project’s properties and set the ISP Clock to the value listed above. If you are using the Device Programming dialog, you should set the ISP Clock using the “Interface settings” section of the dialog.
The AVRDUDE Option column above shows the command-line arguments you should supply when running AVRDUDE. The “-B” option to AVRDUDE takes one argument, which is a number. The argument specifies the minimum allowed ISP period (one divided by the maximum allowed ISP Frequency) in units of microseconds.
Any change to the programmer’s frequency—whether it comes from the programmer’s software, or Atmel Studio, or AVRDUDE—is stored in the programmer’s non-volatile memory, so it will persist even if the programmer is unplugged and powered off.
You can change the ISP Frequency and Max ISP Frequency settings using the programmer’s configuration software. The Max ISP Frequency must always be equal to the ISP Frequency if the ISP Frequency is 462 kHz or higher. If you set the ISP Frequency to anything higher than 462 kHz, the programmer’s software automatically sets the Max ISP Frequency setting as well.
The programmer itself runs at 12 MHz, so each possible value for the ISP Frequency and Max ISP Frequency settings is equal to 12000 kHz divided by some whole number.
If you have any issues related to the frequency settings, you can use the configuration software to set them back to their default values of 114 kHz for the ISP Frequency and 1714 kHz for the Max ISP Frequency, respectively. You can also try resetting all of the programmer’s settings to their factory defaults by running
pavr2cmd --restore-defaults or selecting “Restore Default Settings” from the “Device” menu of the configuration utility.