PWM with NRF24LE1
Have you ever thought that the phone light, when turned ON, is not always ON? It fluctuates with a frequency to save some energy which our eyes can’t sense. It’s a cool thing to save some battery but how is this done? The answer is PWM.
PWM is an important technique for producing analog voltages using digital voltages and controlling LEDs, DC, servo motor, etc.
In this article, we will discuss about generating PWM signal using NRF module.
There are two ways to generate PWM signals with NRF2LE1:
1. Use delay to generate pulses of desired width.
2. Use inbuilt PWM hardware pins.

Fig. 1: Prototype of NRF24LE1 Module based PWM Generator
We will cover both methods one by one.
First method:
This method is focused on using delay to control pulse width. Let’s understand it in simple steps.
1) First the output pin is made HIGH.
2) Then delay is given to hold output HIGH for specified time. This is done in order to generate a HIGH pulse.
3) The output pin is made LOW.
4) The delay is provided to hold output LOW.
5) Steps 1 to 4 are repeated.
The time period of the generated wave will be the sum of delay for HIGH pulse and delay for LOW pulse. Reciprocal of time will give us frequency of the produced signal. We can change the duty cycle by changing delay time of ON and OFF pulse. The delay can be created using inbuilt timers or we can use already defined delay functions. The delay functions are provided by inbuilt libraries.
Second Method:
In this method we will use inbuilt PWM functionality of NRF24LE1 to produce signals. This method is more convenient than the other as it removes reliability on delay functions. One restriction of this method is that the output of PWM signal can only be taken at PWM enabled pins.
Some features of inbuilt PWM are:
• Two channel output. PWM0 and PWM1
• Frequency range from 2 KHz to 254 KHz when MCU is provided 16MHz clock.
In NRF24LE1 there are two pins dedicated for PWM, PWM0 and PWM1. PWM0 is pin 3 of port 0 and PWM1 is pin4 of port 0.
The PWM is controlled through three registers:

Fig. 2: Table Listing Registers of NRF24LE1 used for PWM Generation
An image has been attached to understand the PWM frequency and duty cycle setting.
Simple steps to create PWM signals are:
1. Select period length by writing bit7:6 of PWMCON.
2. Choose prescaler for PWM frequency using bit5:2 of PWMCON.
3. Enable PWM0 or PWM1 using bit1 and bit0 of PWMCON.
4. Select Duty Cycle using PWMDC1 and PWMDC0.
A code has been written to understand the process of creating PWM.
Project Source Code
###
//Program to
#include"reg24le1.h" // I/O header file for NRF24LE1#include"hal_delay.h" // header file containing delay functions// main functionvoid main(){int i = 0, j = 0; // loop variableP0DIR = 0; // Port 0 as outputPWMCON = 0xfe; // enable PWM1// infinte loopwhile(1){for(i= 0xff; i--; i > 0x00){PWMDC1 = i ; // change duty cycledelay_ms(10); // delay of 10 ms}}}###
Circuit Diagrams
Project Video
Filed Under: Tutorials
Filed Under: Tutorials
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.