The microcontroller is a stand-alone C.P.U that has all the peripherals attached to it. You might be wondering, what is the difference between a microcontroller and a microprocessor? A microprocessor is a standalone C.P.U, without a peripheral attached to it. What are peripherals? This are the input and output devices attached to the computer or C.P.U as the case may be. This is synonymous to your personal computer. It is at the point of setting it up, that the output and the input devices are been attached to it. But for the microcontrollers, the output and the input devices has been built into it, at the point of manufacturing. All you have to do is to configure the port, either as an input or as an output port, through the written C program. Writing the C program is simple.so many, are scared when they hear about programming, do not be scared, I will explain all.
Before I explain how to configure the PWM of the microcontroller, let me dive a bit, into how to create the sine table, that makes up the sinusoidal
Pulse width modulation SPWM, which I think is more important knowing first.
The SPWM is a digital way of generating a sinusoidal waveform. It is the number of samples, in sine wave table that determines how pure or how smooth the sinusoidal waveform would be. The sine wave table contains the digital representations of the sine wave, in the form of duty cycle.
In the sine array or wave table, there are different number of samples, that corresponds to the digital representation of the sine wave. The more the samples or values, the purer and cleaner the sine wave.
In Electronics, the formula for showing the relationship between the X and Y axis of the sine graph, is given as; Y = sin (X).
Where Y, represents the Amplitude, which varies between 1 and -1 and X represents the Degree, which varies between 0˚ and 360˚.
What is the essence of the formula mentioned above? It is with this formula, the values in the sine wave table is been created.
In the sine wave graph, there are two identical halves, but pointing in different directions. One in the positive direction and the other in the negative direction. Since the two halves are identical, we would only focus on a single half and then implement the same for the other half, but with the direction reversed. Meaning the same SPWM used for one half, will be used for the second half, but with the direction reversed.
Let me now explain how to generate SPWM.
EXAMPLE 1.
If in your design, you wish to have 32 samples of SPWM in a single half of the sine wave i.e. divide the single half or positive half into 32 samples, then in a full cycle of the sine wave, you will be having 64 samples, because two halves, makes a full cycle.
Remember this formula; Y = sin (X). We will be using it now.
A full cycle corresponds to 360˚, a half cycle will correspond to 180˚. Remember we are dealing with a half cycle.
Since we are using 32 samples for a half cycle. How do we divide 32 values between 180˚? Simple. All you have to do is divide 180˚ by 32.
180˚/32 = 5.63˚
What does this means? This means that, the table will be incremented at the interval of 5.625˚.
Below shows how the table is been incremented.
Y = sin (X).
Sin (0) = 0.
Sin (5.625) = 0.098
Sin (11.25) = 0.195
Sin (16.875) = 0.290
Sin (22.5) = 0.383
Sin (28.125) = 0.471
Sin (33.75) = 0.556
Sin (39.375) = 0.634
Sin (45) = 0.707
Sin (50.645) = 0.773
Sin (56.25) = 0.831
Sin (61.875) = 0.882
Sin (67.5) = 0.924
Sin (73.125) = 0.957
Sin (78.75) = 0.981
Sin (84.375) = 0.995
Sin (90) = 1.
Sin (95.625) = 0.995
Sin (101.25) = 0.981
Sin (106.875) = 0.957
Sin (112.5) = 0.924
Sin (118.125) = 0.882
Sin (123.75) = 0.831
Sin (129.375) = 0.773
Sin (135) = 0.707
Sin (140.625) = 0.634
Sin (146.25) = 0.556
Sin (151.875) = 0.471
Sin (157.5) = 0.383
Sin (163.125) = 0.290
Sin (168.75) = 0.195
Sin (174.375) = 0.098
Sin (180) = 0. ; There is no need to add Sin (180) = 0, as this value will be executed by sin(0) in the next half cycle.
We then need to convert the above values into duty cycles. What is duty cycle? The term duty cycle describes the proportion of 'on' time to the regular interval or 'period' of time. It is expressed in percentage. To convert the above into duty cycles, we will have to multiply each value by 100%.
Sin (0) = 0%
Sin (5.625) = 9.8%
Sin (11.25) = 19.5%
Sin (16.875) = 29.0%
Sin (22.5) = 38.3%
Sin (28.125) = 47.1%
Sin (33.75) = 55.6%
Sin (39.375) = 63.4%
Sin (45) = 70.7%
Sin (50.645) = 77.3%
Sin (56.25) = 83.1%
Sin (61.875) = 88.2%
Sin (67.5) = 92.4%
Sin (73.125) = 95.7%
Sin (78.75) = 98.1%
Sin (84.375) = 99.5%
Sin (90) = 100%
Sin (95.625) = 99.5%
Sin (101.25) = 98.1%
Sin (106.875) = 95.7%
Sin (112.5) = 92.4%
Sin (118.125) = 88.2%
Sin (123.75) = 83.1%
Sin (129.375) = 77.3%
Sin (135) = 70.7%
Sin (140.625) = .63.4%
Sin (146.25) = 556%
Sin (151.875) = .47.1%
Sin (157.5) = 38.3%
Sin (163.125) = 29.0%
Sin (168.75) = 19.5%
Sin (174.375) = 9.8%
After getting the corresponding duty cycle, we then have to convert it into values that can be inputted into the microcontroller.
In the next tutorial, I will be explaining how to configure the PWM of the PIC16f877A.
Please, study this tutorial well. Watch out for Tutorial 3. It will be available on Tuesday, 17th of May.
Thanks for reading. Please share and tell your friends about it.
Your comments, questions and suggestions are all highly welcomed. Thank you.
You can forward your questions to my email, trinnexelectronics@gmail.com or send it as a comment on the blog.
Comments