Pages: [1]   Go Down
Author Topic: SoftwareSerial affects Time  (Read 1305 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello!
I am using SoftwareSerial library.
It is very useful and convenient.
But unfortunately it slows down the clock aproximately 1 hour per day.
I suppose, that the reason is that it stops interrupts, that timer uses to calculate current time.
Please, suggest me how to solve this problem.
Thank you!
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 200
Posts: 12782
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Increase the baud rate.  The risk is a higher incidence of corrupt data.

Upgrade to a "bigger" board.  Something with a processor from the ATmega1280 or ATmega644 family.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 203
Posts: 8722
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you need to keep fairly accurate time you might want to invest in an RTC chip.  The Arduino UNO only has a ceramic resonator so it does not make a very good clock.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 93
Posts: 3981
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Increase the baud rate.  The risk is a higher incidence of corrupt data.

Upgrade to a "bigger" board.  Something with a processor from the ATmega1280 or ATmega644 family.

Really? What's going on?
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 200
Posts: 12782
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


A higher baud rate equates to much less time spent in the interrupt service routine which reduces the chance of an overrun and the amount of overrun if one occurs.  (I'm assuming @miclmr's diagnosis is correct.)

The "bigger" boards have more than one serial port eliminating the need for SoftwareSerial.

@miclmr: Are you using the SoftwareSerial that comes with Arduino 1.0?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


slowing down with 1 hour/day is 4% of the time, sounds like not so much communication.

Are there other things in your sketch that could corrupt timers?
Please post your code.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
God Member
*****
Karma: 26
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You could use my AltSoftSerial library.  It's designed to minimize interrupt latency, so it plays nicely with other interrupt-based functions.

http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html

Sadly, very few people know about AltSoftSerial.  If it solves your problems, please help spread the word.....
« Last Edit: May 12, 2012, 06:49:34 am by Paul Stoffregen » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I am gonna give it a try this afternoon ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 93
Posts: 3981
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A higher baud rate equates to much less time spent in the interrupt service routine which reduces the chance of an overrun and the amount of overrun if one occurs.  (I'm assuming @miclmr's diagnosis is correct.)

Makes sense, just hadn't considered it or had it happen. Maybe I never drove Software Serial hard enough. OTOH, I might not have missed a few millis() here and there smiley-wink
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 200
Posts: 12782
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


That's the problem with milliseconds.  How can you tell if a few are missing?

Pin Change Interrupts are higher priority than the Timer Overflow Interrupts so it's possible for SoftwareSerial to essentially starve the rest of the program of CPU time.
Logged

0
Offline Offline
God Member
*****
Karma: 26
Posts: 606
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

They add up.....
Logged

Pages: [1]   Go Up
Jump to: