Skip to content

Add support for Servo #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nseidle opened this issue Jun 26, 2019 · 3 comments
Closed

Add support for Servo #16

nseidle opened this issue Jun 26, 2019 · 3 comments

Comments

@nseidle
Copy link
Member

nseidle commented Jun 26, 2019

Add support for the Arduino library Servo. Owen's already got the analogWrite() function examples that show how to do this. We just need to build out the other parts of the library API.

@nseidle
Copy link
Member Author

nseidle commented Jun 26, 2019

Weird short blip on the pin when using servoWrite(). No load (servo) is attached.

image

image

The blips are 15ms apart so it looks like an analog write issue.

oclyke added a commit that referenced this issue Jul 3, 2019
This waits until a pulse has just been completed to change the compare register values. This attempts to solve isse #16.

servoWrite could cause the signal to be inverted if/when the compare registers were changed at the same time that they matched the timer. This attempts to wait until the timer value is below the smaller compare register to make any changes.
@oclyke
Copy link
Contributor

oclyke commented Jul 3, 2019

@nseidle caught the moment of inversion on a logic analyzer.
inversion

You can see that the timing between servo frames was 21.9 ms consistently. You can also see regular 15 ms spacing between short blips toward GND after the inversion. You will find that these two frequencies meet perfectly at the E1 marker - GND zero.

The test code was waiting 15 ms between each call to servoWrite(). When that delay collided with the asynchronous timer comparison bad things happened (* insert some explanation for what happened in the bowels of the silicon * ) and the signal was inverted.

Commit 82089ed tries to solve this in a stateless manner by ensuring that the timer value is less than the smaller of the two compare values. Initial testing looks promising, however it's still possible that the servoWrite() function tries to change the register values right when ctimer_val == cmpr0_val. I don't know what will happen in that case.

This solution is nice because it avoids the need for an 'is initialized' array for analog output pins.

@oclyke
Copy link
Contributor

oclyke commented Aug 5, 2019

Closing until we hear more...

@oclyke oclyke closed this as completed Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants