![]() With a better filter, you can either get a cleaner output or you can use a lower PWM frequency. You would specify the output frequency and how pure it has to be - the allowed limits for harmonics of the generated signal frequency and allowed limits for the PWM frequency that can be present in the output signal.įrom the allowed harmonics you would figure out how many steps per second and at what voltage resolution you have to have to keep the harmonics below the limit.įrom the limit for the amount of PWM frequency allowed to be in the signal, you can figure out how much higher than the signal frequency the PWM frequency has to be. The correct way to figure out the required PWM frequency would be to start at the end result and work backwards. That's enough that you don't really see the PWM frequency in the output. That's high enough not to attenuate the generated 50Hz sine wave, but at 31372 Hz it will attenuate the PWM by about 24dB. The circuit given uses a 47 ohm resistor with a 22♟ capacitor. Those filters aren't very effective, so you have to set the cutoff very low (far below the PWM frequency) to clean up the output. The example is using a simple RC filter to remove the high frequency PWM signal from the output signal. That's 15500 points per second.įinally, you have the low pass filter. The example generates 314 points for a 50Hz wave. In reality, it is better to generate a lot of points for your signal. It also says you need a low pass reconstruction filter for that to work properly. The Nyquist criteria says you need at least twice as many points per second as the signal you want to generate. To get a smooth representation of a sine wave, you need to generate a lot of points in the wave. The second consideration is the signal to be generated. ![]() 31372 is a frequency that is easily generated using the given timers and clock frequency. You couldn't, for example, easily hit 31380. Since it all has to work with 8bit or 16 bits values and the processor clock runs at a particular frequency, only certain frequencies are possible. The code is using values from a formula given in the datasheet of the processor. The first is that the microprocessor and the libraries used in the project can conveniently generate the frequency. The answer is that the chosen frequency is arrived through several considerations. So you can't get exactly all frequencies, so pick the closest. Note if the chip creates the timer clock with an integer divider from its main clock, then it will have to be an integer ratio. So, wet finger in the breeze, pick a compromise, 32 kHz, why not. Also you'll need some memory to store the values, etc. If it doesn't, that will be an interrupt, so Fs is limited to the max interrupt rate. Something will have to load each sample value into the timer, once per cycle. ![]() So the sine will look jaggy unless dithering is applied. If we have 16MHz clock and a period of 16 cycles, we can have Fs=2 MHz, but we have only 16 output levels, ie a 4-bit DAC. ![]() It's a PWM, so the number of distinct values each PWM sample can have is equal to the clock frequency used by the timer divided by the PWM period. With 4 samples per period, unless we have a perfect sinc filter, the sine will look like a square with the edges rounded off by RC exponential decay. We want enough samples per cycle of our sine so it still looks like a sine. Since it is cheaper to use a higher frequency than to add a N-th order filter with a ton of opamps, then let's raise the frequency.Įach PWM cycle outputs a digital to analog sample. In engineering terms: there is a cost and complexity compromise between the analog filter order and the sampling frequency. To get a smooth signal with a simple first order RC filter, Fs must be much higher. Sampling theory says Fs has to be at least double frequency F, but that assumes a perfect sinc analog filter which is impossible to make. Higher Fs gives better filtering and allows a lower order filter. The PWM has to be low-pass filtered to turn the square wave into a smooth sine. Ideally we want Fs to be much above F for these two reasons: In the case of this article though, the author just wants to output a sine signal at frequency F. If you want to PWM an inductive load then you'd have to look at the inductance and how much current ripple you want to design in to choose the PWM frequency.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |