Searching \ for '[PIC] I Can't get a 16F877 to run at 20MHz...' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=16F
Search entire site for: 'I Can't get a 16F877 to run at 20MHz...'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] I Can't get a 16F877 to run at 20MHz...'
2005\11\29@094642 by Kev Pearce \(kevp.com\)

flavicon
face
Hi all,

I have a project where I need to recieve and decode a 9600 8E1 serial data stream.
I've only ever built projects based on 84A and 877's running at 4MHz.

I understand that to reliably decode at 9600 I need to be runnign at 20MHz?

I've tried the settings for 9600:

SerIn2 IBUS, 8276, [WAIT("P"), STR packet\5]
but with a 4MHz resonator but get different results each sample, although the first byte is always correct!

All my 4MHz work has been on an EasyPIC board with a USBPIC1 programmer (both from mikroe.com).

This is all fine. I breadboarded up the same circuit and with a 4MHz it works fine.
Swap to a 20MHz, add a few extra lines to my PICBasic code, i.e.:

DEFINE OSC 20
DEFINE LCD_COMMANUS 4000 DEFINE LCD_DATAUS   100
I recomplie and load... and all I get is solid squares along the top line of the LCD.
If I turn off, swap for a 4MHz res on the same breadboard cct, and power on I get my first line banner text displayed fine! but it does not capture and display the data I send it.

I've perservered over the weekend trying to solve this my self... but no nothing! Os now I need to ask for help. Cct also includes a 2x16 LCD and a MAX232...

Should it be this simple?
Any other ways to reliably recieve a 9600 8E1 data stream?
Might it be working and just an LCD @ 20Mhz problem?  - I suppose I could make it toggle an LED to show it's recieved data rather than reply on the LCD?

I tried the exact same cct and code (minus the osc 20 line, and with the correct serial mode) with a 4MHz resonator and a 2400 data rate and it works perfectly!

Anyone any ideas????


Cheers very much all

Kev/.

2005\11\29@100511 by John J. McDonough

flavicon
face
----- Original Message -----
From: "Kev Pearce (kevp.com)" <spam_OUTlistsTakeThisOuTspamkevp.com>
Subject: [PIC] I Can't get a 16F877 to run at 20MHz...


> I recomplie and load... and all I get is solid squares along the top line
> of the LCD.
> If I turn off, swap for a 4MHz res on the same breadboard cct, and power
> on I get my first line banner text displayed fine! but it does not capture
> and display the data I send it.

The black squares are a dead giveaway that you aren't initializing the LCD.
Chances are your Basic compiler isn't doing such a good job of keeping the
delays constant across clock speeds.  Try stretching out the LCD delays.
The LCD is fine with really slow timing ... but if the timing is a little
fast you won't get it initialized, and until it gets initialized it will be
as dumb as a rock.  Of course, if you are using library routines for the LCD
that came with the compiler, you may be out of luck.

--McD

2005\11\29@101049 by Robert Young

picon face

{Quote hidden}

1) P16F877s came in two speed grades.  Are you using the higher speed
grade?
2) How do you change the oscillator type in PicBasic?  If you were using
MPLAB and assembly I'd tell you to check your flags/options to be sure
you have selected HS as the oscillator type.
3) Have you checked with an oscilloscope (10x probe) that the resonator
is oscillating?  Is the kind with built-in caps?  Too much capacitance
due to bread-board (those white push-in component kind are pretty bad)?

Rob

2005\11\29@102157 by olin piclist

face picon face
Kev Pearce (kevp.com) wrote:
> I understand that to reliably decode at 9600 I need to be runnign at
> 20MHz?

No.  You need to run at a frequency that can be divided down to baud x 16
with sufficiently low error.  Therefore 9600Hz x 16 = 153.6KHz is the lowest
frequency that would work.


******************************************************************
Embed Inc, Littleton Massachusetts, (978) 742-9014.  #1 PIC
consultant in 2004 program year.  http://www.embedinc.com/products

2005\11\29@103204 by Kev Pearce \(kevp.com\)

flavicon
face
Sounds close.... I am using built in routines in PicBasic... I'll try some
bigger timing values etc...

{Original Message removed}

2005\11\29@103412 by Kev Pearce \(kevp.com\)

flavicon
face
> 1) P16F877s came in two speed grades.  Are you using the higher speed
> grade?

It's marked ...877-20 so I assumed that its 20Mhz capable.

> 2) How do you change the oscillator type in PicBasic?  If you were using
> MPLAB and assembly I'd tell you to check your flags/options to be sure
> you have selected HS as the oscillator type.

Oh... always wondered about the oscillator flag. I've always set it to XT
thinking it meant Crystal based i.e. external decrite component.
I'll try HS...

> 3) Have you checked with an oscilloscope (10x probe) that the resonator
> is oscillating?  Is the kind with built-in caps?  Too much capacitance
> due to bread-board (those white push-in component kind are pretty bad)?

Not got to that stage yet... or dusted of the old scope yet either ;-)

Thanks for the comments

Kev/.


----- Original Message -----
From: "Robert Young" <EraseMErwybeakerspam_OUTspamTakeThisOuThotmail.com>
To: "'Microcontroller discussion list - Public.'" <piclistspamspam_OUTmit.edu>
Sent: Tuesday, November 29, 2005 3:10 PM
Subject: RE: [PIC] I Can't get a 16F877 to run at 20MHz...


>
>> {Original Message removed}

2005\11\29@103646 by Alan B. Pearce

face picon face
>I understand that to reliably decode at
>9600 I need to be runnign at 20MHz?

No.

I have had a 16F876 running at 3.6864MHz transmit and receive at 19200
without missing any characters. I used Fr. McGhee's Picuart code as the
basis, and used interrupts with the FIFO from Olins macros to buffer the
input and output streams.

2005\11\29@103850 by Kev Pearce \(kevp.com\)

flavicon
face
I think it was something I read in the docs (so I guess it's a high level
language thing):

http://www.melabs.com/resources/ser2modes.htm

Actually it says you will need more than 4Mhz but I only have 20Mhz
resonators in my draw.

Cheers

Kev/.

{Original Message removed}

2005\11\29@103938 by Kev Pearce \(kevp.com\)

flavicon
face
So the idea of not using hte LCD and trying to simply light an LED, to show
recieved data, might be a worth while test???

Kev/.

{Original Message removed}

2005\11\29@104453 by Robert Young

picon face

>
> > 2) How do you change the oscillator type in PicBasic?  If you were
> > using MPLAB and assembly I'd tell you to check your
> flags/options to
> > be sure you have selected HS as the oscillator type.
>
> Oh... always wondered about the oscillator flag. I've always
> set it to XT
> thinking it meant Crystal based i.e. external decrite
> component. I'll try HS...
>

XT mode won't have enough drive (overdrive) to make the resonator work
reliably at 20MHz.  You need HS mode.

Also, and several other people have already pointed this out, 20MHz is
not a guarantee of getting 9600bps to work, especially if you have other
code bugs.  You get EXACT baud rates by having a crystal frequency that
is a multiple of your baud rate according to the tables found in the
PIC16F877 data sheet.  20MHz will have some residual error in the baud
rate.

Rob

2005\11\29@105525 by David Van Horn

picon face
> Sounds close.... I am using built in routines in PicBasic... I'll try
some
> bigger timing values etc...

Do you have any deterministic way to set timing values?
Have you scoped the interface pins and checked the timing?




2005\11\29@110523 by Kev Pearce \(kevp.com\)

flavicon
face
Interesting, thank you very much for the info...

As the device's main job is to listen to the serial input, it probably worth
me going for a resonator that is a multiple like you say... I'll get myself
a better selection of resonators...

Cheers

Kev/.

{Original Message removed}

2005\11\29@112505 by olin piclist

face picon face
Robert Young wrote:
> 20MHz will have some residual error in the baud rate.

True but at such a high oscillator frequency and low baud rate the divisors
are large and therefore there is good resolution in the divided values.  At
20MHz oscillator and 9600 baud, the exact divisor would be 20MHz / (9600Hz *
16) = 130.21.  At a divisor of 130 you get .77% resolution on selecting the
baud rate, meaning you can hit the desired baud rate with no more than half
that (.38%) error.  That's plenty good enough.  In this particular case you
will get 20MHz / 130 / 16 = 9615 baud, which is .16% high.  No problem.


******************************************************************
Embed Inc, Littleton Massachusetts, (978) 742-9014.  #1 PIC
consultant in 2004 program year.  http://www.embedinc.com/products

2005\11\29@115809 by Joe McCauley

picon face
Why do you need to run at 20Mhz to receive at 9600? My copy of the data
sheet (p114) shows that you can receive at 9600 with 4Mhz. Are you using the
built in USART? If not you should consider it.

Joe

> {Original Message removed}

2005\11\29@122634 by Paul James E.

picon face

Kev,

Are you changing the Oscillator from XT (4 Mhz) to HS (>4 Mhz)?
If not, you probably aren't even getting the PIC to run at all.
Just a thought.   Let us know when you find the answer.


                                         Regards,

                                           Jim


> Sounds close.... I am using built in routines in PicBasic... I'll try
> some  bigger timing values etc...
>
> {Original Message removed}

2005\11\30@051633 by Kev Pearce \(kevp.com\)

flavicon
face
Hi all,

First of let me thank everyone for the great responces. As much as I lie to
fix things myself, when the time comes to give up and ask a web list, the
quality of the replies always amazes me!! Thank you all.

So what I did last night:

Got fed up with the fixed 4Mhz xtal in my EasyPIC board so de-soldered this
and it's caps and replaced with a three pin SIL socket so I could swap
resonators easily.

Then pop in a 20MHz res and set the Oscialltor mode to HS and hey presto it
worked!!!
Then it, failed then worked..... I then realised for some reason each time I
reload a new HEX file in the mikroe picusb1 programmer software it resets
the oscialltor mode to XT!!! How annoying! Tried the lastest release no
different. I'll post on the mikroe forums to see if this can be fixed.

The LCD now worked but I could not read the data I needed to read, it was
capturing bytes but they were wrong, but consistanly wrong... so after some
more fiddling I worked it out. I have a feed which is 9600 baud, 8 data
bits, even parity, one stop bit, true levels.
I was using the PBP Serin2 mode of 8276 which should match this... but I
worked out the default number of data bits INCLUDES the parity bit so it was
actually running 7 bits of real data + 1 bit of even parity. I then changed
the default 'total' number of data bits to 9 (8 real + 1 parity) and it
worked perfectly! Not sure if this is just my understanding or if this is
the rs232 standard... or maybe a bug in PBP Serin2 modes???

So thanks once again all... now I can move on to how I capture different
lengths of 'serial packets' where the length is one of the byte at the start
of the packet!


Cheers

Kev/.


{Original Message removed}

2005\11\30@070754 by Richard

flavicon
face
Hi Kevin

Have a look for the include file for the pic you are using, in this case
16f877.inc and open it in notepad, it should look like the following.

;****************************************************************
;*  16F877.INC                                                  *
;*                                                              *
;*  By        : Leonard Zerman, Jeff Schmoyer                   *
;*  Notice    : Copyright (c) 2003 microEngineering Labs, Inc.  *
;*              All Rights Reserved                             *
;*  Date      : 11/07/03                                        *
;*  Version   : 2.45                                            *
;*  Notes     :                                                 *
;****************************************************************
       NOLIST
   ifdef PM_USED
       LIST
       include 'M16F87x.INC'   ; PM header
       device  pic16F877, xt_osc, wdt_on, pwrt_on, lvp_off, protect_off
       XALL
       NOLIST
   else
       LIST
       LIST p = 16F877, r = dec, w = -302
       INCLUDE "P16F877.INC"   ; MPASM  Header
       __config _XT_OSC & _WDT_ON & _PWRTE_ON & _LVP_OFF & _CP_OFF
       NOLIST
   endif
       LIST

What you need to do is edit the text and change it from xt to hs watch case
sensitivity if you are using MPASM

Richard

{Original Message removed}

2005\11\30@074727 by Kev Pearce \(kevp.com\)

flavicon
face
Top tip, thanks

Kev/.

----- Original Message -----
From: "Richard" <@spam@spacecatKILLspamspam450se.co.uk>
To: "Microcontroller discussion list - Public." <KILLspampiclistKILLspamspammit.edu>
Sent: Wednesday, November 30, 2005 12:07 PM
Subject: Re: [PIC] I Can't get a 16F877 to run at 20MHz...


{Quote hidden}

> --

2005\11\30@083813 by olin piclist
face picon face
Kev Pearce (kevp.com) wrote:
> I then realised for some reason each
> time I reload a new HEX file in the mikroe picusb1 programmer software
> it resets the oscialltor mode to XT!!!

Did you set the config bits in the source code?  If not, you can't really
blame it.


******************************************************************
Embed Inc, Littleton Massachusetts, (978) 742-9014.  #1 PIC
consultant in 2004 program year.  http://www.embedinc.com/products

2005\11\30@161008 by Gerhard Fiedler

picon face
Richard wrote:

> Have a look for the include file for the pic you are using, in this case
> 16f877.inc and open it in notepad, it should look like the following.

> What you need to do is edit the text and change it from xt to hs watch case
> sensitivity if you are using MPASM

Usually there is a mechanism to override the default configurations in such
include files. If possible, this is generally better than editing the
include files.

For one, the include files will normally get overwritten by updates to the
compiler. Second, such settings are usually project-specific (rather than
compiler-specific), so having them in the project sources makes more sense
than having them in a default compiler include file.

Another option (if overriding is not possible) would be to use the compiler
include file only as a template for creating your own, project-specific
include file.

(Don't know that compiler at all... :)

Gerhard

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...