Skip to content
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

Problem with servo's #21

Open
wjbraat opened this issue Mar 8, 2019 · 4 comments
Open

Problem with servo's #21

wjbraat opened this issue Mar 8, 2019 · 4 comments

Comments

@wjbraat
Copy link

wjbraat commented Mar 8, 2019

Hi, I am a happy user of your library. Yesterday I ran into a problem however.
I was using a software I2C on pins D12 (SDA) en D13 (SCL). This works fine.
When I attached a group of 6 servo's (pin D3-D5-D6-D9-D10-D11)) to the controller the problem occurred. The servo's on D9, D10 and D11) connected to PortB (same Port as SDA-D12 and SCL-D13) these servo's started oscillating. This also happens when the servo-objects are not written to.

When I moved the software I2C to PortC (A0-SDA and A1-SCL) the problem was gone.

Does the timing of SoftwareWire interfere with the servo timing?

Kind Regards, Willem Braat (Netherlands)

@wjbraat wjbraat closed this as completed Mar 8, 2019
@wjbraat wjbraat reopened this Mar 8, 2019
@wjbraat
Copy link
Author

wjbraat commented Mar 8, 2019

I am using an Arduino Pro Mini (5V) on 16 MHz.

@Koepel
Copy link
Collaborator

Koepel commented Mar 8, 2019

Yes, it does interfere.
Thank you for reporting this issue and for your clear explanation.

It is the same issue as issue #5

The Servo library uses one timer with one interrupt. In the interrupt routine the PWM signals are written to the pins. To do that, the interrupt must run at a high rate. The SoftwareWire library reads a register, changes a bit, and writes the register back. That is not safe.

The OneWire/OneWire.cpp library uses noInterrupt() and interrupt() every time a register is changed. We have to add that as well.

Can you use a different port to avoid it?

@wjbraat
Copy link
Author

wjbraat commented Mar 8, 2019

Thanks you for the quick response.
When I moved the software I2C to PortC (A0-SDA and A1-SCL) the problem was solved!

Regards, Willem

@wjbraat
Copy link
Author

wjbraat commented Mar 8, 2019

It is not often that one uses all 6 PWM ports. For this design it was necessary.
So, the workaround is quite simple: don't run SoftwareWire on a port that drives a servo... :-)
Willem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants