Atmel AVR131: Using the AVR’s High-speed PWM I want to design a digital signal generator which can generate digital values for the Sine wave using 8051 and then convert. Sine Wave generation using PWM. Home Embedded Sine Wave Generator using PWM with LPC2148 Microcontroller Tutorial. Sine Wave Generator using. In our case will be generating a 50Hz sine wave using. Sine Wave Generator using 8051 datasheet. Program a half sine wave with 12 entries into the memory. Waveform Generator using Microcontroller 89C51. The generation of a sine wave using a. The program converted into HEX file and. Read about 'how to generate 50to 60 hz sine wave. You could start by trying something like this which generates a slow triangle wave: PWM Signal Generation using.
Program For Sine Wave Generation Using 8051 Programmer
Sine Wave Generator using PWM with PIC Microcontroller. The PIC1. 8F4. 55. PWM output channels and they are P1. A, P1. B, P1. C and P1. D. All of them are capable of generating PWM waves at a time. In this project only one of the PWM channels are using. The P1. A is the PWM channel in this particular project.
A simple example of the of waves generated at this pin is shown below; As shown in the above figure the . Duty- cycle is the percentage of time period for which the logic. ON time), starting from the beginning of the cycle. The PWM is that kind of a wave in which the ON time and OFF time can vary in a cycle but the sum of . The second wave has 1. Duty- cycle and the third wave has 9.
Duty- cycle. According to the modulation of the width of a pulse in a period of the wave, the PWM can generate any required voltage with the help of a proper filter circuits. The filter circuits are used for generating the voltage corresponding to a modulated wave. Hence the PWM wave is always associated with a filter circuit. When applied to a proper filter the 5. If the maximum voltage (logic 1 voltage) of the pulse is 5. V then the 5. 0% duty cycle wave can produce a continuous 2.
V. The 1. 0% duty cycle wave can produce nearly 0 voltages and the 9. V. Thus the wave when applied to a filter can continuously produce a voltage which is the average of the voltage in a single period. Increasing the Duty- cycle will increase the voltage at the filter device’s output and decreasing the Duty- cycle will decrease the voltage as well.
The filter could be any device which can generate the equivalent voltage of a PWM wave. It normally consists of Low- pass filters, amplifiers, load drivers etc. They generate the voltage corresponding to the pulse width modulation in the wave and can fed that voltage to the load device. The registersassociated with the PWM modules like CPR1, PR2 and TMR2 etc. Increasing the Duty- cycle will increase the voltage at the filter device’s output and decreasing the Duty- cycle will decrease the voltage as well. In this particular project the sine wave samples are generated periodically by re- writing the value of the CCPR1 register to vary the Duty- cycle.
PWM generation using 8051. This tutorial will take you through the PWM basics and implementation of PWM on 8051 and. Duty cycle of a square wave is.
It is done by generating interrupts periodically with another timer module timer. CCPR1 value when the code is inside the timer.
ISR. It is done as shown in the following figure; The voltage generated by the PWM wave in the interval between two interrupts will be a constant value and this time period can be called . The more the number of PWM cycles in a Sampling time, more stable the output voltage will be. The Duty- cycle of the PWM wave is increased in a sinusoidal way each times the timer.
The consecutive samples that should be generated at each sampling time should follow a sinusoidal pattern. These samples should have the values as if they have been taken by sampling a real sine wave.
An example of the sine wave samples is shown following figure in which 1. These values when applied to a filter circuit can generate the sine wave at its output by smoothing the step size. The output of the filter which is fed with the sine wave samples is shown in the following figure. The brown line shows the actual sine wave constructed by the filter circuit. The values that should be assigned to the CCPR1 register to generate such consecutive samples are actually taken from a look- up table. The look- up table with 5.
Sample no. Value. Sample no. Value. Sample no. Value. Sample no. Value.
Sample no. value. When these values are assigned to the CCPR1 at consecutive sampling periods, it can generate a sine wave at the output of the filter circuits. A zoomed in image of the sine wave that has been generated by the filter used in this project using the above look- up table is given in the following.
The sample step value creating the sine wave can be seen in this image. The steps are not very clear and it should not be since the capacitor in the filter circuit smoothed out the steps to create the sine wave. Time period calculations: Sampling time: In this project the TMR0 is set to zero and the timer.
Now the timer will count from 0x. FF with a clock frequency of FOSC/4 with a pre- scale of 1: 2. The CPU clock frequency is set as 4. MHz and hence the time period of a single clock TOSC can be calculated as TOSC = 1/ FOSC = (1 / (4. The time period of the clock which the timer. FOSC/4) = TOSC * 4 = (0.
The timer. 0 has a pre- scale value of 1: 2 and hence the time period should be again multiplied by 2. Hence the time period at which the value in the 8 bit timer increases = (0. The timer. 0 value increases from 0x.
FF with a time period of 0. Hence the total time taken for the timer to overflow and cause an interrupt can be calculated as.
The Sampling time = 4. PWM period: In this particular project the PR2 is written to a very small value so as to generate small time periods and hence to get more number of PWM cycles per sampling period. PR2 = 2. 2Using the equation for calculating the Period of the PWM wave given as; PWM Period = . The PWM Period = 2us. Thus in a Sampling time number of PWM cycles can be calculated as 4.
PWM cycles. Number of PWM cycles per Sample = 2. Thus the timer. 0 will generate an interrupt after every 2. PWM cycles. This much number of PWM cycles per sample is good enough to generate a stable output sample voltage from a filter device.
For the first 2. 0 PWM cycles the value assigned to the CCPR1 register will be the first value in the look- up table and for the next 2. PWM cycles the value assigned to the CCPR1 register will be the second value in the look- up table and so on. Since a single sine wave is made up of 5. Time period of one sine wave = 4. Since the frequency is the reciprocal of the time period the frequency of the sine wave can be calculated as; Frequency = 1 / Time period = 1 / 2 * 1. Hz. The frequency of the sine wave = 5. Hz. PWM Duty- cycle: The Duty- cycle in this particular project is varied according to the look- up table whenever a timer.
The maximum Duty- cycle (1. PWM period. The Duty- cycle generated by the microcontroller depends on the value in CCPR1 register and for a maximum value of 2us the value that should be written in the CCPR1 register can be calculated using the equation for PWM Duty- cycle; PWM Duty Cycle = (CCPR1 * TOSC * (TMR2 Pre- scale Value)Using the above equation, The maximum value of CCPR1 = PWM duty cycle max / (TOSC * (TMR2 Pre- scale Value))The TMR2 Pre- scalar value is selected as 1 and the TOSC is already calculated as 0. CCPR1 = 2 * 1. 0^- 6 / 0. The CCPR1 can be written with any value between 0 and 1. This look- up table used in this project satisfies this condition since the minimum value in the look- up table is 1.
The filter design: The following figure shows a microcontroller generating PWM wave which is then used to generate the corresponding analog voltage with the help of a filter circuit. The filter could be any device which can generate the equivalent voltage of a PWM voltage. It normally consists of integrator, amplifiers, load drivers etc. They generate the voltage corresponding to the pulse width modulation in the wave and can fed that voltage to the load device.
In this particular project the filter circuit is actually an integrator made with a single capacitor. The filter simply integrates the duty cycle of each PWM cycles and hence averages out the voltage in a PWM wave as shown in the following figure; The red colored lines shows the capacitors integration action on the PWM wave and the orange colored lines shows the average voltage that is available at the output of the integrator circuit corresponding to the PWM wave. In the above figure three different PWM waveforms are shown with PWM 1 has a duty cycle of 5. If the 5. V logic is used to generate the PWM then this average voltage will be almost equal to 2. V. The second waveform PWM 2 has a duty cycle of 1. V logic. The third waveform PWM 3 has a duty cycle of 9. V logic. The above discuss things will happen only when the time period of the integrator is equal or slightly greater than the Period of the PWM.
The integrator is a circuit which has a resistor and a capacitor in series connected across the input and the ground and the analog voltage is obtained across the capacitor as shown in the following figure; The product of the value of the resistance R and the value of capacitance C in the above circuit should be almost equal or slightly greater than the Period of the PWM wave. RC > = PWM Period.
From the calculations done for the Period of PWM wave, the value of the PWM Period is obtained as 2us. Hence for the proper generation of voltage according to the modulation of the pulses in the wave, the product RC should be equal or greater than 2us. Consider the 0. 1u. F capacitor is selected as C, and then the value of R required can be calculated as RC > = 2us. R > = 2us / CR > = 2 * 1.
R > = 2. 0 ohms. Hence if the value for the C is taken as 0. F and the value of R is taken as 2.
PWM wave having a Period of 2us. Note that the value of R is very small and this 2.
Hence there is practically no need to use a 2. The circuit: The circuit operates on well regulated 5. V supply with a 4. MHz external crystal oscillator which forms 4. MHz CPU clock with the help of an internal PLL.
The standard 0. 1u. F capacitor is used as the filter circuit (RC integrator) to generate the voltage equivalent of the PWM.
The capacitor is connected across the PWM pin (PIN 1. The probe from the CRO is connected across the ground and the PWM pin of the microcontroller. Tips for better results.