This is only a preview of the January 2021 issue of Silicon Chip. You can view 42 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "AM/FM/SW Single-Chip Digital Radio":
Items relevant to "MiniHeart: A Miniature Heartbeat Simulator":
Items relevant to "The Bass Block Subwoofer":
Items relevant to "Busy Loo Indicator":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
The
AVR128DA48
and the
Curiosity Nano
evaluation board
By
Tim Blythman
The AVR DA Curiosity Nano Evaluation Kit demonstrates Microchip’s new
range of AVR128DA microcontrollers. These have several very significant
advantages over commonly used AVRs, such as much more flash memory
and RAM, a higher operating speed, 12-bit ADC channels and a 10-bit DAC.
Despite all this, they actually cost less than the ATmega328P!
W
hen we saw that the new AVR DA family AVR
chips were available, we had to try them out.
They cost around $2.50 even in single quantities,
slightly less than an ATmega328P.
But they have four times the flash memory, eight times
the RAM and greatly enhanced peripherals. If you’re designing a new circuit around an AVR, it would be silly not
to use one of these.
While some micros have cryptic part numbers, the AVR128DA series is quite straightforward. The “AVR” means
that it is an AVR processor (originally from Atmel, now
part of Microchip). The “128” means that it has 128kB of
program (flash) memory and the “DA” refers to this particular AVR family. There are also AVR32DA and AVR64DA
parts with 32kB and 64kB of flash memory, respectively.
The two digits following the “DA” are simply the number
of pins that the part has. The parts in this series are AVR82
Silicon Chip
128DA28, AVR128DA32, AVR128DA48 and AVR128DA64.
These are available in various packages and footprints,
which are described by further suffixes.
When we looked at the ATtiny816 in January 2019
(siliconchip.com.au/Article/11372), we thought it looked
like a fair competitor to the ATmega328 (as found in the
Arduino Uno board). In fact, with more ADC (analog-todigital converter) channels, it was an tinyAVR series chip
that could put its bigger (megaAVR) sibling to shame. The
AVR DA family is even more impressive – see Table 1.
Like the ATtiny816, the AVR128DA series has Event
System and Configurable Custom Logic (CCL) hardware.
These two peripherals handle in hardware what would
have previously been done with software, freeing up processor time. The comparators and 10-bit DAC allow arbitrary trigger voltage thresholds to be set for external signals.
One example of the benefits of the Event System is that,
Australia’s electronics magazine
siliconchip.com.au
instead of a timer triggering an interATmega328
ATtiny816
AVR128DA28 AVR128DA48
rupt which then starts the ADC sam#
pins
28
20
28
48
pling, it’s possible to configure the
SRAM
2k
512b
16k
16k
timer event to trigger the ADC directly, reducing latency and procesFlash
32k
8k
128k
128k
sor overhead.
EEPROM
1k
128b
512b
512b
Clearly, these chips are even more
Max.
clock
20MHz
20MHz
24MHz
24MHz
potent than their predecessors. With
# ADC
6 x 10-bit
12 x 10-bit
10 x 12-bit
18 x 12-bit
substantial RAM and flash memory,
they put the ATmega328 from the Ar# GPIOs
21
18
23
41
duino Uno to shame.
# timers
3
4
6
8
While the amount of EEPROM is
#
DACs
0
1
x
8-bit
1
x
10-bit
1
x
10-bit
reduced, like many AVR parts, they
are also capable of writing directly to
# USARTs
1
1
3
5
their flash memory. Thus the reduced
# HW SPI
1
1
2
2
EEPROM is more than offset by the
# HW TWI
1
1
1
2
substantial increase in flash memory
Programming
ISP
UPDI
UPDI
UPDI
that is available for storing data.
Also of note are the numerous 12Table 1 – comparison of four AVR micros.
bit ADC channels and the UPDI programming interface. Since the UPDI
interface only uses one pin, no GPIO ports are comproOther settings can be changed by copying simple text
mised by being connected to the programming interface.
files with a specific format and content.
You can download a complete datasheet for these deThe AVR128DA48 itself (U200) has nearly the bare minivices from http://ww1.microchip.com/downloads/en/ mum of surrounding components. A 2.2µF capacitor proDeviceDoc/40002183A.pdf
vides bulk bypassing. Three 100nF capacitors locally bypass
the supply (two on digital VDD and one on analog VDD).
Available packages
The analog supply is fed via an inductor for extra filtering.
While the device fitted to the AVR128DA Curiosity Nano
A 32kHz crystal and its accompanying capacitors are
board is the 48-pin TQFP (thin quad flat pack) version, there connected to supply a reference frequency for the RTC (reis also a 28-pin version available in a DIP package. We’ll al-time clock) peripheral. The internal oscillator can clock
detail both below in our comparison with other AVR parts. the processor at 24MHz and a PLL allows peripherals to
We’ll describe how to build a circuit around a bare AVR- run at 48MHz, across the full supply range down to 1.8V.
128DA28 chip later; the DIP version is an obvious candidate for breadboarding.
The AVR128DA48 Curiosity Nano Evaluation Kit comprises the AVR128DA48 noted earlier, surrounded by a
small number of extra components – see its complete circuit,
shown in Fig.1. The PCB also includes an ATSAMD21E18A
32-bit ARM processor (U100), accompanied by its own entourage of components at one end of the PCB (U103-U107).
The ATSAMD21E18A provides the PKOB Nano (PICkit
On Board) programmer function, and is connected to a micro-USB socket to interface to the host computer.
Interestingly, there is a fairly clear line on the Curiosity Nano’s PCB that separates the programmer and its target. There are even jumper pads on the PCB underside so
that the connection between them can be broken if needed
(J101, J201, J203, J205 & J206).
We won’t delve into the details of the programmer; suffice to say that it includes an adjustable voltage regulator
and five tiny level converter ICs, which bring three debug
signals and a UART (TX/RX) pair back to the programmer
for communication.
As well as the PKOB function, it also provides a virtual
COM port (to communicate with the UART on the AVR128DA) and emulates a USB flash drive too – see Fig.2.
The USB drive is only ‘virtual’ and doesn’t work like
a portable flash drive. The files that are present can be
opened to show status information, but can’t be edited.
One of the more interesting features is that you can flash
A block diagram of the AVR128DA family from the datathe AVR128DA48 on the Nano by copying a HEX file to
sheet. Note how the Event System Bus runs in parallel
with the main Data Bus, connecting most peripherals.
the virtual drive.
siliconchip.com.au
Australia’s electronics magazine
January 2021 83
SC
AVR128DA48 CURIOSITY NANO EVALUATION MODULE
Fig.1: like the PCB itself, the circuit for the Curiosity Nano AVR128DA is clearly divided
between the programmer and power supply at left, and the target device at right. Solder
jumpers J101, J201, J203, J205 and J206 can be used to disconnect the two halves.
84
Silicon Chip
Australia’s electronics magazine
siliconchip.com.au
siliconchip.com.au
Australia’s electronics magazine
January 2021 85
parts if you already have a PICkit4.
Programming the Curiosity Nano
Fig.2: five files appear on the virtual USB drive that the
Curiosity Nano AVR128DA presents; they can be dragged
and dropped to change settings. It’s even possible to upload
a HEX file to the AVR128DA48 by copying it to the virtual
drive. Talk about easy to program!
A user pushbutton and LED are also connected via 1kΩ
resistors. These connect to GPIO pins PC7 and PC6, respectively. It’s not much, but allows some basic code to be
tested without needing to connect any external hardware.
In any case, the narrow PCB shape is perfect for fitting to
a breadboard. The edge of the PCB is ringed by a series of
pads which allow a row of pin headers to be friction fitted,
although we found that they were a very tight fit.
The pads are also duplicated as castellated half-holes,
making it possible to solder the headers in place, or even
to solder the board to a matching set of pads on another
board (ie, treating the whole Curiosity Nano as an SMD).
The pads at the end of the board closest to the USB socket
duplicate those pins used by the programmer.
AVR128DA28 in DIP
To do this, you will need the free Microchip MPLAB X
software; see our article on installing and using that software starting on page 48 of this issue.
The basic steps are to write the code, compile it and then
program to the device. We suggest starting with our sample
project (available for download from the SILICON CHIP website) if you haven’t worked with MPLAB X before. Open
that project, expand the “Source Files” to see “main.c” and
double-click to open it.
We’ll quickly walk through this example.
The first #define for F_CPU lets the code know how fast
the instruction clock is. By default, these parts start up
with a 4MHz primary clock frequency, which can be later
changed in software.
There is no need to change this for our simple examples.
The blink() function is called by main(), and it sets pins
PA7 and PC6 as outputs (setting the DIRSET register). Then,
it goes into an infinite loop, cycling between setting these
pins high (OUTSET) and low (OUTCLR), separated by onesecond delays.
With the project open, click “Clean and Build” (hammer and brush icon). You should get a “BUILD SUCCESSFUL” message.
AVR devices require the fuse bits to be read before programming. These are the same as configuration bits on PIC
devices, and the MPLAB X software calls them configuration bits for consistency.
This can be done by clicking the Window-> Target Memory Views -> Configuration Bits menu item. The top-most
icon with the green arrow facing up is “Read Configuration Bits”. Click this and allow the process to complete
(see Fig.5).
You may need to select the programming tool if you are
using something different, but if this read occurs successfully, then Programmer communication is working fine.
We also tried working with an AVR128DA28 on a breadboard. Our minimal setup is shown in Fig.3, and the corresponding circuit in Fig.4.
The two supply pins, 20 (VDD) and 14
(AVDD) are bypassed to nearby GND pins
(21 and 15) by 100nF capacitors. A 10kΩ
l
resistor pulls up the RST pin (18) to VDD.
This is about the minimum needed for normal operation.
For programming, we connected pins 2,
3 and 4 (VDD, GND & UPDI) of a PICkit4 to
pins 20, 21 and 19 of the AVR128DA28 via
a six-pin SIL header. Because the PICkit4
cannot supply power to the target in UPDI
mode (as it can with some PICs in ICSP
mode), external power must be supplied to
the VDD and GND rails.
We also fitted a LED and 1.1kΩ resistor
between pin 1 (PA7) and GND, to provide
the hardware equivalent of a “hello world”
program (a blinkenlight!).
Since the PC6 and PC7 pins (as used for
the button and LED on the Curiosity Nano)
are not present on the 28-pin variant, we did
Fig.3: this minimal breadboard circuit for the AVR128DA28 needs only
not do much more than verify that we could a handful of passive parts as, by default, the device is clocked from an
flash the LED successfully. Still, this is an even internal oscillator. The LED and resistor are optional but are useful to
cheaper way to experiment with these new AVR test that it is working as expected.
86
Silicon Chip
Australia’s electronics magazine
siliconchip.com.au
Fig.6: these debugging buttons are only visible after a debugging session has started. Most of these buttons also have
keyboard shortcuts assigned to them, which is handy for
quickly stepping through code while debugging it.
Fig.5: the small button at upper left in the Configuration Bits
window reads the device’s configuration bits (or fuses in AVR
parlance). Then the fuse settings can be changed and exported
by using the Generate Source Code button at the bottom.
We would advise not changing anything here, even if
you are familiar with PIC configuration bits. Unlike PIC
programming, some AVR fuse bits (particularly some clock
settings) can prevent the device from being programmed.
You should now be able to press the “Run” button to
program the Curiosity Nano. When this completes, you
should see the LED on the Nano flashing at around 0.5Hz.
Debugging
One of the great features of MPLAB X is the ability to debug a project as it runs. If you’ve worked with BASIC programs or the Arduino IDE, you’re probably familiar with
the use of PRINT statements to display the internal program
state and determine why it isn’t doing what it should. This
can be very helpful and can often give enough information
to get to the bottom of a problem.
But it can also interfere with program operation, and you
cannot pause the running program to allow it to be examined in depth. The debugging feature of MPLAB X operates quite seamlessly and can halt the running program to
inspect its internal state. You can even set ‘breakpoints’ to
allow the program to pause operation at a certain point in
its operation automatically.
You might hear it referred to as ICD (in-circuit debugging) to emphasise the fact that you can debug the actual
circuit operation, with all hardware attached and working.
Another handy resource to use during debugging is the
disassembly listing. It can be found under the Window ->
Debugging -> Output -> Disassembly Listing File menu.
The “Load symbols” option needs to be set to allow this.
It can be found under the Properties window, but our example project already has this set. MPLAB X will show
you where to set this if it is not.
The disassembly listing contains both the source code
and also the specific machine instructions and their locations in program memory. It can be a handy tool to use on
its own, even without the debugger.
A debugging session is started by clicking the “Debug
Project” button, just below the main menu bar. Then, the
buttons in the Debugging bar (Fig.6) become available.
These buttons should give you a good idea of how handy
the MPLAB X debugger can be.
From left to right, the first button is Stop, which ends
the current debugging session. This is followed by Pause,
Reset and Continue. The remaining buttons provide different Step options, allowing the program to run until, for
example, the next statement (Step Over) or until the current function ends (Step Out).
Hence, the importance of the disassembly listing; the debugger needs to know what point in program flash memory corresponds to what line of code to be able to highlight
where it stops.
A good example of stepping would be to see what course
a program takes on an if statement or switch statement.
After starting a debugging session, click Pause and you
should see the editor window highlight a line of the source
code in green (it’ll probably be a line from “delay.h”, as
that is where the program spends most of its time). In the
bottom right window, there should be a “Variables” tab.
Build the world’s most
popular D-I-Y computer!
ALL-NEW COLOUR
See the articles in
SILICON CHIP
July & August 2020
2
480MHz, 32-bit
processor; 9MB of
RAM; 2MB flash memory;
800 x 600 pixel colour display
Don’t miss your opportunity to
experience Australia’s own worldclass, world-famous single board
computer that you build and
program yourself. And it’s so easy
– all the hard work is already done
for you: the heart of the Colour
Maximite 2 (the Waveshare CPU
Module) is completely pre-assembled and soldered!
Short Form Kit includes:
All this
for only
Note: does not include plastic instrument case, CR12xx cell or
USB power supply/cable. Photo above shows completed unit.
Subscriber’s price
is just
$
14000
10%!
$
12600
Plus $10.00
p&p in Aust
Waveshare CPU module pre-loaded with MMBasic
the PCB – high quality board with silk screening component ID
SILICON CHIP Subscribers:
front & rear panels – already drilled/punched so you don’t have to!
$AVE
and all other components required to build the Colour Maximite 2
Fig.4: a protoboard mockup of the circuit opposite.
Obviously this layout is not sacrosanct – but if you’re not
familiar with breadboards, follow this one to avoid mistakes.
siliconchip.com.au
+ p&p
Order now (or more information) at
www.siliconchip.com.au/shop/20/5508
Australia’s electronics magazine
January 2021 87
Click this and then click on “<Enter new watch>”.
A watch is a variable which the debugger can read and
display. It isn’t updated in real-time, but can be inspected
any time that the program is paused and is highlighted in
red if it has changed. While variables only exist as bytes
in RAM, the debugger knows what type it is (eg, int, char
or pointer) and can display other appropriate information.
For example, the value of a pointer’s target can be resolved and displayed, or a character array can be displayed
as a text string.
One interesting value to display is “PC”, the program
counter, which is effectively one of the program’s internal
variables. You can pause the program and check that the value of PC matches the line of code as shown in the assembly
listing. Of course, our example program is elementary. But
also, modern compilers are very good at optimising code,
which sometimes means that even the debugger can have
trouble mapping the source code to the program memory.
One more useful tool that the debugger provides is called
a breakpoint. This is a point in the source code which will
automatically pause the program when it is reached. Cleverly setting breakpoints can help pin down where a problem might be occurring.
For example, you could set a breakpoint just before a
switch statement, then step through the switch statement
to check the logic and values of critical variables to ensure
that the correct branch is taken.
When we reviewed the PICkit 4 in September 2018
(siliconchip.com.au/Article/11237), we also gave a brief
overview of in-circuit debugging (ICD). We noted, amongst
other things, that the PICkit 4 was much more responsive
than the PICKit 3 during debugging. We found that the
PKOB debugger on the Curiosity Nano was similarly fast.
Example code
Microchip has provided some sample code for these processors at siliconchip.com.au/link/ab4m
These are actually Microchip Studio (previously known
as Atmel Studio) projects, but they contain a “main.c” file
which can be added to a blank MPLAB X project. We tested this with the “AVR-DA_LED_dimming_PWM” example,
and it worked with no changes to the code.
Examples like these are great resources for getting started with microcontroller peripherals. Typically, you would
have little more than a list of registers from a data sheet.
The examples provide working code that can be used directly. This even helps with subtle things like checking
the correct syntax for manipulating the correct registers.
Conclusion
The AVR DA family of microcontrollers is an impressive update to the AVR roadmap, while the AVR128DA48
Curiosity Nano Development Board provides a simple and
economical way to try out the new features. You can get
these parts from:
Digi-Key: https://www.digikey.com.au
Mouser: https://au.mouser.com
Microchip Direct: https://www.microchipdirect.com
Microchip’s part number for the Curiosity board is
DM164151, and the current price is around AU $25, excluding delivery costs.
SC
Subscribe to SILICON CHIP and you’ll not only $AVE MONEY
but we GUARANTEE you’ll get your copy!
When you subscribe to SILICON CHIP (printed edition) in Australia we GUARANTEE you’ll
never miss an issue!
Subscription copies are despatched in bulk at the beginning of the on-sale week (due on
sale the last Thursday of the previous month). It is unusual for copies to go astray in the
post – but when we’re mailing out many thousands of copies, it is inevitable that Murphy
might strike once or twice (and sometimes three or four times!)
So we make this promise to you: if you haven’t received your SILICON CHIP anywhere in
Australian by the middle of the month of issue (eg, issue datelined “September” by 15th
September) send us an email and we’ll post you a replacement copy in our next mailing
(we post out twice a week). Send your email to: silicon<at>siliconchip,com.au
Remember: it’s cheaper to subscribe anyway - do the maths and see the savings!
Remember: we pick up the postage charges – so you $ave even more!
Remember: you don’t have to remember to go out and buy your copy - it’s delivered right to your letter box!
Remember: your newsagent may have sold out when you get there - and you’d miss out!
Remember: there is also an on-line version you can subscribe to if you’re travelling
Convinced? We hope so! And we make it particularly easy to take out a subscription –
for a trial 6 month, a standard 12 month or a giant 24-month with even bigger savings!
To subscribe, simply go to our website – www.siliconchip.com.au – click on the “subscriptions” tab and follow the prompts.
We accept payment by Paypal, Visa, Mastercard, EFT/Direct Deposit or Cheque/Money Orders (sorry, no Amex or Diners).
We’re waiting to welcome YOU to the SILICON CHIP family!
88
Silicon Chip
Australia’s electronics magazine
siliconchip.com.au
|