Allow adjusting PWM output range for lights, fan or heater channels

Hi All
We have some LED lights whose brightness we’d like to control by PWM via a MOSFET
(although this question could relate to any device which needs proportional control such as a heater or a fan)

So far we’ve successfully configured QGC and ArduSub so that joystick buttons 13 and 14 adjust the pulse duration of the PWM signal on servo channel 8, from 1100us to 1900us.

This is at an update rate of 50Hz on a PH4-mini, or 200Hz on a Pixhawk clone.

The bad part is that this is a very low duty cycle, and not enough to get a bright light - we’d ideally like to be able to go from 0 to 100% - although we wouldn’t expect the brightness to be especially linear :slightly_smiling_face:

We’ve tried tinkering with RC8_MIN, RC8_MAX, SERVO8_MIN and SERVO8_MAX, and monitored the values in MAVLink Inspector and on a scope, but the range of PWM output stays resolutely between 1100 and 1900us.

We’d kind of like to be able to map a joystick input of 1100-1900us onto a PWM range close to 0%-100%. 10 steps would probably be fine. Other ranges might be good for other purposes, of course.

In the file ArduSub/ReleaseNotes.txt there’s this tantalising entry:

Sub 3.5.2 31-October-2017

Changes from 3.5.1:
.
.
.
- Allow adjusting PWM output range for lights channels

but we can’t find where this is implemented in the code or available in the QGC setup. Can you help?
btw thanks for all the amazing work! :smiley:

Hi @BStiles, welcome to the forum :slight_smile:

ArduSub’s joystick button function handling for Lights1 is here:

Somewhat confusingly, the output values are determined by the lights1 input channel range (rather than the SERVOn_ values for the assigned lights1 output channel, which are apparently ignored). That’s probably a bug, but for now you can set the values corresponding the the RC Input channel for the control you’re working with.

For Lights1 that’s RC9 (note the RC_Channels::rc_channel(8); in the implementation is zero-indexed). I’ve confirmed that setting RC9_MIN=1 (0 skipped the lowest step, 1 is still ~0% duty-cycle) and RC9_MAX=5000 (100% duty-cycle for a 200Hz output) or RC9_MAX=20000 (100% duty-cycle for a 50Hz output) allows whichever output channel is assigned to Lights1 (e.g. MAIN 8/servo 8 for your described use-case) to take on values in that range by checking SERVO_OUTPUT_RAW. I imagine that works fine for the actual outputs, but I’ll leave that for you to check with your LED or oscilloscope.

Number of steps can be controlled as usual by the Brightness Steps control from the Lights page, or the JS_LIGHTS_STEPS parameter if for some reason you want more than 10 steps.

Hi Eliot. Thanks for the super prompt response! I’m seeing what the problem was now - I was adjusting the min and max values for RC8, when the input values for lights channel 8 is RC9. I knew this but somehow it slipped my mind :upside_down_face:
It’s working perfectly now using the values you suggested.

The update rate on the PH4-mini on this channel is 50Hz and I’m concerned that this may cause some strobing effects on the onboard cameras. Is it possible to alter this? It’s likely to be controlled by divider ratios for the particular timer channel on the MCU, so it might be tough to do without upsetting other time intervals which depend on this timer.
Thanks again…

1 Like

Excellent! :slight_smile:

Take a look at the SERVO_RATE and RC_SPEED parameters :slight_smile:

You may also want to take a look at your camera framerate options, and Power Line Frequency setting (if one is available for your camera(s)). Ideally you want any flickering to occur at the same frequency as your frames, so that lighting is consistent when the frames are captured.