Shop OBEX P1 Docs P2 Docs Learn Events
Serial Communications using the Internal Clock — Parallax Forums

Serial Communications using the Internal Clock

Dave HeinDave Hein Posts: 6,347
edited 2006-08-22 16:45 in General Discussion
The internal clock is not very accurate, which causes problems with serial communication. I am able to get serial communications to work with the internal clock by first measuring the actual clock rate generated. I do this by running a program that toggles an LED every 10 seconds, and then measure the actual time between toggles using a stop-watch. I normally run this for 10 toggles to get a more accurate measurement.

I measured a frequency of 4.48 MHz for the SX chip I am using when I set it for 4 MHz. I then derive the number of clock cycles per bit as follows:

CLOCK_RATE = 4480000
BAUD_RATE = 9600
SERIAL_CYCLES = ((CLOCK_RATE+(BAUD_RATE/2))/BAUD_RATE)

My serial I/O routines use the value of SERIAL_CYCLES to generate a delay between each bit. Once I implemented this scheme I haven't seen a problem with serial communications. The drawback to this method is that you have to determine a new value for CLOCK_RATE for each chip that is used.

Dave Hein

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-08-22 15:54
    Dave,

    ·· One other potential problem I see is that you could experience issue during thermal changes.· I can't see the internal RC being stable at different temperature extremes...Say going from a refrigerated condition to the area warming up to say 80 degrees.· Have you tested it in similar conditions?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Dave HeinDave Hein Posts: 6,347
    edited 2006-08-22 16:23
    I only used this method in a normal room temperature range, so I don't know how well it would work at extreme temperatures. You're probably right that there would be problems at very cold and very hot temperatures. Serial communications is quite forgiving, and it can work up to a +/- 5% frequency error.

    Dave
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-08-22 16:32
    Or use an autobaud feature. This would work using message frames
    where each message has a few preamble bytes·to determine the baud rate.
    A source with autobaud detection is here:
    http://www.sxlist.com/techref/scenix/lib/io/osi2/serial/duart_0412.src?key=autobaud&from=%2Ftechref%2Fscenix%2Findex%2Ehtm

    regards peter
  • BeanBean Posts: 8,129
    edited 2006-08-22 16:45
    Dave,
    For non-critical application that is a good idea.
    If your using SX/B it would be really easy just do:
    DEVICE SX28,OSC4MHZ,TURBO,OPTIONX,STACKX,OSC4MHZ
    FREQ 4_000_000, 4_480_000 ' 4_480_000 is the actual clock frequency
    
    PROGRAM Start
    Start:
      SEROUT RA.1,T9600,$AA
    END
    
    

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
    ·
Sign In or Register to comment.