Pages: [1]   Go Down
Author Topic: SerialUSB instability - Program stalls  (Read 747 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I have been testing the stability of my SerialUSB stream for continuous output over long period of time and have been running into some problems.

Here is the Arduino code I am using to test:
Code:
void setup() {
  SerialUSB.begin(115200);
}

void loop() {
  double t_start=micros();
 
  SerialUSB.write(0x99);
 
  double t_end=micros();
 
  //Limit program to 200Hz speed
  while((t_end-t_start)<5000) {
    t_end=micros();
  }
}

And on my computer side I am using the following python module:
Code:
import time
import serial
import getPort //Module returns available serial ports for selection

portname=getPort.get_serial_port()
ser=serial.Serial(portname,115200,timeout=0.1)

try:
    while(1):
        t_loopstart=time.clock()
        print ser.read(1)
        t_loopend=time.clock()
        print "Program Runspeed: %.1f\n" % (1/(t_loopend-t_loopstart))
finally:
    ser.close()
    print "Program Ended"

When I start these programs up at first communication is flawless. Then suddenly around 1 hour of runtime the arduino serial stream stops completely. No more data is transfered. If I stop the python program at this time then open the serial monitor in arduio there is still no serial data being transmitted. The only way to get the serial stream to begin again is to reupload the code to the arduino.

I really don't understand what is happening here, can anybody give me a hint?
Logged

NZ
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think your timer may have a hickup when rolling over to zero.

micros() should use a "unsigned long" and not a "double"

K
« Last Edit: March 30, 2013, 04:34:25 am by fiddler » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think your timer may have a hickup when rolling over to zero.

micros() should use a "unsigned long" and not a "double"

K

Thanks, that was exactly the problem! Never would have guessed that.
Logged

Pages: [1]   Go Up
Jump to: