Gate PWM Not Working Until Reboot – Why Does Reboot Fix It?

Hello everyone,
I’m having an issue with my spreader setup and I’m not sure why it’s happening or why a reboot fixes it.
My spreader uses two PWM inputs:

  • One controls the RPM of the spinning disc (fixed at 2000 PWM),
  • The other controls the gate opening percentage (based on vehicle velocity).
    I’m using a Lua script to control the gate PWM dynamically — it increases as the vehicle moves faster and decreases when slower. However, sometimes after powering on (just connecting the battery), the gate doesn’t open at all. The disc still spins at 2000 PWM, but the gate remains closed.
    If I go to the Compass tab in Mission Planner and click Reboot, everything starts working perfectly — the gate responds to velocity as expected.
    Why does a reboot fix this? Could this be due to PWM outputs being in a bad state on boot and only getting properly initialized after rebooting?
    @Rolf @Eosbandi @Yuri_Rage - could u help me with this one
    Thanks for any insights!

Without a log or your script, it’s really impossible to tell.

Thanks for your time Yuri
Here the Lua code.
RaiTheoVanTocLinear.lua (3.7 KB)
And here the .bin file where the PWM output is showing but the spreader not worked as expected:

The output PWM of spreader are RCOU.C9 and C11.