Arduino 101 Curie Timer One PWM

With this tutorial you learn to use one of the timers available in the microcontroller to generate a PWM signal.

With this tutorial you learn to use one of the timers available in the microcontroller to generate a PWM signal. The Pin selected for the signal is Pin 13 and this will blink the on-board LED. The period of the signal is 1 second (1000000 microseconds) and the duty cycle is set at 25%. The waveform generation, once started, just goes on. In the loop() you can put your code and that won't interfere with PWM signal unless you use timer functions.

Hardware Required

The Circuit

genuino101fzz

image developed using Fritzing. No additional hardware is needed to use this tutorial.

Software Essentials

Libraries

CurieTimerOne.h is the library that provides access to the Timer 1 of the microcontroller. This library allows to set up the number of microseconds that the timer counts before it asserts an interrupt. The interrupt can be configured to call a specific function - the callback function - and each interrupt increments a counter. The same library is used to generate a PWM signal with duty cycle and period length fully customizable.

Functions

None

Code

1#include "CurieTimerOne.h"
2
3void setup() {
4
5 // Setup a PWM signal on pin 13, onboard LED, with a 25% duty cycle
6
7 // of a 1 second period (1000000 usec), as follow (please note the
8
9 // decimal point to indicate double):
10
11 CurieTimerOne.pwmStart(13, 25.0, 1000000);
12
13 // Or, use discrete number range, 0-1023, to define the duty period,
14
15 // 255 is 24.9%, as follow:
16
17 // CurieTimerOne.pwmStart(13, 255, 1000000);
18}
19
20void loop() {
21
22 // put your main code here, to run repeatedly:
23
24 delay( 10000 );
25}

Last revision 2016/03/13 by SM

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.