PWM Introduction

PWM Introduction

PWM means pulse Width Modulation. I know you are not here for full form of this and I don’t intend to do the same. But I want to explain PWM rather than giving the definition of it. So, in this article, we are introducing you about PWM and it’s various modes and in the coming article, we are going to use this.

So for example, you have to glow an LED connected to the controller. It’s simple right? You just have to connect an LED with the controller and that’s about it. If you don’t know about LED blinking, read this article first(which should be quite unlikely). Anyway, we know that the brightness of the LED will be maximum at 5v and minimum or zero at 0v. But what if I need the half of the brightness?

This is where PWM comes to play. Actually, the controller is a digital device, so it can only give an output of 0v or 5v. So we have to “simulate the voltages” that we required. Now the only thing is-How do we do that?

We do that by generating a square wave of 50% duty cycle. This technique is PWM. For those of you don’t know about duty cycle, a duty cycle is the ratio of “ON” time to the “Total time” of the periodic wave. So in this case, the average value at the output would be 2.5 volts. I got this by multiplying the duty cycle with the amplitude of the square wave (5v).

We can do that using timers. The Atmega 16 has three timers with PWM modes that we can use. For more information about timers- visit here.

PWM Generation

So, we have to generate PWM, we can generate it by using timers. If you don’t know about timers, I highly recommend having a basic idea of it. You can read this article here.

By going into PWM mode, we are actually linking I/O operation with the timer. A very basic mode of it is the output signal starts with 0v and when the timer hits the certain value(timer in ctc mode), the signal rise to 5v. The mode I just mentioned is the non-inverted mode. There are three modes of PWM generation-

  1. Non-inverted mode- The mode just mentioned above.
  2. Inverted mode- Here, the signal starts from 5v and when the timer reaches the certain value, the signal falls down to 0v.
  3. Toggle Mode- Here, the signal toggles from it’s previous value whenever the timer hits the certain predefined value.

But, sometimes there are conditions where this value of timer that we are comparing is necessarily not fixed. Then the output signal would be of different width every time according to the value and mode.

Well, I think that’s it for this article for now, but there is more to it. In the subsequent article, I am going to write about timers and PWM mode and then we will do some illustration projects. Until then, keep learning.

Leave a Comment

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

Share This
Scroll to Top