Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Timers with NRF24LE1 (Part 7/14)

By Amanpreet Singh May 7, 2023

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 // standard library
#include // library containing string functions
#include // 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: Tutorials

 

Next Article

← Previous Article
Next Article →

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.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

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!


RSS EDABOARD.com Discussions

  • Half-bridge LLC resonant converter using UCC25600
  • RFsoc4x2 fpga diagram request
  • BOM sent to Contract assemblers doesnt correspond to schem
  • Lightbox circuit help
  • Transistor circuit in audio

RSS Electro-Tech-Online.com Discussions

  • Kawai KDP 80 Electronic Piano Dead
  • An Update On Tarrifs
  • Trying to use a L9110s motor driver chip
  • I want to make a CRT with some modifications But i have no Idea where to start
  • Funny Images Thread!

Featured – Designing of Audio Amplifiers part 9 series

  • Basics of Audio Amplifier – 1/9
  • Designing 250 Milli Watt Audio Power Amplifier – 2/9
  • Designing 1 Watt Audio Power Amplifier – 3/9
  • Designing a Bass Boost Amplifier – 4/9
  • Designing a 6 Watt Car Audio Amplifier – 5/9
  • Design a low power amplifier for headphones- 6/9

Recent Articles

  • Fischer connector system adds ratchet locking system designed for 300g shock resistance
  • Littelfuse introduces tactile switch with enhanced bracket peg design for mounting strength
  • Infineon releases GaN switch with monolithic bidirectional design
  • Sienna Semiconductor data converters feature sample rates from 20 to 250 Msps
  • Delta’s 5,500 W power supplies achieve 97.5% energy efficiency for AI servers

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 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

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey 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
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe