Jump to content
Sign in to follow this  
plaasjaapie

Clock Crystals Required For Pic's With Boostbasic?

Recommended Posts

I've corresponded with Punerjot about the example code he wrote for running the UART feature of PIC16Fxxx chips. The example code he wrote assumes that a 4 MHz external clock crystal is installed with the PIC chip. Is this something that is a given with BoostBasic or is it specific to his particular example?

 

I'm asking because the other apps for PIC chips that I've encountered in other languages have always relied on the internal clock crystal.

Share this post


Link to post
Share on other sites

Yes besides giving you the CRYSTAL with the boostbasic, the sourcebasic people also will give you the PIC and programmer too. LOL.

 

Dear if you are to use the internal oscillator, you have to enable it in the PCON register. Moreover for USART operations only external crystal is recomded.

Share this post


Link to post
Share on other sites

It is possible to use the internal oscillator with the UART. The only problem is that the exact frequecy of the oscillator is not 4 MHz but somewhere between 3.65 MHz and 4.28 MHz (-8.75% to +7.00% error). This means that the baud rate generator in the UART will have the same error if you use 4 MHz in your calculations.

 

Looking at how RS-232 works and is over sampled on the receive side I came up with the need to sample 10 bits (half way into start, 8 data bits and detect the stop). In order to do this, the baud-rate generator on the reciever must be between -5% and +5% of the baud-rate generator on the transmitter. I got this from the idea that the final sample, that of the stop bit, has to be between 9.5 and 10.5 bit times from the falling edge of the start bit in order to receive the frame correctly.

 

Since this is outside the range on the internal oscillator (for all temperatures and voltage), it is not gauranteed to work. If you keep the thing at room temperature and nominal voltage it most likely will work fine.

 

The other thing that can be done is to self calibrate the baud rate generator. Have the host send the same pattern over and over again until the PIC responds with a happy message. Then, normal communication can begin. During this time, the PIC can adjust the baud-rate generator up and down until it recieves the data correctly. Once the PIC receives the data correctly, it can send the happy message.

 

Too much detail:

You would really like to find the bounds or window between too slow and too fast and place the final baud rate in the center of this window for more stability.

 

If it sounds too ugly to you, buy a crystal!

Share this post


Link to post
Share on other sites

Thanks trossin! That's is exactly the kind of information that I need. I tried to find clock crystals here in town, but the local electronics stockist stopped carrying them a few years back. I'm going to order a handful over the web. :-)

 

Any suggestions as to what I ought to order? While I've built up any number of controller boards using PIC's that other people have designed I'm just now getting into doing a little bit of programming on my own. Any advice that you could give on specs for clock crystals would be greatly appreciated.

Edited by plaasjaapie

Share this post


Link to post
Share on other sites

Dear

 

Thanks trossin!  That's is exactly the kind of information that I need.  I tried to find clock crystals here in town, but the local electronics stockist stopped carrying them a few years back.  I'm going to order a handful over the web.  :-)

 

Any suggestions as to what I ought to order?  While I've built up any number of controller boards using PIC's that other people have designed I'm just now getting into doing a little bit of programming on my own.  Any advice that you could give on specs for clock crystals would be greatly appreciated.

 

 

You need to read the datasheets of the PIC and much more..... about the crystal and clocks. Dont jump to the cosmos theories!

Share this post


Link to post
Share on other sites

Got serial comms on the PIC16F628A going pretty reliably at 19,200 baud last night without an external clock crystal. I've built boards that other people designed and programmed that were doing it. Now, I have as well. :-)

Edited by plaasjaapie

Share this post


Link to post
Share on other sites
Thanks trossin!  That's is exactly the kind of information that I need.  I tried to find clock crystals here in town, but the local electronics stockist stopped carrying them a few years back.  I'm going to order a handful over the web.  :-)

 

Any suggestions as to what I ought to order?  While I've built up any number of controller boards using PIC's that other people have designed I'm just now getting into doing a little bit of programming on my own.  Any advice that you could give on specs for clock crystals would be greatly appreciated.

 

I always run my PICs at the highest frequency they can run unless I'm worried about battery life. This way you get all the performance that you paid for. So, for the 16Fxxx series I would suggest getting 20 MHz crystals. Don't forget to buy some 20pF ceramic capacitors as well if you want the crystal to be very stable. I found that I only need them if I want to implement a clock. Also, don't forget to program the configuration bits for HS mode instead of XT mode.

 

As always, check out the data sheet to see how to connect the crystal and capacitors. Also, check out the voltage and frequency curves to see what the max frequency that you can run at. You have to run at greater than 4.5 V to run at 20 MHz.

Share this post


Link to post
Share on other sites

Thanks again Trossin! Right now while I'm learning I don't really need a whole lot of performance. Before too long, though, I expect to be doing some stepper motor control work. I'm starting with a board schematic designed by a friend which is having problems generating the upper end of performance that the charts for the steppers indicate ought to be possible. I'm suspecting that amping up the frequency will give us a better handle on generating PWM pulses than we have at present.

 

These are still VERY early days though. :-)

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...