View previous topic :: View next topic |
Author |
Message |
sohailkhanonline
Joined: 06 Mar 2008 Posts: 35 Location: pakistan
|
HS PLL and RS232 |
Posted: Tue Apr 22, 2008 11:24 pm |
|
|
hi
this is my code
Code: | #include<18F4620.h>
#fuses [b]H4[/b],NOWDT,NOLVP, NODEBUG
#use delay (clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,stream=LRF,parity=N)
#include<stdlib.h>
#include<input.c>
void main()
{
char c,d;
int data,result;
{
delay_ms(50);
fprintf(LRF,"\n\rEnter the value\n\r");
while(TRUE)
{
c=fgetc(LRF);
data=c-48 ;
result=data*5;
d=result;
fprintf(LRF,"\n%d",c);
}
}
} |
When I use oscillator in HS-PLL (H4) mode i am getting garbage data at RS 232. but when i change it to HS i am getting correct data.
Please don't consider the calculations.
_________________ sohail khan |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 22, 2008 11:39 pm |
|
|
What is your crystal frequency ? |
|
|
sohailkhanonline
Joined: 06 Mar 2008 Posts: 35 Location: pakistan
|
|
Posted: Tue Apr 22, 2008 11:42 pm |
|
|
my crystal frequency is 20Mhz _________________ sohail khan |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 22, 2008 11:49 pm |
|
|
Use the HS fuse, and the PIC will run at 20 MHz. |
|
|
sohailkhanonline
Joined: 06 Mar 2008 Posts: 35 Location: pakistan
|
|
Posted: Tue Apr 22, 2008 11:57 pm |
|
|
My application is configured at 40Mhz H4 configuration, above code is sample for the rs232 problem. Is there any way to fix the rs232 communication keeping same settings (40Mhz). _________________ sohail khan |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 23, 2008 12:02 am |
|
|
Use a 10 MHz crystal with the H4 fuse. (Remove the 20 MHz crystal).
Set the #use delay() frequency to 40 MHz. |
|
|
sohailkhanonline
Joined: 06 Mar 2008 Posts: 35 Location: pakistan
|
|
Posted: Wed Apr 23, 2008 12:09 am |
|
|
Thank you PCM
TCP/IP stack file ccstcpip.h
contains the code (i am using it)
Code: | #if STACK_USE_CCS_PICENS
#include <18F4620.h>
#use delay(clock=40000000)
#fuses H4, NOWDT, NOLVP, NODEBUG |
Above configuration is by CCS stack
SO is there any possibility for rs232 working in above conditions _________________ sohail khan |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 23, 2008 12:12 am |
|
|
It should work. Add a #use rs232() statement below those statements. |
|
|
sohailkhanonline
Joined: 06 Mar 2008 Posts: 35 Location: pakistan
|
|
Posted: Wed Apr 23, 2008 2:02 am |
|
|
Its not working. Everything is working except rs232. _________________ sohail khan |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Wed Apr 23, 2008 6:45 am |
|
|
I am not sure you are understanding what PCM said. Did you change the crystal to 10MHZ as he indicated?
Just to be clear H4 means the oscillator frequency is multiplied times 4.
This means you CANNOT use the H4 fuse with a 20MHZ crystal. With a 20MHZ crystal your only option is 20MHZ.
You can use, for example, 4MHZ crystal+H4 to get 16MHZ or in this case as
PCM said 10MHZ crystal+H4 to get 40MHZ.
The use Delay() statement value must then match the resulting frequency of the oscillator AFTER the multiplier has been applied.
If you are clear on this I apologize for the short lesson but I wanted to make sure you understood. |
|
|
sohailkhanonline
Joined: 06 Mar 2008 Posts: 35 Location: pakistan
|
|
Posted: Wed Apr 23, 2008 10:11 pm |
|
|
Thanks
I understand..
May be the quality of crystal might be the reason
Any ways Thanks to PCM and all fellows.
_________________ sohail khan |
|
|
|