Universidad Politecnica de Yucatán

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

UNIVERSIDAD POLITECNICA DE YUCATÁN

Professor: Angel Arturo Pech Che

Introduction to Robotics and Mechatronics Engineering

PWM SIGNAL PRACTICE

Aban Sosa Carlos Andres


Mendiola Peralta Camila Geraldine
Perez Campos Andrea Aylin
Polanco Casares Alberto
Villanueva May Yuridia Angélica

21-01-2022

1
The objective of this practice is to learn how to control the direction

and speed of a DC motor with brushes. We will control both

direction and speed with a potentiometer.


Page |3

Index

Pwm Signal ..................................................................................................................................... 4

Introduction: ................................................................................................................................ 4

Objetive: ...................................................................................................................................... 4

Theoretical Framework: .............................................................................................................. 4

PWM signal .............................................................................................................................. 4

Analog Signal............................................................................................................................ 5

Digital Signal ............................................................................................................................ 6

Atmega 328P PWM Signal Frequency ..................................................................................... 8

Practical development: ................................................................................................................ 9

Materials: .................................................................................................................................. 9

Procedure: ................................................................................................................................. 9

Code: ....................................................................................................................................... 12

Conclusion ................................................................................................................................. 15

Bibliographic References .......................................................................................................... 15

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
Page |4

Pwm Signal

• Introduction:

In this work we work different components to be able to perform the practice successfully, but

before that we define about the concept of the PMW, as well as about the terms of analog and

digital signal, as well as about the frequency of the ATmega328p and more, since all this is

something that helps us to understand the theoretical part and to be able to pass to the practice

correctly in this activity.

• Objetive:

We have to learn how to control the speed and direction with the ponteciometer using the gear

motors and with the oscilloscope to observe the voltage measurement of the requested and be

successful.

• Theoretical Framework:

PWM signal

Pulse-Width Modulation (See figure 1-PWM) is a powerful technique for controlling analog

circuits with a microcontroller's digital outputs.

PWM is used in many applications, ranging from

communications to power control and conversion. For

example, the PWM is commonly used to control the

speed of electric motors, the brightness of lights, in

Figure 1: PWM / Arduino ultrasonic cleaning applications, and many more.

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
Page |5

A PWM is basically a digital unipolar square wave signal where the duration of the ON time

can be adjusted or modulated as desired. This way the power delivered to the load can be

controlled from a microcontroller.

A signal is an electromagnetic or electrical current that is used for carrying data from one

system or network to another. The signal is a function that conveys information about a

phenomenon.

In electronics and telecommunications, it refers to any time-varying voltage that is an

electromagnetic wave which carries information. A signal can also be defined as an observable

change in quality such as quantity. There are two main types of signals: Analog signal and

Digital signal.

Analog Signal

Analogue signals are transmitted using a continuously changing quantity as a reference. Data

transmission consists of sending signals as continuous waves.

Analogue signals are digitised using a device known as an analogue-to-digital (A/D)

converter. This is essentially a computer-controlled voltmeter which accepts an analogue signal

as input and produces a computer-readable binary number as output. The A/D converter (ADC) is

one of the most important components of the data acquisition system, its performance

determining the accuracy and rate at which digitised samples can be acquired.

Analog signals are often calculated responses to changes in light, sound, temperature,

position, pressure, or other physical phenomena. When plotted on a voltage vs. time graph, an

analog signal should produce a smooth and continuous curve. There should not be any discrete

value changes (See Figure 2).

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
Page |6

Figure 2: Analog Signal

Digital Signal

A digital signal is a signal that represents data as a sequence of discrete values. A digital

signal can only take on one value from a finite set of possible values at a given time. With digital

signals, the physical quantity representing the information can be many things:

• Variable electric current or voltage

• Phase or polarization of an electromagnetic field

• Acoustic pressure

• The magnetization of a magnetic storage media

Digital signals are used in all digital electronics, including computing equipment and data

transmission devices. When plotted on a voltage vs. time graph, digital signals are one of two

values, and are usually between 0V and VCC (usually 1.8V, 3.3V, or 5V) (See Figure 3).

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
Page |7

Figure 3: Digital Signal

Knowing the concepts of Analog and Digital signal, we can now mention some of their

different ones for better understanding:

ANALOG SIGNAL DIGITAL SIGNALS

Is difficult to analyze at first. Is easy to analyse.

Is more accurate than digital signals. Is less accurate.

Take time to be stored. It has infinite memory. Can be easily stored.

To record an analog signal, the technique used, In recording digital signal, the sample signals are

preserves the original signals. taken and preserved.

There is a continuous representation of signals in There is a discontinuous representation of signals

analog signals. in digital signals.

produce too much noise. do not produce noise.

Examples of analog signals are Human voice, Examples of digital signals are Computers,

Thermometer, Analog phones etc. Digital Phones, Digital pens, etc.

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
Page |8

Atmega 328P PWM Signal Frequency

Recall that the ATmega328p is the most popular on the Arduino UNO. However, the

ATmega328p's 28 PDIP package can easily be used without any boards. Simply place it on a

breadboard, and connect a TTL adapter and an ISP and you're ready to go.

And typically, a servo motor anticipates an update every 20 ms with a pulse between 1 ms and

2 ms. This equates to a duty cycle of 5% to 10% at 50 Hz. Now, if the pulse is at 1.5 ms, the

servo motor will be at 90-degrees, at 1 ms, 0-degrees, and at 2 ms, 180 degrees.

But, Frequency as it relates to

PWM is the number of times per

second that we repeat the on and off

cycle (see figure 4). If we pulse the

solenoid on and off at a given duty

cycle 30 times a second, we have a

frequency of 30 Hz.
Figure 4: PWM and Duty Cycle Diagram

Atmega 328P Frequency is: 1MHz/8MHz (Up to 20MHz with external clock)

Here we explain a little more about this, the ATmega328p has two internal oscillators clocked at

8MHz and 128kHz which allows it to run without any external clock source or crystal. By

default, the fuses are configured to use the internal 8MHz oscillator and a clock divider resulting

in a clock rate of 1MHz.

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
Page |9

• Practical development:

Materials:

 1pz H-bridge

 1pz Atmega 328P

 2pzs Geared motor

 1pz Potentiometer

 1pz Protoboard

 Dupont cables

 12 v DC power supply O battery

Procedure:

For the first step was to make the code so that when activating the PWM signal the motors

were activated and began to rotate faster as the signal was stronger.

After that was to connect the inputs that we had defined in our code, as well as the EnA and

EnB since in our case we use 2 motors, as important information the ports EnA and EnB must be

connected to the PWM signal that is represented with a ~. We connect both motors to the

corresponding Outputs.

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
P a g e | 10

Then we go to the breadboard where we connect the potentiometer, which will be responsible

for increasing or decreasing the power of the PWM signal.

To finish with the assembly, we connect to the Arduino the pins that we had already chosen in

our code, as well as the analog signal of the potentiometer and its pins.

Once the assembly is finished, we will give power which in this case will be with an

equipment of the laboratory which we must always check that it marks 0 in both Amperage and

Voltage. Once this is checked we place in amperage 2 and in voltage 9 since when using 2 motors

more voltage is needed.

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
P a g e | 11

We connect the alligators corresponding to the negative and the positive to the 12V and to the

GND of the H bridge.

While it is in operation, we connect the oscilloscope to the pin of the PWM signal in this case

the "5", to be able to observe the frequency and as it is seen through this device.

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
P a g e | 12

Code:

/*Speed control (PWM) of a motor with a potentiometer*/

/*Variables*/

int pot=0; //Analogical Pin to potentiometer

int val; // Variable to read the value of the potentiometer

const int EnA=5; // PH conector to speed up the engine

const int in1=4;

const int in2=3;

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
P a g e | 13

const int EnB=9; // PH conector to speed up the engine

const int in3=8;

const int in4=10;

void setup() {

pinMode (in1,OUTPUT);

pinMode (in2,OUTPUT);

pinMode (in3, OUTPUT);

pinMode (in4,OUTPUT);

void loop() {

val= analogRead(pot);// Value of the potentiometer (It could be a value between 0 and 1023)

val= map(val,0,1023,0,255); // Scale to use in the PWM

//Left

if(val,128){

int vel= map(val,0,127,255,0);

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
P a g e | 14

digitalWrite(in2,LOW);

digitalWrite(in1,HIGH);

digitalWrite(EnA,vel);

digitalWrite(in4,LOW);

digitalWrite(in3,HIGH);

analogWrite(EnB, vel);

//Stop

else{

digitalWrite(EnA,LOW);

digitalWrite(EnB,LOW);

delay(15);

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
P a g e | 15

Conclusion

In this practice we learned about the PWM signal as it is, what it is for, how it works, as well

as the digital and analog signal. We put together a small robot prototype, which when activating

the potentiometer must increase the PWM signal so that the motors start to rotate or move

forward. The PWM signal is found on the pins that have this symbol on their ~ side, with this we

already know that the signal we are looking for exists. And all the above mentioned can be very

useful, since they are concepts that come together and can be used later both as a review, as for

projects or future work.

Bibliographic References

+ Storr, W. (2020, August 5th). Pulse Width Modulation Used for Motor Control. Basic

Electronics Tutorials. https://www.electronics-tutorials.ws/blog/pulse-width-

modulation.html

+ S.A. (S. F.). Pulse Width Modulation - an overview | ScienceDirect Topics. Sciencedirect.

https://www.sciencedirect.com/topics/engineering/pulse-width-modulation

+ Williams, L. (2022, February 2sd). Analog vs Digital: What is the Difference Between Analog

and Digital? Guru99. https://www.guru99.com/analog-vs-digital.html

+ S.A. (S. F.). Activity: Pulse Width Modulation [Analog Devices Wiki]. Wikianalog.

https://wiki.analog.com/university/courses/electronics/electronics-lab-pulse-width-

modulation

+ Arrow Electronics. (2021, February 10th). Analog vs. Digital Signals - What the Difference?

Arrow.Com. https://www.arrow.com/en/research-and-events/articles/analog-vs-digital-

what-is-an-analog-signal

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
P a g e | 16

+ S.A. (S. F.). Difference Between Analog Signals and Digital Signals - Javatpoint.

Www.Javatpoint.Com. https://www.javatpoint.com/difference-between-analog-signals-

and-digital-signals

+ S.A. (S. F.). Analog vs. Digital Signals: Uses, Advantages and Disadvantages | Article | MPS.

Monolithicpower. https://www.monolithicpower.com/en/analog-vs-digital-signal

+ S.A. (S. F.). Analogue Signal - an overview | ScienceDirect Topics. Sciencedirect.

https://www.sciencedirect.com/topics/computer-science/analogue-signal

+ E. (2021, November 20th). ATmega328P Fast PWM mode Programming Examples. Ee-Diary.

https://ee-diary.blogspot.com/2021/07/atmega328p-fast-pwm-mode-

programming.html#:%7E:text=The%20following%20is%20then%20the,75%25%20using

%20Timer%2FCounter0.&text=The%20following%20schematic%20diagram%20shows,(

port%20D%20pin%206).

+ S.A. (S.F.). Standalone ATmega328p. Apiriot. https://api.riot-

os.org/group__boards__atmega328p.html

+ Mariscalchi, A. (2021). Anda Fournel, Thea Ionescu et Jean-Pascal Simon (dir.), Geste, parole

et conceptualisation, revue Studia Universitatis Babeş-Bolyai, Philisophia, vol. 64, no 2.

Lidil, 63. https://doi.org/10.4000/lidil.9113

+ Author, G. (2020, December 3rd). Gears Magazine - Exploring PWM, Frequency and Duty

Cycle. Gears Magazine. https://gearsmagazine.com/magazine/exploring-pwm-frequency-

and-duty-cycle/

+ S.A. (S.F.). Pulse Width Modulation Characteristics and the Effects of Frequency and Duty

Cycle. Resources. https://resources.pcb.cadence.com/blog/2020-pulse-width-modulation-

characteristics-and-the-effects-of-frequency-and-duty-

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.
P a g e | 17

cycle#:~:text=PWM%20Frequency&text=Typically%2C%20a%20servo%20motor%20an

ticipates,at%202%20ms%2C%20180%20degrees.

Pérez Campos Andrea Aylin.


México, Mérida. February 16th, 2022.

You might also like