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

Software-Serial with or without GPS and Servo Library #2514

Closed
sleepingshorty opened this issue Sep 13, 2016 · 5 comments
Closed

Software-Serial with or without GPS and Servo Library #2514

sleepingshorty opened this issue Sep 13, 2016 · 5 comments
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.

Comments

@sleepingshorty
Copy link

sleepingshorty commented Sep 13, 2016

Basic Infos

Arduino 1.6.11
Windows 10

Hardware

Hardware: WeMos D1
Core Version: 2.3.0

Description

Problem description

GPS is attached to PIN D5 and D6. When I attach a Servo to a Pin (I used D4 and D3) it starts a slow jitter like 3 times a second.

Settings in IDE

Module: WeMos D1 R2 & Mini
Flash Size: 4/3
CPU Frequency: 80Mhz
Flash Mode: NA
Flash Frequency: NA
Upload Using: OTA and Serial
Reset Method: ?

Sketch

#include <Arduino.h>
static const int RXPin = D5, TXPin = D6;
static const uint32_t GPSBaud = 38400;
TinyGPSPlus gps;
SoftwareSerial ssGps(RXPin, TXPin);
Servo myServo;

void setup() {
  ssGps.begin(GPSBaud);
  myServo.attach(D4);
 myServo.writeMicroseconds(1500);
}

void loop() {
     while (ssGps.available())
         gps.encode(ssGps.read());}

Debug Messages

Output measured with PulseIn and Arduino Mega 1280:
1489
1495
1489
1495
1489
1495
2197
1495
1489
1495
1489
1595
1495
1489
1495
1489
1489
1495
2201
1495
1489
1495
1489
2011

@sleepingshorty sleepingshorty changed the title Software-Serial with GPS and Servo Library Software-Serial with or without GPS and Servo Library Sep 14, 2016
@iliis
Copy link

iliis commented Jun 4, 2017

Can confirm, I'm having the same issue.
Software Serial library from https://github.com/plerup/espsoftwareserial, version 3.2.3

@devyte
Copy link
Collaborator

devyte commented Oct 12, 2017

@sleepingshorty I'm going to assume that the gps sends updates at about 3 times per second?
At 38400 baud, receiving one byte takes about 260us, assuming my quick sloppy math is correct. Considering that both the servo and softwareserial libs are emulated in software, the best case you can expect is a jitter of 260us in servo, which can happen while softwareserial is receiving a byte.
The jitter here is 700us. The remaining 440us could be overhead somewhere else.
I'm not sure what, if anything, can be done here.

@devyte
Copy link
Collaborator

devyte commented Oct 12, 2017

@igrr do you have any insight here?

@igrr
Copy link
Member

igrr commented Oct 12, 2017

I think we have modified PWM implementation to use NMI interrupt, so I'm surprised that this still is an issue. I would have expected the reverse, that is SoftwareSerial being broken by PWM.
No immediate clues, need to debug this.

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Feb 28, 2018
@earlephilhower
Copy link
Collaborator

This should be fixed by a combination of #5578 and #4640.

Before Servo was using timer1 directly, not PWM, so the PWM NMI bit that @igrr mentioned wouldn't even be used. Now, Servo uses the waveform generator which is also NMI, and should be invariant of IRQ disable by SW Serial.

Closing for now, but if someone has the same issue with the GIT head, please do open up a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

5 participants