Announcement

Collapse
No announcement yet.

SoftPWM vs analogWrite

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • SoftPWM vs analogWrite

    Hi Greig,

    Today I sort of solved a problem that's been bugging me with the Arduino plugin for a while, but which has sat on the back burner.

    I am using my Arduino to send PWM dimming control to meanwell LDD-H constant current LED drivers.

    https://www.meanwell.com/webapp/prod...spx?prod=LDD-H

    One of the specifics of this driver is that it requires a PWM signal between 100Hz and 1kHz. In my testing I've found going over the 1kHz upper limit seems to cause no issue, but going under the 100Hz lower limit introduces a noticeable and irritating flicker.

    When I dim using an Arduino being controlled by the HS3 plugin I get exactly this flicker. For a long while I couldn't understand why, as to the best of my knowledge the PWM pins of an Arduino operated well above 1kHz.

    Tonight I finally understand, it's the PWM library being used. Rather than call "analogWrite", which would set a PWM duty cycle on a hardware PWM pin, the plugin is using the SoftPWM library instead.

    The advantage of SoftPWM is pretty clear:

    - It enables the PWM fade function
    - It allows any pin to be set as a PWM output, not just the "hardware" PWM pins.

    BUT, the default frequency of SoftPWM is only 30Hz, fine for a small diode perhaps, definitely not fine for overhead lighting.

    The library allows for higher frequencies to be set using SoftPWMBegin(). I see this being used in the ino file,under EEPROMSetup. But, if I try to insert a value in the parenthesis, the plugin behaves strangely after upload:

    - "Full" and "Off" are reversed, and the slider acts in reverse.
    - The flicker is still present, as if the config change made no difference to the frequency.


    I've 'sort of' solved the issue as I said, by replacing "SoftPWmSet" with "analogWrite" in the p case statement under Data Input. This actually works and I can now dim without flicker, hooray!


    What I miss out on though, is the PWM fade time. All dimming changes happen instantly and can be a little jarring. There is no smooth transition, which for domestic lighting, is a pretty desirable feature.

    So, my question, is it at all possible to configure SoftPWM for a base frequency above 100Hz? If so, where should I put this and what am I doing wrong?

    I'm using an Arduino Mega 2560 with an Ethernet shield (5100).

    Thanks for your time.
Working...
X