CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

communication problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vpan



Joined: 31 Oct 2008
Posts: 14

View user's profile Send private message

communication problem
PostPosted: Wed Nov 19, 2008 2:04 pm     Reply with quote

I want to communicate with a pc through rs232 and pic 16f628 and crystal 4Mhz at 19200 and works fine. When I replace the crystal with one at 20Mhz it doesn't work. I put a pic 16f877 too and it has the same results. Is there anything else I have to do to make it work ?

(when a make the change with the crystal I correct the code too)

The circuit is made on PCB.

My purpose is to make it work at 115200 (20MHz XT) but I see that I can't do it nor at 19200.
It's probably not going to work right ?
Any ideas ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 19, 2008 2:17 pm     Reply with quote

Quote:
it doesn't work.

What does that mean ?

Quote:
when I make the change with the crystal I correct the code too.

Does that mean you change the #use delay() statement to this ?
Code:
#use delay(20000000)



Post your compiler version.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: communication problem
PostPosted: Wed Nov 19, 2008 2:20 pm     Reply with quote

vpan wrote:
...16f628 and crystal 4Mhz at 19200 and works fine....When I replace the crystal with one at 20Mhz it doesn't work....(20MHz XT) ...

For 20 MHz you cannot use the XT oscillator configuration. You must use the HS configuration.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Guest








PostPosted: Wed Nov 19, 2008 2:30 pm     Reply with quote

Your loading capacitors may also be wrong for a 20 MHz crystal. Check the Microchip data sheet and the crystal manufacturers recommendation.

HTH - Steve H.
vpan



Joined: 31 Oct 2008
Posts: 14

View user's profile Send private message

PostPosted: Wed Nov 19, 2008 2:31 pm     Reply with quote

thanks both of you...

my compiler version is 4.057

i did all necessary corrections

when i connect 20MHz i have wrong results!
on 4 MHz everything is fine!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 19, 2008 2:34 pm     Reply with quote

Post a test program that shows the problem.
Here is an example of a test program. Notice how it's very short.
http://www.ccsinfo.com/forum/viewtopic.php?t=25130&start=2
Don't post a large program.
vpan



Joined: 31 Oct 2008
Posts: 14

View user's profile Send private message

PostPosted: Wed Nov 19, 2008 2:47 pm     Reply with quote

Code:
#include <16F628.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use RS232(baud=19200, xmit=PIN_b2, rcv=PIN_b1)
#byte PORTA=0x05
#byte PORTB= 0x06
     //#byte PORTC= 0x07
#define button PIN_A4
#define del 1


int i=0;


int16 sine[20]={0,100,190,262,309,325,309,262,190,100,
             0,-100,-190,-262,-309,-325,-309,-262,-190,
              -100};
           

void main(){   
set_tris_a(0x1f);
set_tris_b(0x02);
       //set_tris_c(0x02);   
 
   while (TRUE)  {
     
   while(input(button)){;}
                   for(i=0;i<=19;++i){
       delay_ms(del);
       printf ("A %ld\n",sine[i]);}
   }}

there is my code, the comments reported at 16f877

for 4MHz the only change is
#fuses XT,#use delay(clock=4000000)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 19, 2008 3:10 pm     Reply with quote

It works for me. I installed vs. 4.057. I installed a 16F628 on my
PicDem2-Plus board, with a 20 MHz crystal. I jumpered pin B2 to C6
so it would connect the Tx pin on the 16F628 to the MAX232 on the board.
I added a '\r' to your printf statement so it would do a carriage return
after each line. I configured HyperTerminal for 19200 baud, N, 8, 1,
with no handshaking. This is what I get:
Quote:

A 0
A 100
A 190
A 262
A 309
A 325
A 309
A 262
A 190
A 100
A 0
A -100
A -190
A -262
A -309
A -325
A -309
A -262
A -190
A -100


----
Edit: Corrected the Tx pin number to C6.


Last edited by PCM programmer on Thu Nov 20, 2008 1:15 am; edited 1 time in total
pvol



Joined: 10 Oct 2008
Posts: 46
Location: GREECE

View user's profile Send private message

PostPosted: Thu Nov 20, 2008 1:11 am     Reply with quote

Do you have any ideas why don't work for me?

I have 2 crystals and I change them both, but get the same result!
What must I do ?
Ttelmah
Guest







PostPosted: Thu Nov 20, 2008 3:29 am     Reply with quote

The most likely problem is the loading capacitance, or general layout of the board.
Higher frequency crystals, will generally become more critical of errors here, and will probably want a lower capacitance. The manufacturer will give a loading spec for the crystal. Say, something like 20pF. Now the normal crystal layout, with the capacitor between the oscin, and oscout pins, and two capacitors one from each pin to ground, gives the approximation:

Cl = ((C*C)/2C+Cs)

Where 'Cl' is the load capacitance wanted, 'C' if the value of each of the two added capacitors, and 'Cs', is the stray capacitance from the PCB tracks, and IC pins. Now, _provided_ you have the crystal placed close to the chip, whith nice short leads, and no ground plane round the capacitor pins, a typical value for 'Cs', will be perhaps 5 to 6pF (normally 3pF for the PIC itself, and aout the same for the board). Cl, will be from the manufacturers data for your crystals, and might be anything from perhaps 18pF to 40pF. 18 to 20pF, is perhaps typical for a 20MHz crystal.
Solving for 'C', you get:

C = (Cl - Cs)*2

So for a 20MHz cystal, with 5pF for stray capacitance and a crystal requiring 18pF load, you get:

C = (18 - 5) *2 = 26pF

Commonly 27pF is used for this configuration.

However visualise instead, using a 'proto' board, with 15pF capacitance between each track block, or a PCB, laid out with a ground plane tight round the crystal legs, giving a simiular capacitance. The leg capacitance of the PIC adds to this, so you get (for the required capacitors):

C = (18 - (15+3)) * 2 = 0pF....

Put perhaps33pF capacitors in the circuit, and the crystal is seeing 35pF, rather than the 18pF, it wants. If the 4MHz crystal, is a design wanting perhaps 27pF, it works, but the 20MHz crystal, is too far out of spec, and the gain falls below the critical value to maintain oscillation...

My guess would be that the board you are using, and the capacitors you have fitted, are giving much too high a capacitance for the higher frequency crystal.

Best Wishes
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 20, 2008 4:26 am     Reply with quote

For most of my quick and dirty prototyping I don't use stabilizing capacitors at all. I know its not good electrical practice, but I've never had a problem to date. Most of my prototyping is done on solderless breadboards with 32kHz-20MHz crystals.

Once I finish prototyping, I solder on the appropriate stabilizing capacitors.

My advice is - double check your circuit for other problems as well. One of the most common mistakes I used to make was interchanging the RX-TX lines. I also used to often forget to connect Vss of the microcontroller to ground. I know these are trivial mistakes, but they happen. Try out a simple LED flashing program. If that works then you can eliminate errors 2 and 3.

Rohit
Ttelmah
Guest







PostPosted: Thu Nov 20, 2008 5:14 am     Reply with quote

'stabilizing capacitors'?!....
Talking about the _loading_ capacitors for the crystal. These are not 'stabilising capacitors', but a critical part of the resonant circuit.
If you are not fitting these, the odds are that if it works, it is because the stray capacitance on the prototype is high enough to get close to the required value. On the overtone crystals used at these frequencies, unless you get into the right 'order', the oscillator risks running on the wrong overtone, if at all...
A small change, just drifts the frequency a little, and on fundamental crystals, you can go a surprising 'way' before the gain drops too far, but on some overtone crystals, the 'commonest' effect is to start oscillating at a lower overtone. However particularly with small crystals, the gain drops rapidly as you move away from the correct loading, and the oscillator not working is quite common.

Best Wishes
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 20, 2008 5:23 am     Reply with quote

Quote:
'stabilizing capacitors'?!
My bad Embarassed
Quote:
if it works, it is because the stray capacitance on the prototype
Yes, I guess you are right about this.

Rohit
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

RE:
PostPosted: Thu Nov 20, 2008 6:00 am     Reply with quote

I always had communication trouble with 20 Mhz crystals on 16F877, I am not sure why, but I think they have something to do with

1. selecting the right capacitors
2. quality of the crystal (I am just guessing here)

In any case the problem was so severe that I replaced them with 16 Mhz ones.

Are you sure the PIC is working with the 20 Mhz crystal, you could toggle an output port high & low in the program and then use a scope to check whether the port is toggling.

thanks
arunb
vpan



Joined: 31 Oct 2008
Posts: 14

View user's profile Send private message

PostPosted: Thu Nov 20, 2008 3:34 pm     Reply with quote

Problem solved!! Thanks to all of you guys!

I change C1 and C2 to 15pf
re-warm some connections, shorted some wires
and now it's work!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group