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!
----- Original Message -----
From: "Kev Pearce (kevp.com)" <spam_OUTlistsTakeThisOuTkevp.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.
> -----Original Message-----
> From: .....piclist-bouncesKILLspam@spam@mit.edu
> [piclist-bouncesKILLspammit.edu] On Behalf Of Kev Pearce (kevp.com)
> Sent: Tuesday, November 29, 2005 8:47 AM
> To: .....piclistKILLspam.....mit.edu
> Subject: [PIC] I Can't get a 16F877 to run at 20MHz...
>
>
> 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/.
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)?
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
> 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_OUTTakeThisOuThotmail.com>
To: "'Microcontroller discussion list - Public.'" <piclistspam_OUTmit.edu>
Sent: Tuesday, November 29, 2005 3:10 PM
Subject: RE: [PIC] I Can't get a 16F877 to run at 20MHz...
>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.
>
> > 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.
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...
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
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.
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}
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!
----- Original Message -----
From: "Richard" <@spam@spacecatKILLspam450se.co.uk>
To: "Microcontroller discussion list - Public." <KILLspampiclistKILLspammit.edu>
Sent: Wednesday, November 30, 2005 12:07 PM
Subject: Re: [PIC] I Can't get a 16F877 to run at 20MHz...
> 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 -----
> From: "Kev Pearce (kevp.com)" <RemoveMElistsTakeThisOuTkevp.com>
> To: "Microcontroller discussion list - Public." <spamBeGonepiclistspamBeGonemit.edu>
> Sent: Wednesday, November 30, 2005 10:16 AM
> Subject: Re: [PIC] I Can't get a 16F877 to run at 20MHz...
>
>> 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.
>>
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
> 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.