Site Information

 Loading... Please wait...

Blog

Application Note: Arduino Due Timer Control

Posted by Wilfried Voss on

Application Note - Arduino Due Timer Control

The Arduino platform is not only the ideal solution for the hobbyist, due to low price and ease of programming; it is also a great tool for professionals who are looking for quick prototyping.

This application note will address the very specific topic of timer control for the  Arduino Due.

The Arduino platform does provide library functions dedicated to timers, and they cover all Arduino boards, including the Arduino Due. However, the Due takes up a special position in the Arduino product line of processors.

It is, after all, the first ARM-based Arduino development board, which accounts for special considerations compared to the standard, ATmega-driven boards. The ARM Cortex-M3 processor’s versatility opens the door to more sophisticated applications, and that includes timer programming.

A timer is a clock that controls the sequence of an event while counting in fixed intervals of time. A timer is used for producing precise time delay. Secondly, it can be used to repeat or initiate an action after/at a known period of time.  Most processors have timers incorporated on the chip. They not only generate time delays but they can also be used as counters.
Source: EngineersGarage – https://www.engineersgarage.com/definitions/what-is-timer

This definition of timers is important, because this document is not about timekeeping, i.e. the management of date and time of the day.

The application of timers can be as simple as a blinking LED or as complex as detecting an interruption in a serial data communication.

Not all applications will require complex timing algorithms, but it is beneficial to have a set of timer functions that integrate easily without the need of a major learning curve. My timer library includes functions to initialize, load, start and stop a timer as well as checking the timer count and status.

As I mentioned previously, the Arduino platform already provides library functions dedicated to timers, and there are more samples available through the Arduino Playground. However, my focus was not only on increased precision but also adaptability to other hardware platforms, e.g. using the same concept on an NXP LPC17xx processor.

Last, but not least, the following assumes some basic knowledge of embedded programming with the Arduino platform. Should that not be the case, please refer to the literature appendix, especially the books written by Simon Monk. Be assured that the learning curve is minimal.

My point is, I will not engage in repeating topics that have already been covered extensively by others, but I will reference resources where necessary.

Download the Application Note

The information provided in this document is provided "as is" without warranty of any kind. Copperhill Technologies Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Copperhill Technologies Corporation be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Copperhill Technologies Corporation or its suppliers have been advised of the possibility of such damages.

https://copperhilltech.com/content/Application Note - Arduino Due Timer Control.pdf

Download the Code Sample

The Arduino Due Timer Control sample code (sketch) is a free download (zip file) and it can be downloaded here:

https://copperhilltech.com/content/Arduino-Due-TimerControl.zip

Neither the author nor the publisher are responsible for technical support of any project you derive from or add to the sample code. The Arduino Due Timer Control sketch is a free software; you can redistribute it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. With downloading this programming sample, you confirm that you have read and agree with these terms and conditions.

Recommended Literature

Programming Arduino: Getting Started with Sketches

by Simon Monk

This thoroughly updated guide shows, step-by-step, how to quickly program all Arduino models. Programming Arduino: Getting Started with Sketches , Second Edition, features easy-to-follow explanations, fun examples, and downloadable sample programs. Discover how to write basic sketches, use Arduino’s modified C language, store data, and interface with the Web. You will also get hands-on coverage of C++, library writing, and programming Arduino for the Internet of Things. No prior programming experience is required!

Programming Arduino Next Steps: Going Further with Sketches

by Simon Monk

In this practical guide, electronics guru Simon Monk takes you under the hood of Arduino and reveals professional programming secrets. Featuring coverage of the Arduino Uno, Leonardo, and Due boards, Programming Arduino Next Steps: Going Further with Sketches shows you how to use interrupts, manage memory, program for the Internet, maximize serial communications, perform digital signal processing, and much more. All of the 75+ example sketches featured in the book are available for download.

The Definitive Guide to ARM Cortex-M3 and Cortex-M4 Processors

by Joseph Yiu

This new edition has been fully revised and updated to include extensive information on the ARM Cortex-M4 processor, providing a complete up-to-date guide to both Cortex-M3 and Cortex-M4 processors, and which enables migration from various processor architectures to the exciting world of the Cortex-M3 and M4.

This book presents the background of the ARM architecture and outlines the features of the processors such as the instruction set, interrupt-handling and also demonstrates how to program and utilize the advanced features available such as the Memory Protection Unit (MPU).

Chapters on getting started with IAR, Keil, gcc and CooCox CoIDE tools help beginners develop program codes. Coverage also includes the important areas of software development such as using the low power features, handling information input/output, mixed language projects with assembly and C, and other advanced topics.

CAN Bus Prototyping With Arduino Uno - Prototyping Hardware

This post is part of a series about Controller Area Network (CAN Bus) Prototyping With the Arduino Uno. As I had mentioned earlier, it is assumed that you have some basic knowledge of the Arduino, Arduino Sketches, and Arduino Shields. I will nevertheless take the opportunity of mentioning the prototyping hardware and its variants. It is important to know that the [...]

Read More »


Arduino Due - Programming And Debugging Using JTAG ICE And Atmel Studio

Atmel’s SAM3X series MCUs are great for users who want to move further from the world of 8bit/16bit microcontrollers to 32bit ARM Cortex core MCUs. One of the most famous device in this series is SAM3X8E, Atmel’s Smart ARM microcontroller. The development platform of choice for getting started with the SAM3X8E is the Arduino Due board.  The SAM3X8E [...]

Read More »


Arduino Due Firmware Flaw: Problem With Using The USB Programming Port At 230400 Baud And Beyond

One of the improvements that came with the Arduino IDE's updates was an increased baud rate for the Serial Monitor.  Well, there are many time-sensitive applications that will benefit from the speed gain, specifically when using one of the fastest Arduinos around, the Arduino Due with its ARM Cortex M3 processor. However, when you set the Serial [...]

Read More »


ARM Cortex Processors – UART Programming Problem At Baud Rates Higher Than 115200

To say it upfront, I cannot confirm with 100% certainty that all ARM Cortex microcontrollers are affected by the UART programming problem as described in the following, but there are indications that make my assumption very probable. The outcome depends primarily on thorough testing of serial communication applications, but there is evidence to the contrary [...]

Read More »


Programmable, Arduino-Due-Based USB Gateway With Two CAN Bus Ports

As part of our business strategy of providing prototyping solutions for the CAN Bus (including SAE J1939, ISOBUS, NMEA 2000) we have decided to focus more on the Arduino platform, specifically the Arduino Due. The Due, while providing the power of an ARM Cortex M3 processor, comes with two CAN Bus ports per default, however, lacking the [...]

Read More »


Arduino DUE CORE Board With Dual CAN Bus Interface, Real-Time Clock, And SD Card

As I had mentioned in my post, Arduino DUE CORE Board With Dual CAN Bus Interface And Extended Power Supply Range, our business strategy is providing prototyping solutions for the CAN Bus (including SAE J1939, ISOBUS, NMEA 2000), and, in the months to follow, we will increase our focus on the Arduino platform, specifically the Arduino Due. Now [...]

Read More »


Arduino DUE CORE Board With Dual CAN Bus Interface And Extended Power Supply Range

As part of our business strategy of providing prototyping solutions for the CAN Bus (including SAE J1939, ISOBUS, NMEA 2000) we have decided to focus more on the Arduino platform, specifically the Arduino Due. The Due, while providing the power of an ARM Cortex M3 processor, comes with two CAN Bus ports per default, however, lacking [...]

Read More »


Hands-On Recipes To Quickly Build And Understand Arduino Projects And Their Development

The single-chip computer board Arduino is small in size but vast in scope, capable of being used for electronic projects from robotics through to home automation. The most popular embedded platform in the world, Arduino users range from school children to industry experts, all incorporating it into their designs. Arduino Development Cookbook comprises clear and step-by-step [...]

Read More »


Arduino Due Design Flaw: Due Won't Start After Power-Off-On, Requires Reset

I had noticed the problem with resetting the Arduino Due for a while and finally started looking into a solution. In detail, the Arduino Due doesn't reliably start running its sketch after power is applied. This applies when power is applied per USB or through the external power supply. If power is removed for less than five [...]

Read More »