Getting 19200 baud serial out of a PIC


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81

    Default Getting 19200 baud serial out of a PIC

    I am working with a bluetooth module (BTM102) that comes set factory default at 19200. I need to send serial data to it at that rate. It would seem that I need to bump up the clock rate of the PIC to 8MHz. Anyone gone through this? The external xtal needs to be inexpensive for production. Is it as simple as that - just doubling the clock rate and using serout at 9600 baud to get 19200?
    "Do or do not, there is no try" Yoda

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: Getting 19200 baud serial out of a PIC

    SEROUT2 handles 19200 with a 4Mhz or better OSC.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81

    Default Re: Getting 19200 baud serial out of a PIC

    OH Duh! Should have turned the page in that manual. I never used SEROUT2 before...
    I'm using a 12F675, so will I need an external oscillator/xtal/resonator? Or will the internal 4MHz work?
    "Do or do not, there is no try" Yoda

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: Getting 19200 baud serial out of a PIC

    Some of the older chips do not have a very accurate internal OSC, I can not say about the 675. If this is for production it might be worth using a 50 cent resonator just to be sure.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81

    Default Re: Getting 19200 baud serial out of a PIC

    Thanks Dave,
    I dropped in a 10MHz crystal oscillator and YES that works. But not the 4 MHz internal osc apparently.

    Unfortunately a resonator will eat up 2 valuable pins, and a crystal oscillator (using 1 pin) is too pricey for the project. So I'll have to bump up to a 16F627 or something, and that is $$ too. Argh!
    "Do or do not, there is no try" Yoda

  6. #6
    Join Date
    Dec 2005
    Posts
    1,073

    Default Re: Getting 19200 baud serial out of a PIC

    Quote Originally Posted by tekart View Post
    Unfortunately a resonator will eat up 2 valuable pins, and a crystal oscillator (using 1 pin) is too pricey for the project. So I'll have to bump up to a 16F627 or something, and that is $$ too. Argh!
    The 12F615 cost 2/3 what the 12F675 costs and has a 4/8MHz internal oscillator. I've used it at 9600 but have never had the need to try 19200. It's a fairly new chip so the accuracy of the internal oscillator may be better than that of older PICs.

  7. #7

    Default 19200 and clock accuracy

    I make data loggers using the 18F4620 running on internal clock (INTIO2) and a Dallas DS1629 with a 32768 Xtal as RTC and temperature sensor. I do a clock accuracy check by instructing the DS1629 to output a clock at one quarter rate and count transitions. See attached code.

    In over 100 loggers the PIC18F4620 clock accuracy has always been better than 0.1% (1000 ppm) and much smaller than the minimum increment obtainable by changing the OSCTUNE register so I have never had to apply a speed correction.

    I get excellent data with DEBUG at 19,200 bps BUT I ALWAYS use CharPacing 100 to give some extra stop bit time. This functions flawlesly for me.

    HTH
    Brian

    Code:
    TuneOscillator:
         high pgc : pause 2 : debug 13,10,"Comparing IntOsc with RTC ", 13, 10
         i2cwrite SDA, SCl, %10011110, $AC, [ %10000101]  
             'OscOut = OscIn/4, temperature on demand
         pause 20
     'StartConversion:
         i2cwrite SDA, SCl,%10011110, [ %11101110]       ' send $EE   
          'activate DS1629 OscOut to divide by 4.  
          'make a copy of the OSCTUNE register before any changes
          '32768 Hz/4 = 8192 Hz.  A 2 second window should see 16384 counts.
          'NOTE.  Either leave this function active in live logger OR allow
          'conversion time for the DS1629 to fetch tenperature.
          
          count clkpin, 2000, clkcal  'returns number of low to high transitions
          debug 13, 10, "ClkCal = ", #clkcal  'in a 2 second window
          if clkcal > 16384 then 'Clock is SLOW
             debug ", SLOW by ", #(clkcal - 16384)
          else
             debug ", FAST by ", #(16384 - clkcal)
          endif
          debug , " ticks in 16384. " 
          clkerror = abs((1000000*(clkcal - 16384))/16384)
          debug  "Clock error = ", dec clkerror, " ppm", 13, 10
          i2cwrite SDA, SCl, %10011110, $AC, [ %00000101]  'Turn OscOut OFF

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts