Completely Detach Servo#7084
Conversation
|
@obrain17 Your PR is kind of running against my major rework of the waveform generator, PR #7022. But you are certainly on to something here. void Servo::detach()
{
if (_attached) {
startWaveform(_pin, 0, REFRESH_INTERVAL, 1);
delay(REFRESH_INTERVAL / 1000); // long enough to complete active period under all circumstances.
stopWaveform(_pin);
_attached = false;
_valueUs = DEFAULT_NEUTRAL_PULSE_WIDTH;
}
}This way, first, without affecting period, the PWM duty cycle is cut to 0 for the next upcoming period. The waveform gets stopped only after the final real duty cycle has completed. |
|
@dok-net I just inserted your code snippet into my project and the servo rotated smoothly without "jumps" with Anyway your code with controlled ending the waveform within a period makes much more sense than my easy workaround. So I will withdraw/close my PR. Thank you for the good work! |
|
@obrain17 When you close this PR, please open an issue so we can keep track of the work to fix it - mention this PR, too, so the discussion isn't lost. |
|
Leaving the pin in input after detach() has bad effects with my servo: the servo sees noise from an adjacent pin and slams the 0 stop, groaning loudly. With a low it wouldn't be picking up noise from adjacent signals. I'll take a scope capture later this evening. I've noticed this with your PR, Dirk. |
earlephilhower
left a comment
There was a problem hiding this comment.
@Tech-TX, you might want to replace INPUT with INPUT_PULLUP manually and give your servo a try.
| void Servo::detach() | ||
| { | ||
| if (_attached) { | ||
| pinMode(_pin, INPUT); |
There was a problem hiding this comment.
INPUT leaves the pin in a high impedance state and subject to noise unless an external pull-up/down resistor is added to the circuit.
INPUT_PULLUP, however, will have a weak pull-to-VCC resistor placed on the pad. Two potential issues are:
- Is "always 1" a valid, safe state for servo control inputs?
- What is the "typical" input impedance of a servo, and how does it compare to the (weak, can't seem to find the exact value) internal pullup?
|
There are two issues I wanted to fix with my PR:
Anyway 1) is fixed with #7023 (containing the above mentioned code) I will close my PR but create an issue instead so our discussion here does not get lost. |


In current implementation twitches may occur when calling
Servo.detach().This is because after
stopwaveformis performed immediately and then followed bydigitalWrite(_pin, LOW)causing a different duty-factor on the PWM.Completely cutting off the pin with
pinMode(_pin, INPUT)solves this issue.A welcome side-effect is that
Servo.detach()would really detach the pin (high impedance) instead of setting it to LOW.