Arduino PWM Inversion Issue - Muppet 2 Project

preview_player
Показать описание
Issues with Arduino PWM inverted mode
Рекомендации по теме
Комментарии
Автор

Can you seriously not get it working using one of the other PWM peripherals? - it's a while since I've used Atmel but there are 3 seperate PWM peripherals on the ATMega with multiple PWM modes (I assume you've read the datasheet and not just relying on what the Arduino library knows how to set up)

mikeselectricstuff
Автор

Hi Julian

You could do something like this in software



if (input=0){
digitalWrite(pin, High);
}
else if input=255{
digitalWrite(pin, LOW);
}
else{
analogWrite(pin, input);
}



I am sure I read some ware that it’s the analogWrite library that dose this actually
doing a digitalWrite instead of setting up PWM if the value is 255 or 0.

MicroMouse
Автор

This is not a quirk of the atmega, because it can and will exactly do what want. The problem is the simple code and the fact that Arduino is hiding too much from the developer. One of the biggest mistakes that the Arduino designers made IMHO. I have seen so many people having problems, because Arduino keeps them from knowing what is actually going on. That said...
• Make sure the timer is in *"phase correct PWM"* mode (looks like it is, since the flanks move symmetrically).
• *Get rid of the "analogWrite".* Write the timer registers directly. It's much faster than calling analogWrite (since you are changing two values you want that to happen as close together as possible) and more importantly you know what really happens to the timer registers.
• *update the timer registers in the timer overflow interrupt.* Otherwise you *will have glitches* that can fry your MOSFETs. If another interrupt triggers just between the two timer value updates, you can end up with two different duty cycles on the outputs for a short time. (again: Arduino isn't helpful here; unless you know exactly what the core and all libraries are doing, there could be a lot of other interrupts happening)

superdau
Автор

I think it is a problem of the arduino analog write, wich looks something like this:
pinMode(pin, OUTPUT);
if (val == 0) {
digitalWrite(pin, LOW);
}
else if (val == 255) {
digitalWrite(pin, HIGH);
}
else


You can find the function in

Meiestrix
Автор

Julian are the signals for example if A is at 10% duty cycle and b is at 80%.. mosfet B shuts off before mosfet B . is this correct . Like you I can not have both mosfets on at the same time and I would like to have the code automatically adjust duty cycle for both A and B . for example when I turn the Pot as A adjust lets say to 10% can be also adjust to lets say 88% or what ever max value I want .

carlossorondo
Автор

is there any reason why you can't just have a bit of code that manages your inverted input so that 0 = 255 and 255 = 0, but the values in between are left intact?

MobiusHorizons
Автор

I'm wondering if this isn't a bug but a feature - if you push the PWM to to the point where it's no longer a "P", it turns off. That is, the inverted and non-inverted outputs go to the same value which *turns off* the driven load rather than apply pure DC across it.

russellhltn
Автор

would it be possible to keep the wave form in it's "stock" form and swap the n-type and p-type fets for that half of the bridge. In that arrangement the signal would interact in an inverted say even at extreme duty cycles.

dennisseuferling
Автор

Julian; a serious question by someone to whom programming might as well be written in heiroglyphics: Why is an Arduino needed for this? Surely it could be achieved more simply, reliably, and for a lower cost, by using dedicated hardware? Thanks.

RWBHere
Автор

Looks tweekable in software? I think it's how it's handling the edge cases of 0x00 and 0xFF (if for example it was 8 bit resolution) so you could patch the own driver source code 👍

backofficeshow
Автор

It might be interesting to see a disassembly of the target code, to see what the Arduino compiler is doing with the source. I have a feeling that it is getting in the way and complicating matters.

Zadster
Автор

makes me wonder if it's an Arduino IDE/compiler issue....

lezbriddon
Автор

I think that's a bug of the arduino library. Tried talking directly to the registers? :)
I seem to recall the can't really go 100% on or off but ridiculously close since it still has to pwm

Chriva
Автор

don't overthink this. just add constrain code and keep it with the 1-99%. Boom. done. No extra failure points required.

learnelectronics
Автор

Software workaround? When you get to a writing 0 or 255 PWM values, switch off the inverted PWM and write the corresponding 0 or 1 to the port, for 1-254, switch inverted PWM back on. There might be a few milliseconds of glitching that you'd need to take care of the order of writing so as not to short with both MOSFETs switched on!

marcusjenkins
Автор

Why (or rather when), do you nees 0 or 100% "PWM"? And if you need it, it could be done in software with a couple of ifs. :)

roberteliassen
Автор

Hi Julian,
How will you handle the required overlap with external components?
Second question: would you ever need 100% PWM on or off in this boost-or-buck converter? Does it then still work?
I can imagine the converter to have certain specs for maximum/minimum conversion. I may be mistaken, but I imagine there is no real need for 100 or 0 percent PWM on the two gates in either buck or boost modes.

Another suggestion was to just use complimentary mosfets. In that case you wouldn't have to use software inversion and perhaps not be bothered by this weird PWM-effect.

MaxintRD
Автор

Inverted signal is supposed to be narrower than the positive, doesn't it?

flyboy
Автор

Why didn't you just swap the wiring around, so that you don't have to do the clockwise and anti clock wise thing!

lalortech
Автор

unsigned int math resulting in overflow ?

ryebis