View previous topic :: View next topic |
Author |
Message |
dave4 Guest
|
Unstable serial comm when using internal osc? |
Posted: Tue Aug 28, 2007 12:23 am |
|
|
I'm using an internal osc and the serial comm is unstable. Sometime the data is good and sometime it is garbled. Can anyone relate this or I am doing something wrong?
Thanks |
|
|
RossJ
Joined: 25 Aug 2004 Posts: 66
|
|
Posted: Tue Aug 28, 2007 12:57 am |
|
|
Which PIC are you using?
Are you working at room temperature (i.e. 25C)?
Are you autonegotiating the baud rate or is this fixed (at both ends)?
Most PIC18s have a factory calibrated INTOSC which is typically accurate to +/-1% at 25C. The INRC oscillator is very inaccurate and can be +/-10% or more and is NOT appropriate for baud rate generation.
USART comms should be reliable with baud rate errors of a couple of percent. Serial comms using the USART is timing critical since there is no separate clock (as is the case with say I2C). So clock error/drift could well be responsible for data errors.
If you suspect clock/baud rate accuracy problems, test the clock's accuracy. Either use an oscilloscop or some other suitable test instrument, or write a routine to output a fixed length pulse on an IO (say 60 seconds) and time it with a stop watch. |
|
|
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Tue Aug 28, 2007 8:47 am |
|
|
The INTOSC is pretty stable and good enough for UART clocking - we had one project where we were running at a non-standard Baud rate (was around 230kBaud), and the fixed error between both sides was around 3% - and with this we never lost data. So with standard Baud rates if you get within 2% it should be fine. |
|
|
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Tue Aug 28, 2007 9:12 am |
|
|
Using the internal osc on a 485 network caused me problems. The baud rate was ok, but, using a master-query where each slave would respond in a time slot, based on an id, sometimes failed. My time slots were too close together, and by the time id #25 reported, it might crash over top of #24 or #26. Doesn't sound like this is your problem, but thought I'd throw it in just in case
Ken |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue Aug 28, 2007 2:15 pm |
|
|
Its a long shot and it depends on the chip you are using ...but could it be you overwrote the internal rom location that stores the calibration constant
Ex for 12F629
#rom 0x3FF = {0x3490}
//// sets the internal oscillator to mid freq (0x3480) (0x34B0) near 4mhz
//// 0x3FF is top of rom and must contain a retlw instruction
//// with the value for the internal osc calibration
/// retlw is 0x34kk so kk Ex 80 is the value placed in OSCAL
/// osccal is xxxx xx.. max 1111 11.. mid 1000 00.. min 0000 00..
/// 0xFC 0x80 0x00
/// if the location 0x3FF is erased in error the osc won't run
/// freq affects baud rate one 629 needs 3470 the other 34B0 |
|
|
dave4 Guest
|
|
Posted: Tue Aug 28, 2007 3:19 pm |
|
|
i'm using PIC12F683 |
|
|
dave4 Guest
|
|
Posted: Tue Aug 28, 2007 3:40 pm |
|
|
Here is my code
Code: |
#include <12F683>
#fuses INTRC, NOWDT, NOPROTECT, NOBROWNOUT, NOMCLR
#use delay(clock = 8000000)
main()
{
setup_oscillator(OSC_8MHZ|OSC_NORMAL);
while(1)
{
output_high(PIN_A5);
delay_ms(1000);
output_low(PIN_A5);
delay_ms(1000);
}
} |
I'm confused whether this is setup is for internal RC or internal OSC. |
|
|
Guest
|
|
Posted: Tue Aug 28, 2007 3:41 pm |
|
|
dave4 wrote: | Here is my code
Code: |
#include <12F683>
#fuses INTRC, NOWDT, NOPROTECT, NOBROWNOUT, NOMCLR
#use delay(clock = 8000000)
main()
{
setup_oscillator(OSC_8MHZ|OSC_NORMAL);
while(1)
{
output_high(PIN_A5);
delay_ms(1000);
output_low(PIN_A5);
delay_ms(1000);
}
} |
I'm confused whether this is setup is for internal RC or internal OSC. |
And also, I measured the frequency at the IO pin (clk output) and it measured only 2mhz. Maybe I don't understand the purpose of this pin but isn't it suppose to also be 8mhz? |
|
|
Guest
|
|
Posted: Tue Aug 28, 2007 5:34 pm |
|
|
Anonymous wrote: | dave4 wrote: | Here is my code
Code: |
#include <12F683>
#fuses INTRC, NOWDT, NOPROTECT, NOBROWNOUT, NOMCLR
#use delay(clock = 8000000)
main()
{
setup_oscillator(OSC_8MHZ|OSC_NORMAL);
while(1)
{
output_high(PIN_A5);
delay_ms(1000);
output_low(PIN_A5);
delay_ms(1000);
}
} |
I'm confused whether this is setup is for internal RC or internal OSC. |
And also, I measured the frequency at the IO pin (clk output) and it measured only 2mhz. Maybe I don't understand the purpose of this pin but isn't it suppose to also be 8mhz? |
All questions answered.
Thanks. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Aug 29, 2007 7:39 am |
|
|
If you look at the 12F683 datasheet figures 16-38,16-39,16-40 you will see that the HFINTOSC can easily drift over 3% with changes of voltage and temperature. I have seen desktop PCs that were off by almost 2% sitting on my desk. Using a software UART sometimes if 9600 baud doesn't work I try 9408 baud or 9792 baud (9600 +/- 2%) to see if it works better. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|