Getting 19200 baud serial out of a PIC


+ Reply to Thread
Results 1 to 16 of 16
  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

    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

  7. #7
    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.

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

    Default Re: Getting 19200 baud serial out of a PIC

    Thanks Dave,
    I'll consider that F615 chip. It has the 10 bit A/D that I need too. I can sacrifice the OSC1 pin and justify the cost of an external crystal oscillator I think. It's all coming together now.

    Thanks all.
    "Do or do not, there is no try" Yoda

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: Getting 19200 baud serial out of a PIC

    PIC12F1822

    8 Pins
    Internal precision 32Mhz oscillator.
    EUSART (HSEROUT).

    You can run at 250K baud on the internal OSC.

    Requires PBP 2.60A.
    DT

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

    Default Re: Getting 19200 baud serial out of a PIC

    Quote Originally Posted by Darrel Taylor View Post
    8 Pins
    Internal precision 32Mhz oscillator.
    EUSART (HSEROUT).
    Can the EUSART be inverted? If not, it may require additional hardware, depending on the application.

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Quote Originally Posted by dhouston View Post
    Can the EUSART be inverted? If not, it may require additional hardware, depending on the application.
    The transmit side can be inverted.
    But with a 32Mhz OSC, 19200 is no problem for SEROUT2.

    The bluetooth module may take true levels though.
    DT

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

    Default Re: Getting 19200 baud serial out of a PIC

    That's a really cool chip - but it is pricey. I'm still on PBpro 2.50 - time to upgrade I guess. But I will try out the 12F615 first, I'm getting some next week. My bluetooth (BTM-182) unit needs true serial so that is OK.

    Thanks Darrell - you da man!
    "Do or do not, there is no try" Yoda

  13. #13
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default Re: Getting 19200 baud serial out of a PIC

    Quote Originally Posted by tekart View Post
    That's a really cool chip - but it is pricey.
    It is about the same price as the PIC12f675, give or take 10 cents.

    http://www.microchipdirect.com/Produ...rds=pic12f1822

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

    Default GOT 19200 baud serial out of a 12F615

    Got some 12F615 chips today, and when I remembered to configure the internal oscillator for 8MHz it produced nice 19200 baud using SEROUT2:

    serout2 tx,32,1,[69,10,13] ' test serial output

    Thanks all!
    "Do or do not, there is no try" Yoda

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

    Default Re: GOT 19200 baud serial out of a 12F615

    Quote Originally Posted by tekart View Post
    Got some 12F615 chips today, and when I remembered to configure the internal oscillator for 8MHz it produced nice 19200 baud using SEROUT2:
    Thanks for the feedback.

  16. #16
    Join Date
    Jan 2007
    Posts
    78

    Default Re: GOT 19200 baud serial out of a 12F615

    I had a project 2 winters ago with the 12F675 sending commands to an HF transceiver at 19200 with the chips internal oscillator.
    I ended up bit-banging the output.
    I wouldn't have attempted this if it hadn't been for the fact that the commands were easy to derive.
    Basically, commands included: Select next Frequency band UP, Select next Frequency band DOWN, shut off transmit power, turn ON transmit power, scan up frequency, scan down frequency.
    The challenge was the commands were 32bit segments.
    I used the OSCAL command and a digi-oscope to get the bit-widths correct for that baud rate.
    I may have the code stashed away in notes somewhere, but not sure since that was so long ago.
    Anyway, just to give a report that the chip can output serial at that speed.
    But at that time, I was using PICBASIC (not the picbasic-pro) compiler.
    Good luck! and have fun

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