PDA

View Full Version : Getting 19200 baud serial out of a PIC



tekart
- 10th February 2011, 18:31
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?

mackrackit
- 10th February 2011, 21:11
SEROUT2 handles 19200 with a 4Mhz or better OSC.

tekart
- 10th February 2011, 21:37
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?

mackrackit
- 10th February 2011, 21:47
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.

tekart
- 10th February 2011, 22:39
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!

BrianT
- 10th February 2011, 22:55
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



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

dhouston
- 10th February 2011, 23:46
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.

tekart
- 11th February 2011, 04:45
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.

Darrel Taylor
- 11th February 2011, 12:17
PIC12F1822

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

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

Requires PBP 2.60A.

dhouston
- 11th February 2011, 13:25
8 Pins
Internal precision 32Mhz oscillator.
EUSART (HSEROUT).Can the EUSART be inverted? If not, it may require additional hardware, depending on the application.

Darrel Taylor
- 11th February 2011, 14:08
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.

tekart
- 11th February 2011, 17:29
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!

ScaleRobotics
- 11th February 2011, 17:47
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/ProductSearch.aspx?keywords=pic12f1822

tekart
- 15th February 2011, 18:24
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!

dhouston
- 16th February 2011, 13:56
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.

dw_picbasic
- 28th February 2012, 22:09
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 :)