PllLdr2 is a port of PllLdr to Arduino Pro hardware (inc Nano, Promini)


This page is an addendum to MCU to load PLL configuration registers. and contains documentation of the differences with the Arduino Pro hardware based PllLdr2 and should be read in conjunction with it.

This is a work in progress, documentation of a current project that will change, a 'living' document. Consider any code published as Beta release, ie experimental. Active code development continues as the code base is generalised to support a range of applications.

EEPROM data structures

The EEPROM contains key configuration data. The first byte is a version number for the data structure. That is followed by an options word and variable length table of contents, each entry consisting of a one byte length field and uint16 offset of a data item. The following data items are PLL register sets, each comprising a variable number of register fields. Each register field starts with a one byte length field followed by a variable number of register content bytes. (Some chips use variable length registers, eg AD9859.)

A buffer is allocated for a register set, register sets must each be no more than that length including the register set length byte and each register length byte. For example, a set of 5 x 4 byte registers takes 1+5*(4+1) bytes or 26 bytes of buffer space.

The order of data bits transmitted is controlled by the DORD option bit. The bit order can also be reversed in the EEPROM image, add the variable and value "rbo":"R" with an appropriate comma separator to the input file and the bit image of each register byte in the EEPROM file produced will be a reverse of the input data.

u16 types are stored backwords or little endian in the EEPROM.

Some options bits enable PLL specific features. There are two bytes of options bits.

Table 1: Options[0] bits
Bits Description
0 invert sel
1 no debounce
2 unused
3 invert /CS
4 Gray code input
5:6 startup delay 0.1*(1+2^(2*x))s
7 invert SCK (CPOL)
12 one of 14 encoding with banking using bit 0
13 one of 15 encoding
14 Reserved
15 Reserved

Bank selection uses sel[0] (subject to invert sel) to select odd or even frequency slots in the EEPROM table.

Table 1: Options[1] bits
Bits Description
0:1 SPR
5 Use D0, D1 for 16bit input


Fig 1:

Fig 1 shows the use of the speed bits in Options[1].


Table 2: Pinout
MCU Nano (ATMega 328P) ProMini (ATMega 328P) ISP 10pin ISP 6pin Comments
Vcc Vcc Vcc 2 2  
GND GND GND 4,6,8,10 6  
SCK D13/SCK D13/SCK 7 3  
MOSI D11/MOSI D11/MOSI 9 1  
MISO D12/MISO D12/MISO 1 4  
/SS D10//SS D10//SS      
Sel[0] D2 D2      
Sel[1] D3 D3      
Sel[2] D4 D4      
Sel[3] D5 D5      
Sel[4] D6 D6     1 of n mode only
Sel[5] D7 D7     1 of n mode only
Sel[6] D8 D8     1 of n mode only
Sel[7] D9 D9     1 of n mode only
Sel[8] A0 A0     1 of n mode only
Sel[9] A1 A1     1 of n mode only
Sel[10] A2 A2     1 of n mode only
Sel[11] A3 A3     1 of n mode only
Sel[12] A4 A4/JP2-1     1 of n mode only
Sel[13] A5 A5/JP2-2     1 of n mode only
Sel[14] D0 D0/RX     1 of n mode only (OPTSEL16)
Sel[15] D1 D1/TX     1 of n mode only (OPTSEL16)

It is inconvenient to use TX,RX for sel[] on the Nano due to the FTDI chip (or whatever), but the full 16 bit selection mode can be obtained using OPTSEL16  on other modules, like the Pro-Mini.

Fig 2:

Fig 2 shows a typical SPI capture.


Programming the chip

There are two options:

A bootloader will be convenient for most applications and the procedure is described below.

Install special Optiboot bootloader

Arduino Nano comes with an Optiboot bootloader that is unable to write to EEPROM, so we will replace it with a build of Optiboot that does support EEPROM. The bootloader occupies the top 1024B of flash, so it requires different fuse settings to the standard bootloader.

The command file below will load the modified Optiboot (link below) and set the fuses and locks using an inexpensive USBASP programmer... but you need to review it and change some default file paths.

@echo off

echo Processing
set FL=
if *%FL%==* set FL=d:\src\optiboot\optiboot\bootloaders\optiboot\optiboot_atmega328.hex

echo FL=%FL%
set PRG=usbasp
set PORT=usb
set OPTS=-B 10
set DEVICE=atmega328p
set AVRDUDE=avrdude
rem preserve EEPROM
rem EFUSE=0x06 for 1.8V BOD, 0x05 for 2.7V
set EFUSE=0x06
set HFUSE=0xD4
set LFUSE=0xFF

echo Write boot loader (%FL%)...

%AVRDUDE% %OPTS% -c %PRG% -P %PORT% -p %DEVICE% -e -Ulock:w:0x3F:m -Uefuse:w:%EFUSE%:m -Uhfuse:w:%HFUSE%:m -Ulfuse:w:%LFUSE%:m
timeout /nobreak /t 1 >nul
%AVRDUDE% %OPTS% -c %PRG% -P %PORT% -p %DEVICE% -U flash:w:%FL%:i -Ulock:w:0x0F:m
goto cleanup


Once installed (one off), application programming of flash and EEPROM is done using the Nano USB port and bootloader, example later.

Command file for programming application flash and EEPROM using AVRDUDE and bootloader

The following is an example command file for  programming application flash and EEPROM using AVRDUDE and bootloader using the USB port on the Nano. Note that some defaults need adjustment to suit your own environment.

@echo off
if *%1==* goto usage

echo Processing %1

set PRG=arduino
set DEVICE=m328p
set PORT=com7
set OPTS=-B 5
set AVRDUDE=avrdude

if *%2==* goto eeprom
if *%2==** goto eeprom
set FLASH=%2
if *%2==*# set "FLASH=D:\src\PllLdr2\PllLdr2\Debug\PllLdr2.hex"

echo program flash (%FLASH%)...
echo %AVRDUDE% %OPTS% -c %PRG% -P %PORT% -p %DEVICE% -U flash:w:%FLASH%:i
%AVRDUDE% %OPTS% -c %PRG% -P %PORT% -p %DEVICE% -U flash:w:%FLASH%:i
timeout /nobreak /t 1 >nul

if *%1==** goto cleanup
echo program eeprom (%1.hex)...
echo %AVRDUDE% %OPTS% -c %PRG% -P %PORT% -p %DEVICE% -U eeprom:w:%1 
%AVRDUDE% %OPTS% -c %PRG% -P %PORT% -p %DEVICE% -U eeprom:w:%1:i 
timeout /nobreak /t 1 >nul
goto cleanup

echo usage: prg eepromfile flashfile
goto end


Getting PllLdr2

The hex code for PllLdr is copyright © Owen Duffy, 2020. All rights reserved. Permission is granted for non commercial use (ie for non commercial application and use in products not commercially manufactured. For other uses, contact the webmaster for further licensing information. The hex code is available subject to those conditions at the link below.

Using the special build Optiboot bootloader in Arduino IDE

The special build Optiboot bootloader with EEPROM support for the Nano can be used in the Arduino IDE, just add the following section to %LOCALAPPDATA%\Arduino15\packages\arduino\hardware\avr\VERSION\boards.local.txt (fixing the VERSIONr as appropriate), and copying the bootloader hex to the stated file path and name in the following as appropriate.

## Arduino Nano w/ ATmega328P (Opti+EEPROM)
## --------------------------
nano.menu.cpu.atmega328OptiE=ATmega328P (Opti+EEPROM)




This will add a menu processor variant of the Nano entitled Opti+EEPROM.



Version Date Description
1.01 25/07/2020 Initial.


© Copyright: Owen Duffy 1995, 2021. All rights reserved. Disclaimer.