0% found this document useful (0 votes)
211 views

How To Change Frequency On PWM Pins of Arduino UNO

This document discusses how to change the frequency on the PWM pins of the Arduino Uno. The default PWM frequencies for different pins are: 490.2Hz for pins D3 and D11, 976.56Hz for pins D5 and D6, and 490.2Hz for pins D9 and D10. These default frequencies can be changed to values between 30Hz and 65KHz using a single line of code that modifies the TCCR2B or TCCR0B registers. Examples of code are provided to set frequencies such as 31372.55Hz, 3921.16Hz, and 62500Hz on different pins.

Uploaded by

CPtaller MTTO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
211 views

How To Change Frequency On PWM Pins of Arduino UNO

This document discusses how to change the frequency on the PWM pins of the Arduino Uno. The default PWM frequencies for different pins are: 490.2Hz for pins D3 and D11, 976.56Hz for pins D5 and D6, and 490.2Hz for pins D9 and D10. These default frequencies can be changed to values between 30Hz and 65KHz using a single line of code that modifies the TCCR2B or TCCR0B registers. Examples of code are provided to set frequencies such as 31372.55Hz, 3921.16Hz, and 62500Hz on different pins.

Uploaded by

CPtaller MTTO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

eTechnophiles

HOME ARDUINO IC’s and COMPONENTS PROTEUS/MATLAB ARTICLES PROJECT VIDEOS

Contact Us

Connect with us

Search … 

December 26, 2017 ⁄ Ankit Negi

How To Change Frequency On PWM Pins Of


Arduino UNO
Arduino Uno is one of the most commonly used Development boards these days.
It can be used for almost any application that one can think of. One such
application is in high-frequency circuits. But to use a controller in a high-
frequency circuit like in a buck converter, the controller must be able to generate
high-frequency PWM wave. And if the controller you are using is Arduino Uno,
then you must know how to change frequency on PWM pins of Arduino Uno.

Now there are many facts about Arduino with which many students are not
familiar. And one of the facts is this: “There is a certain default frequency for each
PWM pin, which is called when the analogWrite command is used on that pin.
And this default frequency can be changed to a value as high as 65Khz and as low
as 30Hz by using just one line code”.

Looking for Arduino Mega PWM


frequency change?

How To Change Frequency On PWM


Pins Of Arduino Mega

You can also watch this video for quick reference:

  Categories

ARDUINO (45)
Here is the default frequency of each PWM pin of Arduino UNO:
ARTICLES (44)
DC Generator (1)
PWM frequency for D3 & D11:
DC Motor (1)
Electrical Concepts (2)
490.20 Hz (The DEFAULT) Electronics (25)
IC 555 Timer based projects
 
(3)
IC's and COMPONENTS (17)
PWM frequency for D5 & D6: Logic Gates (4)
Matlab (10)
976.56 Hz (The DEFAULT) Product Review (8)
Project Videos (1)
  PROJECTS (33)
Proteus (3)
PWM frequency for D9 & D10: PROTEUS/MATLAB (11)
Raspberry Pi (3)
490.20 Hz (The DEFAULT) TOP 10 Projects (20)

Now, these frequencies are optimum for low-frequency applications like fading an Recent Posts
LED. But these default frequencies are not suitable for High-frequency circuits.
Raspberry Pi 3 B+ Pinout
For example, 1Khz is nothing when it comes to an S.M.P.S.
with GPIO functions, Schematic
and Specs in detail
There are many projects in which we require high-frequency pulses, One such
Design better and faster
project is a Buck-Converter. So to achieve frequency lower or higher than the
parts with Rapid Prototyping
default frequency on PWM pins, a one-line code you can use to change frequency
introduced by PCBWay
on PWM pins of Arduino Uno is given below: Raspberry Pi 3 GPIO Pinout,
Pin diagram and Specs in
 
detail (Model B)
Top 3 DC Motor Speed
FOR ARDUINO UNO: Controller Circuit Using
Custom made PCBs
Code for Available PWM frequency for D3 & D11: Raspberry Pi Zero GPIO
Pinout, Specifications and
TCCR2B = TCCR2B & B11111000 | B00000001; // for Programming language
PWM frequency of 31372.55 Hz Arduino Leonardo Pinout,
Schematic and Specifications
TCCR2B = TCCR2B & B11111000 | B00000010; // for in detail

PWM frequency of 3921.16 Hz What is Aluminum PCB? It’s


Structure, Specifications and
Applications
Arduino Mega Pinout, Pin
diagram, Schematic and
specifications in detail
Top 3 innovative PCB
projects of November 20 from
PCBWay
ESP8266 based Automatic
Cooling Fan project with touch
LCD control

TCCR2B = TCCR2B & B11111000 | B00000011; // for


PWM frequency of 980.39 Hz

TCCR2B = TCCR2B & B11111000 | B00000100; // for


PWM frequency of 490.20 Hz (The DEFAULT)

TCCR2B = TCCR2B & B11111000 | B00000101; // for


PWM frequency of 245.10 Hz

TCCR2B = TCCR2B & B11111000 | B00000110; // for


PWM frequency of 122.55 Hz

TCCR2B = TCCR2B & B11111000 | B00000111; // for


PWM frequency of 30.64 Hz

Code for Available PWM frequency for D5 & D6:

TCCR0B = TCCR0B & B11111000 | B00000001; // for


PWM frequency of 62500.00 Hz

TCCR0B = TCCR0B & B11111000 | B00000010; // for


PWM frequency of 7812.50 Hz

TCCR0B = TCCR0B & B11111000 | B00000011; // for


PWM frequency of 976.56 Hz (The DEFAULT)

TCCR0B = TCCR0B & B11111000 | B00000100; // for


PWM frequency of 244.14 Hz

TCCR0B = TCCR0B & B11111000 | B00000101; // for


PWM frequency of 61.04 Hz

Code for Available PWM frequency for D9 & D10:

TCCR1B = TCCR1B & B11111000 | B00000001; // set


timer 1 divisor to 1 for PWM frequency of 31372.55 Hz

TCCR1B = TCCR1B & B11111000 | B00000010; // for


PWM frequency of 3921.16 Hz

TCCR1B = TCCR1B & B11111000 | B00000011; // for


PWM frequency of 490.20 Hz (The DEFAULT)

TCCR1B = TCCR1B & B11111000 | B00000100; // for


PWM frequency of 122.55 Hz

TCCR1B = TCCR1B & B11111000 | B00000101; // for


PWM frequency of 30.64 Hz

EXAMPLE:

To show you how the frequency changes on applying the above code, the Arduino
circuit is simulated in Proteus:

Check out: How to add Arduino Library to Proteus and Simulate Arduino


Projects

1. Two Arduino are selected and placed on Front-Panel

2. Digital Pin 3 ( PWM pin) of each Arduino is connected to the oscilloscope

3. Two separate programs are written for each Arduino:

Program A – Default frequency on Pin 3

void setup() {

pinMode(3,OUTPUT);
// put your setup code here, to run once:

void loop() {
analogWrite(3,155);
// put your main code here, to run
repeatedly:

Program B – Changed frequency on Pin 3

void setup() {

TCCR2B = TCCR2B & B11111000 |


B00000001; // for PWM frequency of
31372.55 Hz
pinMode(3,OUTPUT);
// put your setup code here, to run once:

void loop() {
analogWrite(3,155);
// put your main code here, to run
repeatedly:

4. Hex file of above programs are given to Arduino

5. Run Simulation

6. It can be clearly seen in oscilloscope that frequency is increased to a very high


value when this piece of code is used :
TCCR2B = TCCR2B & B11111000 | B00000001; // for PWM frequency of
31372.55 Hz

Read Similar Articles:

| How to add Arduino Library to Proteus and Simulate Arduino Projects

| Add Microphone library to Proteus and generate audio waveforms

| How to Add And Simulate Ultrasonic Sensor Library in Proteus


Share this:

 

Like this:

Loading...

Related

How To Change PWM Arduino Programming for Arduino UNO Pinout, Pin
Frequency Of Arduino Mega absolute Beginners in 2020: diagram, Specifications and
January 25, 2020 The Ultimate Guide Features in Detail
In "ARDUINO" July 14, 2018 November 20, 2020
In "ARDUINO" In "ARDUINO"

Shop Related Products

ELEGOO UNO R3 Board ARDUINO UNO R3 UNIROI Ultimate Starter ELEGOO UNO Project
ATmega328… [A000066] Kit Compatible with… Super Starter Kit wi…

$13.98 $23.00 $29.95 $29.99 $36.99


(3243) (3560) (739) (5625)

Arduino UNO SMD Rev3 HiLetgo ESP32 OLED LAFVIN R3 Board NVIDIA 945-82771-0000-
[A000073] WiFi Kit ESP-32 0.96… ATmega328P A… 000 Jetson …

$20.89 $29.95 $18.49 $11.99 $397.80


(120) (167) (47) (41)

Ads by Amazon

ARDUINO ARTICLES

« How to Add And Simulate Ultrasonic Sensor Library in Proteus ?


Top 10 Arduino Projects For Beginners in 2018 (Honest Opinion) »

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Notify me of follow-up comments by email.

Notify me of new posts by email.

Post Comment

WordPress Theme: Wellington by ThemeZee.

You might also like