Fast versus phase-correct PWM

  Рет қаралды 4,302

Uwe Zimmermann

Uwe Zimmermann

2 жыл бұрын

In this video I show the difference between fast pulse width modulation and phase-correct pulse width modulation in an AVR microcontroller.
Edit 2022-06-01: the source code can be found here pastebin.com/XrgEnbUL

Пікірлер: 21
@nsummy
@nsummy Жыл бұрын
Excellent explanation. I’ve been working on a couple of pwm projects and have been completely confused by the difference. My only criticism of this video is you didn’t explain why someone would use fast over phase correct or vice versa :). Either way this gave me a good start. Thanks!
@uwezimmermann5427
@uwezimmermann5427 Жыл бұрын
This video was planned as a short additional material for my students, not as a self-explanatory, full tutorial... if I ever find the time... Just in short, fast-mode gives you twice the pwm frequency at otherwise same performance, but it is also the standard mode in most cases. If you run two channels at different duty cycles still they will either be switched on or off at the same time giving you larger current transients in total. Phase-correct pwm not only distributes the switching times more widely, it also can be used if you need to avoid overlaps between switching, e.g. if you use one channel for the switching of the upper and one for the lower transistors in a H-bridge.
@nsummy
@nsummy Жыл бұрын
@@uwezimmermann5427 Thank you! that helps a lot.
@danhellgren5671
@danhellgren5671 Жыл бұрын
I use this for motor control on a STM32. But I have never heard the expression phase-correct, I have only heard center aligned.
@uwezimmermann5427
@uwezimmermann5427 Жыл бұрын
different manufacturers, different names...
@garavel28
@garavel28 3 ай бұрын
Hello Sir, can I ask you a question via email about the MPPT algorithm that I am trying to make using Arduino Mega 2560?
@grzesiek1x
@grzesiek1x Жыл бұрын
my question is , why my 25 KHz signal on my Arduino Uno (Atmega 328 p) is very stable almost perfect while on Attiny85 there is a constant shift of duty cycle like a few percent and also frequency is not very stable for example between 25 000 - 25 400 it varies etc. Do you have any idea why is it so ? How ti improve it? I am not going to solder this until I make it more accurate (it will be for my ESC of brushed motors controller project and I need it to be very stable).
@uwezimmermann5427
@uwezimmermann5427 Жыл бұрын
all Arduino boards I know of (especially Uno and Nano) use a 16 MHz quartz crystal, sacrificing 2 pins of the package of the Atmega328. You can also run the Atmega328 on an internal RC-oscillator like the ATtiny. The internal oscillator can be calibrated, but by default it is specified to be accurate to about 2% as you observed.
@grzesiek1x
@grzesiek1x Жыл бұрын
@@uwezimmermann5427 Thanks for the reply. I really appreciate it.
@dare-er7sw
@dare-er7sw 2 жыл бұрын
Hi, I need your brain power. Dual PWM resistor weighting in analogue adds more resolution and bits. I'm making an AM transmitter. Can we do that digitally??? Combining bits from D9 D10 phase correct to 14 bit possible? I have 31.25 KHz on each pin as PWM. A0 takes in Audio. ADC is 10bit only but I want more PWM resolution to suppress noise I need to combine the high and low bits digitally and perhaps add a bit or two from Arduino clock, maybe.. so this 31.25KHz PWM is gonna turn on and off 1600KHz carrier via a nand gate. We got audio now at 1600KHz No one is able to help me. Not even Arduino forums. Please suggest.
@uwezimmermann5427
@uwezimmermann5427 2 жыл бұрын
With "digitally" do you mean OOK (on-off-keying)? Otherwise I don't see how "switching the carrier with a NAND gate" will give you a continuous modulation of the amplitude of the carrier wave. Well, in principle of course, if you switch on and off the carrier wave and then pass it through a high-pass filter getting rid of the PWM signal, you would get the carrier wave and its sidebands through and thus your desired signal, the separation between 31 kHz and 1600 kHz might be enough to handle for a quite simple filter. But then you should also be able to do this simultaneously from two resistor-weighed outputs - however you would need to handle the carrier switching and filtering separately for both channels and only mix them afterwards. Essentially you would need a bandpass filter for each "PWM channel" around the carrier frequency, wide enough for your desired audio frequencies and narrow enough to suppress the PWM frequency. After the filter you mix the two signals using weighed resistors.
@Mehmetemin0606
@Mehmetemin0606 Жыл бұрын
ı need some help. ı want to keep first pwm stabil and control second pwm with potentiometer
@uwezimmermann5427
@uwezimmermann5427 Жыл бұрын
that could almost sound like a question I ask my students... If you are using an ATmega and you are using the same timer for both pwm-channels, then you can change the duty cycles individually by setting the OCRxA and OCRxB to different values. E.g. for Timer1 this would be OCR1A and OCR1B. Now you can use one of the ADC channels to read the potentiometer value and use this value to set the corresponding OCR-value. In Timer1 there is are 10bit PWM modes which suit the 10bit ADC of the Atmega ideally. In the main loop you would periodically start an AD-conversion and then just write OCR1A=ADC. In Arduino-speech you could do almost the same by writing analogWrite(analogRead(chan)/4) here you need to divide by 4 because in the default settings analogRead is 10bit wide but analogWrite only 8bit.
@Mehmetemin0606
@Mehmetemin0606 Жыл бұрын
@Uwe Zimmermann It is so important proposal for my school project. thanks a lot for your help.
@jesusreignonhigh6732
@jesusreignonhigh6732 2 жыл бұрын
Can I get the code and schematic pls?
@uwezimmermann5427
@uwezimmermann5427 2 жыл бұрын
there is really not much of a schematics - the main connection is a 10 kΩ potentiometer to give a variable voltage to pin ADC0 and the multiplexed 4-digit LED display, connection description is in the source code which I had to tidy up a bit: pastebin.com/XrgEnbUL
@jesusreignonhigh6732
@jesusreignonhigh6732 2 жыл бұрын
@@uwezimmermann5427 thanks
@9700784176
@9700784176 Жыл бұрын
what is the use of one over the other.
@uwezimmermann5427
@uwezimmermann5427 Жыл бұрын
If you just want to control individual loads then you would prefer fast PWM because it gives you twice the pulse frequency and thus is easier to filter, less flicker. But if you want to control a load in an H-bridge configuration then the phase-correct one will give you non-overlapping signals for the high side and low side drivers.
Hardware CPU Timers - PWM and Interrupts - Beyond Arduino #2
9:31
megaAVR Microcontrollers: Fast PWM Generation
21:39
Jonathan Currie
Рет қаралды 12 М.
Useful gadget for styling hair 🤩💖 #gadgets #hairstyle
00:20
FLIP FLOP Hacks
Рет қаралды 7 МЛН
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 79 МЛН
Duty cycle, frequency and pulse width--an explanation
8:53
Justin Miller
Рет қаралды 460 М.
STM32 PWM basics
18:31
Random Rick
Рет қаралды 20 М.
PWM in AVR
15:13
DrMattMarshall
Рет қаралды 14 М.
Getting started with AVR and platformio
18:09
Uwe Zimmermann
Рет қаралды 12 М.
ATmega328 and PlatformIO - no Arduino!
16:21
Uwe Zimmermann
Рет қаралды 11 М.
Cheap Risc-V Supercluster for $2 (DIY, CH32V003)
9:02
bitluni
Рет қаралды 246 М.
5 Ways To Generate A Sine Wave (Analog)
13:16
Sine Lab
Рет қаралды 84 М.
AVR 22# ШИМ.
20:52
Andrey Frolov
Рет қаралды 3 М.
Arduino PWM without analogWrite() - Muppet 2 Project
13:08
Julian Ilett
Рет қаралды 28 М.
Запрещенный Гаджет для Авто с aliexpress 2
0:50
Тимур Сидельников
Рет қаралды 409 М.
Looks very comfortable. #leddisplay #ledscreen #ledwall #eagerled
0:19
LED Screen Factory-EagerLED
Рет қаралды 3,6 МЛН
#samsung #retrophone #nostalgia #x100
0:14
mobijunk
Рет қаралды 10 МЛН
Rate This Smartphone Cooler Set-up ⭐
0:10
Shakeuptech
Рет қаралды 4,6 МЛН