+ All Categories
Home > Documents > Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at [email protected] if...

Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at [email protected] if...

Date post: 04-Mar-2021
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
16
Stop Watch Timer Controller Tutorial Philip Vallone 1 | Page Stop Watch Timer Controller Tutorial Overview In this tutorial I will show you how to implement a Stop Watch Timer Controller. This tutorial is based off the Atmel’s LWMesh Peer2Peer Application for the SAMR21 xplained pro. While working on the example project, there was a System Software Timer routine that I wanted to implemented on other projects. This code works like a stop watch. You can start and stop the timer as needed. This can be very useful measuring timeouts. I recently worked on a LWMesh project with 2 SAMR21 Xplained Pro boards. The SAMR21 is a Radio Tranceiver. The project consisted of sending large amounts of data from one board to the next via RF. I implemented a timeout to check if the sender receives an acknowledgment that it received all the data from the receiver in a certain amount of time. In you are familiar with the Atmel Software Foundation (ASF), you will realize that ASF provides a lot of examples for working with their AVR and SAM 32-bit ARM® Cortex®-M0+ processors. However, implement these example projects in another project can be daunting and time consuming. This tutorial takes the leg work out of implementing a Stop Watch timer controller and adding it any SAMD21 project. Atmel’s AVR2130: Lightweight Mesh Developer Guide provides a detail of the LWMesh library. For reference, section 5.11.2 Software timers, which cover the code we will be implementing in our project. Tutorial Series Information Tutorial Name Series Board Category Tutorial in Series Difficulty Stop Watch Timer Controller SAMD21 SAMD21 xplained Pro Timers - Easy Requirements Atmel Studio 7 (AS7) SAMD21 xplained Pro Micro USB 2.0 Cable, Micro-B Male, References Atmel’s AVR2130: Lightweight Mesh Developer Guide
Transcript
Page 1: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 1 | P a g e

Stop Watch Timer Controller Tutorial

Overview In this tutorial I will show you how to implement a Stop Watch Timer Controller. This tutorial is based off the Atmel’s LWMesh Peer2Peer Application for the

SAMR21 xplained pro. While working on the example project, there was a System Software Timer routine that I wanted to implemented on other projects.

This code works like a stop watch. You can start and stop the timer as needed. This can be very useful measuring timeouts. I recently worked on a LWMesh

project with 2 SAMR21 Xplained Pro boards. The SAMR21 is a Radio Tranceiver. The project consisted of sending large amounts of data from one board to the

next via RF. I implemented a timeout to check if the sender receives an acknowledgment that it received all the data from the receiver in a certain amount of

time.

In you are familiar with the Atmel Software Foundation (ASF), you will realize that ASF provides a lot of examples for working with their AVR and SAM 32-bit

ARM® Cortex®-M0+ processors. However, implement these example projects in another project can be daunting and time consuming. This tutorial takes the leg

work out of implementing a Stop Watch timer controller and adding it any SAMD21 project.

Atmel’s AVR2130: Lightweight Mesh Developer Guide provides a detail of the LWMesh library. For reference, section 5.11.2 Software timers, which cover the

code we will be implementing in our project.

Tutorial Series Information Tutorial Name Series Board Category Tutorial in Series Difficulty

Stop Watch Timer Controller SAMD21 SAMD21 xplained Pro Timers - Easy

Requirements Atmel Studio 7 (AS7)

SAMD21 xplained Pro

Micro USB 2.0 Cable, Micro-B Male,

References

Atmel’s AVR2130: Lightweight Mesh Developer Guide

Page 2: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 2 | P a g e

Contact You can reach me at [email protected] if you have any questions of comments.

Hardware Prerequisites Atmel® | SMART SAM D21 Xplained Pro Evaluation kit

Micro-USB standard device cable

Software Prerequisites Atmel Studio 7

Atmel Software Framework (ASF) (3.19.0)

Tutorial Time Estimated completion time: 30min.

Download Files I have uploaded all the files you will need for this tutorial. You can download the files from GitHub here:

https://github.com/PhillyNJ/SamD21SystemTImerExample

Unzip to a folder of your choice. You will need these files for the tutorial.

Page 3: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 3 | P a g e

Create the Project Click File>New>Project

Choose “GCC C ASF Board Project, Enter a name for your project, click OK

Page 4: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 4 | P a g e

Page 5: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 5 | P a g e

Select the SAMD21 Device ATSAMD21J18A & SAM D21 Xplained Pro - ATSAMD21J18A board and click Ok

Open the ASF Wizard

Choose your Project:

Page 6: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 6 | P a g e

Add the TC – Timer Counter Control (driver) Callback module:

Choose the TC – Timer Counter Control (driver) Callback and click Add>>

Click Apply

A summary page will appear. Click OK

Page 7: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 7 | P a g e

Page 8: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 8 | P a g e

Add the Project Files Create the following folder structure in your project:

We are going to add the files I provided from my Git Hub library. We’ll need to add the compiled libsam0_lib_hw_timer.a library to our project

Click on the lib folder, and select Add> Existing Item

Page 9: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 9 | P a g e

Navigate to where you unzip the project files.

Navigate to the sam0/lib and select the libsam0_lib_hw_timer.a file and click Add

Page 10: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 10 | P a g e

Next, Right Click on sam0>Add>Existing Item in the project solution

And add the rest of the files:

Page 11: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 11 | P a g e

Your Project should look like this:

Page 12: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 12 | P a g e

Now, we need to tell the compiler where these files are located.

Right click on the Project and click Properties

Page 13: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 13 | P a g e

Under Tool Chain>ARM/GNU C Compiler, add the 2 directories

Under ARM/GNU Linker, click Libraries and add the compiled library and Path as shown

Page 14: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 14 | P a g e

Add the Code Open up the main.c and add the following code

#include <asf.h> #include "sysTimer.h" static SYS_Timer_t myTimer; void appTimerTestHandler(SYS_Timer_t *timer); void initMyTimer(void); void startMyTimer(void); void stopMyTimer(void); int main (void) { system_init(); SYS_TimerInit(); initMyTimer(); startMyTimer(); while (1) { SYS_TimerTaskHandler(); } }

Page 15: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 15 | P a g e

void appTimerTestHandler(SYS_Timer_t *timer) { port_pin_toggle_output_level(LED_0_PIN); (void)timer; } void initMyTimer(void) { myTimer.interval = 1000; // milli seconds myTimer.mode = SYS_TIMER_PERIODIC_MODE; myTimer.handler = appTimerTestHandler; } void startMyTimer(void){ SYS_TimerStart(&myTimer); } void stopMyTimer(void){ SYS_TimerStop(&myTimer); }

A copy of this code can be found in project files downloaded from github.

Compile and Upload Press F7 to compile the project

Click the Device Programming Icon

Select your Tool, then click Apply

Page 16: Stop Watch Timer Controller Tutorial - AVR Freaks€¦ · You can reach me at acmbug@gmail.com if you have any questions of comments. Hardware Prerequisites ... (driver) Callback

Stop Watch Timer Controller Tutorial Philip Vallone 16 | P a g e

Click Memories, then Program

The LED on the Samd21 should blink every 1 second. You can change the interval by modifying the following line:

myTimer.interval = 1000;


Recommended