Application Note: Arduino Due Timer Control

Application Note - Arduino Due Timer ControlThe Arduino platform is not only the ideal solution for the hobbyist, due to the 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.

The following image demonstrates an example of timing a serial transmission between two nodes.

As is demonstrated in the picture, the message frequency will be between 50 to 200 msec.

A timeout will occur when a time of greater than 750 milliseconds elapsed between two message packets when more packets were expected. A timeout will cause a connection closure.

A connection is considered closed when:

  1. The sender of a data message sends the last Data Transfer package.
  2. A timeout occurs.

Not all applications will be as complex, but this example demonstrates how important it is to have a set of timer functions that integrate easily without the need for 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.

This is a work in progress.

Table of Content

  • The Arduino Due
    • The ARM Cortex-M3 Processor
    • System Description
    • The Arduino Due
  • Timer Control
    • Delay Functions
    • Elapsed Time Functions
      • micros() Resolution Using the Arduino Due
    • Arduino Playground – Timer Sample Code
    • Arduino Due Interrupt-Driven Timer Control
      • Interrupt-Driven Timer Control Sample
      • Timer Control Sample C/C++ Code
  • Download the Code Sample
  • Recommended Literature

Published by

Copperhill Technologies
158 Log Plain Road
Greenfield, MA 01301

https://copperhilltech.com

© 2018 Copperhill Technologies Corporation. All rights reserved.

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher.

Trademarks

All trademarks or registered trademarks are the property of their respective owners.

Disclaimer

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.

Document Lifetime

Copperhill Technologies Corporation may occasionally update online documentation between releases of the related application note. Consequently, if this document was not downloaded recently, it may not contain the most up-to-date information.

Contact Us

Despite all efforts in preparing this eBook, there is always the possibility that some aspects or facts will not find everybody’s approval, which prompts us, author and publisher, to ask for your feedback. If you would like to propose any amendments or corrections, please send us your comment. We look forward to any support in supplementing this eBook, and we welcome all discussions that contribute to making the topic of this book as thorough and objective as possible.

To submit amendments and corrections please log on to our website at
https://copperhilltech.com/contact-us/
and leave a note.