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 CCS Technical Support

PIC18F452 with 40.685 Mhz OSC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mesuty
Guest







PIC18F452 with 40.685 Mhz OSC
PostPosted: Thu Apr 07, 2005 12:48 am     Reply with quote

Dear Friends;

In my project , I have a PC communicating 30 PIC 18F452 over a four wire RS 422 circuit. Level converter is 2x Max 485 one for TX and other is RX. Enable PIN of RX circuit is directly connected to logic 0 to keep all devices in listen mode. TX of PICS are controlled with PIN_C1. I am using hardware UASRT with 9600 Baud and OSC frequency of PIC is 40.685 MHZ.

For the trial purposes , just a PC and one PIC are connected to comms. line. The RX and TX lines are terminated with 120 ohms at PIC side.

When I start the circuit , I am receiving many garbage charecters. After a few charecters sent , transmision pausing as stated in delay_ms(400); . So the routine is working.

My Compiler version is 3.221.

Could someone help me ?

My test routine is as follows.

#include <18F452.h>
#device adc=8
#use delay(clock=40685000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, BROWNOUT, BORV20, NOPUT, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9,stream=MAINCOMM)


void main()
{

set_tris_D(0x00);
set_tris_E(0x00);
set_tris_C(0b10110000);
output_high(PIN_C1); // TX control pin

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_8_bit);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
setup_timer_2(T2_DIV_BY_1,255,16);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER2);
enable_interrupts(INT_TIMER3);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
output_high(PIN_C1);
while(1)
{
putC('a');
delay_ms(400);
}
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Apr 07, 2005 1:19 am     Reply with quote

Your #fuses statement is wrong and possibly your clock source too.

Running at 40MHz is only possible with:
1) A 10MHz crystal and enabling the 4xPLL clock multiplier (replace HS by H4 in the #fuses statement).

or

2) An external clock generator and setting the #fuses statement to EC i.s.o. HS.

Check table 22-4 (page 271) of the PIC18Fxx2 manual.


Another problem in your program is that you are activating a lot of interrupts, but you have no interrupt handlers. So once an interrupt becomes activated it's never cleared and effectively stalls your program.
mesuty
Guest







PostPosted: Thu Apr 07, 2005 8:25 am     Reply with quote

My CPU is working without any problem with HS mode and 40.685 Mhz OSC. Do you think is there a method to communicate at any baud rate, just for trial purposes.

BR.
Ttlemah
Guest







PostPosted: Thu Apr 07, 2005 8:47 am     Reply with quote

From what you describe, your problem could be line bias. An undriven differential pair like this, is _not_ warranted to float to a '0' ('1' at the PIC) state. You can get differential driver/receivers, that are warranted to do this, or differential terminators that do this. Alternatively, just use a resistive divider terminator. So (for 100ohm termination, rather than 120ohm), use:
Code:


5v ------/\/\/\/------+ line1
             1k2          |
                            /
                            \
                            / 120R
                            \
             1K2         |
0v ------/\/\/\/------+ line2


This gives a perceived impedance for the terminator, of 1/(1/1200+1/120+1/1200) = 100R, and applies 0.24v bias voltage to the differential pair. Do this at both ends of the line, and chose which line goes to the high and low connction, so that the bus idles to the 'break' state at the receive pins, and you may well find it all works.
Texas do a software controllable terminator, that is warranted to do this.
HS, is not the suggested mode to operate with an external oscillator. The amplifier in the chip, is only warranted to work to 25MHz, and driving this with an unused 'output' pin, at 40MHz, will waste power. Switch to using EC mode (or EC_IO), which are the recommended modes with an external oscillator.

Best Wishes
Mesuty
Guest







PostPosted: Fri Apr 08, 2005 4:23 am     Reply with quote

Thank to everbody replied;

Everythink seems OK now.

B.R.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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