18F2550 clock scaling

Status
Not open for further replies.

deperkin

Member level 2
Joined
Apr 12, 2009
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,776
scaling question:

I have some code that is refurbished from a pic using 4MHz clock.

I now want to use the code for an 18F2550 that has an internal oscillator of 20MHz.

From my limited understanding this means that I am getting a 5MHz timing on the instructions.

How do I prescale this in order to get the instruction timing to 1MHz???

which would allow me to reuse my existing code (for a universal remote) without having to change much.
(i.e. the pic would be timing like a 4Mhz clock).


Thank all !
 

using an external crystal would be the only way w/o changing the code.
and as far as i know 18f2550 only has a 8Mhz internal clock
 

Here is my code: maybe it is a problem in the code.
I am attempting to code for a universal remote programmed to Sony TV setting.

#include <18F2550.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOLVP //
#FUSES NOPUT

#use delay(clock=4000000) //serial works with #use delay(clock=20000000)
#define RS232_XMIT PIN_C6 //RS232 serial transmit
#define RS232_RCV PIN_C7 //RS232 serial receive
#use rs232(baud=9600,xmit=RS232_XMIT,rcv=RS232_RCV,parity=N,bits=8,stream=COMP)


int counter,i,com,adr;
int16 buffer;
int16 cnt = 0;
#int_ext
void ext_isr(){
output_bit(PIN_C2, 1);
counter=0; //reset counter and buffer
buffer=0;
disable_interrupts(int_ext); //disable interrupts

while(!input(pin_b0)){ //wait for high level
delay_us(15);
++counter; } //time how long has been low
fprintf(COMP,"counter:%u\r\n",counter);
if(counter>=15&&counter<=30){ //if from about 800 to 1000 us
//do routines
delay_us(200);
for(i=0;i<13;i++){ //13 following bits
if(input(pin_b0)){ //if the input high
bit_set(buffer,0); //set the LSB and shift left
buffer<<=1;}
else //otherwise just shift
buffer<<=1;
delay_us(1740); //wait for naxt bit
}
buffer>>=1; //shift 1 right because of last reading
com=buffer&0b00111111; //command is 6-bit long; ignore the rest
buffer>>=6; //shift 6 right
adr=buffer&0b00011111; //address is 5-bit long; ignore the rest
//display on an LCD
fprintf(COMP,"Address:%u Command:%u\r\n",adr,com); //send bytes to the rs232
delay_ms(150);
} //wait
//return(0); //return to main
}

main(){
delay_ms(100);
//output_bit(PIN_C2, 1);
fprintf(COMP,"on... \n\n");
while(1){
delay_ms(100);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
cnt = cnt + 1;
//fprintf(COMP,"cnt:%lu",cnt);
output_bit(PIN_C2, 0);
delay_ms(50);
}
}

Thanks again...

Also I did change and place a 4MHz clock on it and it works now on serial, only the timing is off and i dont get consistent address and command. Also I have to hold the buttons down for a LONG time and sometimes then it doesnt even work...
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…