Go Down

Topic: SoftwareSerial affects Time (Read 1 time) previous topic - next topic

miclmr

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!

Coding Badly


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.

johnwasser

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.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Jack Christensen



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?
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Coding Badly


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?

robtillaart


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.
Rob Tillaart

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

Paul Stoffregen

#6
May 12, 2012, 01:45 pm Last Edit: May 12, 2012, 01:49 pm by Paul Stoffregen Reason: 1
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.....

robtillaart


I am gonna give it a try this afternoon ...
Rob Tillaart

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

Jack Christensen


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 ;)
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Coding Badly


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.

Paul Stoffregen


Go Up