Timer in ARM MBED LPC1768

Introduction

Timers in microcontrollers are used for introducing delay, counting events, generating waveforms and also for PWM generation.

In ARM MBED 32-bit timer are used to set time, read time, count time, etc. (between microseconds and seconds).

You can independently create, start and stop any number of Timer objects.

 

Note: Timers are based on 32-bit int microsecond counters, so they can only time up to a maximum of 2^31-1 microseconds (30 minutes). They are designed for times between microseconds and seconds. For longer times, you should consider the time() real time clock.

 

Timer

Create object of Timer

e.g.

Timer timer

 

Start()

To start the timer

e.g.

timer.start()

 

Stop()

To stop the timer

e.g.

timer.stop()

 

Reset()

To reset the timer

e.g.

timer.reset()

 

Read()

Read the passed time

e.g.

timer.read()

 

Read_ms()

Read the passed time in milisecond

e.g.

timer.read_ms()

 

Read_us()

Read the passed time in microsecond

e.g.

timer.read_us()

 

Program

// Count the time to toggle a LED
#include "mbed.h"
Timer timer;
DigitalOut led(LED1);
int begin, end;
int main() {
timer.start();
begin = timer.read_us();
led = !led;
end = timer.read_us();
printf("Toggle the led takes %d us", end - begin);
}

Components Used

ARM mbed 1768 LPC1768 Board
ARM mbed 1768 Board
1
Ad