Issues with Arduino PWM inverted mode

By Julian

Youtuber, shed dweller, solar charge controller aficionado

15 thoughts on “Arduino pwm inversion issue – muppet 2 project”
  1. Avataaar/Circle Created with python_avatars REDDY NIRANJAN says:

    Hello, my name is NIRANJAN, I am not getting proper inverting pwm from Arduino Uno, if you have any methods to invert the pwm signal practically. Please let me know if any have.

  2. Avataaar/Circle Created with python_avatars Carlos Sorondo says:

    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 .

  3. Avataaar/Circle Created with python_avatars J Q says:

    JULIAN ILETT YOU SHOULD DEFINITELY MAKE A VIDEO EXPLAINING HOW TO BUILD A CIRCUIT, CODE, APP AND ZERO CROSSING CIRCUIT WHICH CAN CONTROL AT LEAST 5 AC LIGHT BULBS AND BE ABLE TO NOT ONLY TURN THEM ON/OFF BUT DIM EACH ONE OF THEM SEPARATELY VIA BLUETOOTH HC-06 AND ANDROID APP. THAT WILL BE A CHALLENGE!!!

  4. Avataaar/Circle Created with python_avatars Vyl Bird says:

    I've offered you source code, I've suggested the right chip. I've got a whole prototype all wired up that I've offered to post you – a functional MuPPet, having solved most of these problems, fully documented and open. Please, just let me help you.

    I've faced all these problems you are having. I know how to do this. But I can't quite finish it off – take my work, combine it with your own.

  5. Avataaar/Circle Created with python_avatars Liam O'Brien says:

    I'll second the comments about ditching the Arduino libraries, I'm currently in the process of building a HV high power MPPT controller. I decided to go with talking to the AVR directly using the registers and timers, I first used Fast PWM mode and encountered some nasty spikes when on 0% duty cycle, once I switched to Phase Correct mode they went away and my MOSFET thanked me. This is actually a documented issue in the ATMEL chip data sheet. Not sure about the issues with the inverted PWM but I think Phase Correct would solve the larger problems.

  6. Avataaar/Circle Created with python_avatars SnrC says:

    unsigned int math resulting in overflow ?

  7. Avataaar/Circle Created with python_avatars yagoa says:

    all you need to do is to put a if statement to 100 and 0 %

  8. Avataaar/Circle Created with python_avatars RWBHere says:

    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.

  9. Avataaar/Circle Created with python_avatars c muller says:

    Just invert the duty cyle yourself with a pwm (100-dc)

  10. Avataaar/Circle Created with python_avatars PIXscotland says:

    Your project won't need the full span of PWM from 0 to 100%.
    I'd suggest just finding the safe zone for PWM and not stray outside that. Probably 2%-98%.
    Hard code the levels outside this is you need to.

    While using external hardware to do the PWM will work it's overkill and adding to the BOM for no real function.
    Commercially the extra components would not happen and I think for your project it shouldn't either.
    Finding issues and concerns, analysing them and deciding if they are important is a large part of the design process.

  11. Avataaar/Circle Created with python_avatars LALORTECH says:

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

  12. Avataaar/Circle Created with python_avatars Mike R says:

    Julian, Instead of fixing this anomaly externally, why not just fix it in the Arduino code? I believe you could nest two conditionals in the main loop and drive the output the way you need it at the top and bottom end of the PWM range. Seems much easier than wiring around this issue — at least to me. Just wondering…Mike

    p.s. regardless of how you choose to address the issue, I'll certainly enjoy watching & learning from you talking the rest of us through your thought process. love your videos & please keep them coming.

  13. Avataaar/Circle Created with python_avatars John Wasser says:

    The analogWrite() function has special cases for 0 and 255 inputs. The Arduino core doesn't know that you jiggered with the hardware registers to invert the signal. You could copy analogWrite() from the core and write a version for inverted PWM.

  14. Avataaar/Circle Created with python_avatars MobiusHorizons says:

    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?

  15. Avataaar/Circle Created with python_avatars Steven Ingram says:

    Hmmm. Do you think the value the pot is generating is a range from 0 to 1 (which serves as the frequency seed for the duty cycle). If that's the case, it would explain what's happening here. Since !0 is true/on (which causes it to go from almost always off as you approach 0 to suddenly on when you reach 0) and !1 is false/off (so it goes from almost always on as you approach 1 to suddenly off when you reach 1). So when you hit the limit (0 or 1) it does the opposite of what is expected. So it seems like you could write a condition to check for true or falseness… and while not true or false, invert the value… else return the value.

    Here's hoping I said that the right way around. In my head I'm actually seeing something like:

    if(value !=0 || value !=1) return invert(value) else return value;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.