SOLVED RC Servo PWM control.
@reitinge Thank you.
So, the duty cycle value for 50hz would be from 0.1 to 0.05 (1ms to 2ms pulse width) and for 100Hz would be from 0.2 to 0.1 for example.
But I could not make it work...
Edit: With 500Hz it moved so... Ok
The length of the period for 50 Hz is 0.02 s.
For pulse width 0.001 s:
Duty cycle = 0.001/0.02 = 0.05
Pulse width 0.002 s:
Duty cycle = 0.002/0:02 = 0.1
Are you sure about the frequency and width of the pulses? I would expect a duty cycle range from 0 to 1.
@reitinge Yes but these values of duty cycle does not work as calculated.
@reitinge And I am not sure...
At 50hz the servo just ignores the DOUT signal. It started working at 500Hz up to 5000Hz.
And the Duty cycle calculation does not create the expected response from the servo at all. The width I am sure (but it is around 0.8 to 2.2ms)
So I am confused. I could make the servo works but this formula for the duty cycle and pulse width does not works.
I have connected my Monarco HAT to the oscilloscope and the PWM behaves as expected. I set the frequency to 50 Hz and on the first measurement I set the duty cycle to 0.5 (Figure 1). Figure 2 shows the measurement at a duty cycle = 0.1. Please note that Monarco HAT has open-drain outputs, as shown in Figure 2.
Can you send a wiring diagram to your RC servo?
@reitinge To be more specific, for an open-drain digital output you will need to subtract the calculated duty cycle value from 1:
Duty_cycle = 1 - Calculated_duty_cycle
For 1 ms width pulse and frequency 50 Hz:
Duty_cycle = 1 - 0.05 = 0.95
For 2ms width pulse and frequency 50 Hz:
Duty_cycle = 1 - 0.1 = 0.90
If you are using a DO as an 5V voltage source, see the Using digital outputs in 5V logic circuits chapter here:
The logic is "reversed":
If DOUT=OFF, no connection to ground exists and you will measure 5V at the output. If DOUT=ON, connection to ground is made and there will be 0V at the output. That's how you can control devices which use 5V logic.
I apologize for the mystification in previous posts.
@reitinge With the "Duty_cycle = 1 - Calculated_duty_cycle" it worked like a charm. THANK YOU!
You are welcome