Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

Timers with NRF24LE1 (Part 7/14)

By Amanpreet Singh

Image of NRF24LE Module based TimerTiming plays an important part in our life. It’s normal for a human to allocate time for future plans. We only need brain and a clock to decide what is the current time and how much time has passed. Similarly, a microcontroller can also calculate time. It serves the purpose of brain as in case of human and the clock is provided by oscillator. For us, wastage of a second may not be important but for microcontroller a microsecond is very crucial.


Timers with NRF24LE1

Timing plays an important part in our life. It’s normal for a human to allocate time for future plans. We only need brain and a clock to decide what is the current time and how much time has passed. Similarly, a microcontroller can also calculate time. It serves the purpose of brain as in case of human and the clock is provided by oscillator. For us, wastage of a second may not be important but for microcontroller a microsecond is very crucial.
 
 
In this article you will find answer to questions like – How we can use NRF to keep a track of elapsed time, how we can generate delay of specified period and much more.
 
Most microcontrollers have inbuilt functionality know as Timers. These Timers are used to keep a track of time. Also they can be used as counter to count pulses. The NRF24LE1 has three timers Timer0, Timer1 and Timer2. We will be discussing only Timer0 in the present article.
 
Prototype of NRF24LE Module based Timer
 
Fig. 1: Prototype of NRF24LE Module based Timer
 
 
The timer uses clock frequency to update time. It uses registers to hold the value of time. For example, if we use a clock of 16 MHz which has a time period of 62.5 nS (nano seconds) then the timer register increments its value by 1 after every 62.5 mS.  It also means that the smallest measurement we can take is 62.5 mS. 
 
Image of NRF24LE Module based Timer
 
Fig. 2: Image of NRF24LE Module based Timer
 
We already discussed that the timer uses registers to store the value of time. In NRF24LE1 we can choose between 8-bit register, 13-bit register and 16-bit register. The selection of register affects the amount of time a timer can store. For example, an 8-bit register can store value up to 255. If we use 16 MHz frequency of time period 62.5 mS then the maximum amount of time that this register can store is (62.5 * 255) =  15.9 uS (micro seconds).
 
Now what if we change the frequency? Let’s try it out.
 
Let’s say my new frequency is 16MHz/8 = 2 MHz which means now the time period is 0.5 uS. Now if we use 8-bit register to hold the value of time then the maximum amount of time that this register can store is (0.5 * 255) =  127.5 uS (micro seconds). What we observe is, if we decrease the frequency, the maximum amount of time that register can store increases. The divider that we use to decrease the frequency is known as prescaler. We can change this prescaler to change the frequency. In NRF module the prescaler is inbuilt and fixed at 12. That means now frequency becomes 16/12 = 1.33 MHz.
 
We have to select the Timer0 to function as a timer or counter. For this we have TMOD (Timer Mode) register. The second bit of this register is used to select between timer and counter. If this bit is 0 then timer is selected and if 1 then counter is selected. We have to write this bit according to our requirement. 
 
For Timer0, we have three modes:
 
1. Mode0 – this mode is used to select 13-bit register
2. Mode1 – This mode is for 16-bit register.
3. Mode2 – it is for 8-bit auto reload.
4. Mode3 – this mode is used to select one 8-bit register as timer/counter and other 8-bit as timer.
 
The first bit and zero bit of TMOD register is used to select between different modes. The various combinations of these bits refer to different modes. They are:
 
00 – Mode0
01 – Mode1
10 – Mode2
11 – Mode3
 
The registers which hold the value of time for timer0 are TL0 and TH0. These two registers are of 8-bit each. They can be combined to be used as 16-bit register or 13-bit register. TH0 holds the higher byte and TL0 holds the lower byte of data. Also if these registers get full, it is known as overflow. We can check if an overflow has occurred by checking the overflow flag in TCON (Timer Control) register. The bit number five represents the overflow flag. If flag is 1 then overflow has occurred. We can write a service routine which gets called when overflow occurs.
 
 
Overflow flags are automatically cleared when the service routine is called.
 
To start the timer we have to set the bit number four of TCON. If this bit is cleared that is 0, the timer will stop. We can also access this bit through TR (Timer Run) variable. If TR = 1, timer starts. If TR = 0, timer stops.
 
There are more features of timer like overflow, hardware control, gate control and pulse counter. We will be discussing these features in our upcoming articles.
 
We have written a code to understand the timers. We are using timer0 in mode1. We have created a delay of …… 
 

Project Source Code

###

//Program to 

#include "reg24le1.h" // I/O header file for NRF24LE1
#include <stdlib.h> // standard library
#include <string.h> // library containing string functions
#include <stdio.h> // standard I/O library
 
sfr16 DPTR = 0X82; // declare functional register DPTR
 
// main function
void main()
{
 
int i = 0;
P1DIR = 0; // Port1 as output
 
P10 = 0; // Pin 0 of Port 1 low
 
EA = 1; // Enable global interrupt
TMOD = 0X01 ; // timer0 in 16bit mode1
TR0 = 1; // start timer
 
// infinite loop
while(1)
{
TH0 = 0; // initialise timer register upper byte
TL0 = 0; // initialise timer register lower byte
while(TF0 == 0); // wait for timer overflow flag
TF0 = 0; // clear flag
P10 =1; // make Pin0 of Port1 high
TH0 = 0; // initialise timer register upper byte
TL0 = 0; // initialise timer register lower byte
while(TF0 == 0); // wait for timer overflow flag
TF0 = 0; // clear flag
P10 = 0; // make Pin0 of Port1 low
}
}

###

 


Circuit Diagrams

Circuit-Diagram-NRF24LE-Module-Timer

Project Video


Filed Under: Electronic Projects

 

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What are the battery-selection criteria for low-power design?
  • Key factors to optimize power consumption in an embedded device
  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver
  • Introduction to Brain Waves & its Types (Part 1/13)

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Fpga wake up
  • Code Optimization
  • Avalanche Pulser
  • Pull up via GPIO
  • Poly Spacing Effect

RSS Electro-Tech-Online.com Discussions

  • Someone please explain how this BMS board is supposed to work?
  • HV Diodes
  • Question about ultrasonic mist maker
  • DIY bluetooth speaker
  • Disabled son needs advice please
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering