Jump to content

Recommended Posts

Hi all

 

Im currently having trouble trying to work out the board rate on my current project. The problem im having is i miss understand the data sheet and dont know if my oscillator is 10 or 40MHz. Random characters are coming out in hypertermianal but, i cannot get speed correct. Data sheet link has been included below:

 

http://www.sourceboost.com/Products/EZ-Con..._c_en_turbo.pdf

 

Ok, at this stage can i us the " #pragma CLOCK_FREQ 4000000 " to bring the clock down to 4MHz?

 

Lastly i have included my settings and calculations and settings below:

 

baudcon.3=0;// 8-bit Baud Rate Generator BRG16 = 0;

txsta.2=1; // BRGH =1, High Baud Rate Select bit

txsta.4=0; // SYNC = 0, asynchronous

spbrg=259; // 9600 baud // 10MHz

sspcon1.0=1; // SPI Master mode, clock = FOSC/16

sspcon1.4=1; // Clock Polarity Select bit

sspcon1.5=1; // Synchronous Serial Port Enable bit

 

 

10MHz Calcualation

 

((10,000,000/9600)/16)-1) = 64

 

this is using #pragma CLOCK_FREQ 10000000

 

 

40MHz Calcualation

 

((40,000,0000)/16)-1)=259

 

 

this is using #pragma CLOCK_FREQ 40000000

 

 

hope you can help

 

Elvis75

Link to post
Share on other sites

Elvis75,

 

Im currently having trouble trying to work out the board rate on my current project.  The problem im having is i miss understand the data sheet and dont know if my oscillator is 10 or 40MHz. Random characters are coming out in hypertermianal but, i cannot get speed correct.

The crytsal is 10MHz, it uses the internal 4x PLL to give a 40MHz clock. So the clock rate for the PIC is 40MHz. Us this value when working out things like baud rate divisors.

 

Regards

Dave

Link to post
Share on other sites

Hi

 

 

Ok, thanks for your help. Im a bit lost on the clock #pragma CLOCK_FREQ thing. If i have a 4MHZ ossilator do i need to add #pragma CLOCK_FREQ 4000000 at top of source code? If i have a 10MHz oscillator do i add #pragma CLOCK_FREQ 10000000?

 

I have included the 40Mhz calculations below. Do i need to add the #pragma CLOCK_FREQ 40000000 at the top of the source code, or is this default?

 

 

 

Calculations

 

40MHz Calcualation

 

((40,000,0000/9600)/16)-1)=259

 

baudcon.3=0;// 8-bit Baud Rate Generator BRG16 = 0;

txsta.2=1; // BRGH =1, High Baud Rate Select bit

txsta.4=0; // SYNC = 0, asynchronous

spbrg=259; // 9600 baud // 40MHz

sspcon1.0=1; // SPI Master mode, clock = FOSC/16

sspcon1.4=1; // Clock Polarity Select bit

sspcon1.5=1; // Synchronous Serial Port Enable bit

 

I think this is correct? Can you just have a look

 

Cheers Elvis75

Link to post
Share on other sites

If you do not use the library delay functions or some other generic

library that uses them (you will see a timing warning if you do when

you compile), you do not need the clock pragma at all.

 

... your spbrg value seems a little off... at 40Mhz 9600 might be slightly

error prone with sync=1 ...

From the datasheet table (unsure which chip you have, but if you have it BRG16=0):

9600: SYNC=0 BRGH=0 SPBRG=64 *Error=0.16%

9600: SYNC=0 BRGH=1 SPBRG=255 *Error=1.73%

 

Btw get windmill/comdebug or some other terminal tool that adhears to standards,

Hyperterminal has very many non-standard terminal issues.

 

This is one of the best free tools for fixing problems with a serial capable link:

http://www.windmill.co.uk/serial.html

Link to post
Share on other sites

Hi, thanks for reply

 

Im not using any timming at moment in my source code and therefore i can leave the pragma out, and clock will run at 40MHz?

 

I think my error is slightly high because im using FOSC/16, which calculates to 259. However looking at the 18F2520 datasheet (see below link, page 207 and 209), microchip use FOSC/64 and therefore they calculate it to be 255?

 

http://ww1.microchip.com/downloads/en/DeviceDoc/39631B.pdf

 

Im not sure what im doing wrong. This code works fine on the 16f877 (Hi-Tech, using 4MHz Oscillator), and now i have ported across to 18F2520 (EZ turbo board), i only get random characters comming out on hyperterminal. It indicates the baud is wrong but i cannot see what im doing wrong. Any ideas?

 

Lastly in Hi-Tech i use, while(!TXIF)

 

In sourceboostC i use, while(!pir1.TXIF). Is this correct?

 

Cheers Elvis75

Link to post
Share on other sites

You can use plain old txif or pir1.4 , not sure pir1.txif is valid or not.

All my ported code uses custom remaps to convert the boostC version

to my old mcc18/Hi-TechC.

 

Anyway there are quite a few register differences between the 16F and 18F devices.

Double check its not a silly config issue like port direction or not disabling something

like the wdt. The only other reason i can think why you may have garbage is your not

handling the serial data fast enough.

Link to post
Share on other sites

Hi

 

um.... I dont think i have disabled the WDT. Looking at my 16F source code, i dont think this was required. Is it required on the 18F? If so, how do i disable?

 

Lastly on the 16F i set, sspcon=0x31, but on the 18F they dont have this register, just the sspcon1 register. At this point i set this register to 0x31. Is this corrrect? Or is this my error. I also notice they have a sspcon2 register, but i have not set this up.

 

Cheers Elvis75.

Link to post
Share on other sites

Well i belive it is time for you to do a bit of datasheet reading on those questions

since they are very simple and there are steps in the datasheets that tell you the

info you are asking.

 

As for the WDT, it is enabled by default (well treat it that way and you will have

less issues with it).

Link to post
Share on other sites
I also notice they have a sspcon2 register, but i have not set this up.

 

 

You know it just occured to me that maybe Microchip put that sspcon2 register there to serve some purpose!

 

... and that purpose is, along with sspcon1 and sspcon in PIC16, to control the synchronous serial port and is not required to get your RS232 type serial connection going.

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...
×
×
  • Create New...