generating 38khz with pic18f4550 and 4mhz crystal

Post
Tarneem
New Member
2012/12/07 06:13:54
Hi
 
I am trying to use my pic18f4550 as a generator for 38khz Frequency and I have 4Mhz crystal
I am using Timer0 for this purpose and here is the value  I sent to set the time : 0xFFF9
here is the code:
void main ()
{TRISDbits.TRISD0=0;
while(1)
{D0=~D0;
dely();
}}
 
void dely ()
{T0CON = 0x08;// 16 bit mode
TMR0H = 0xFF;
TMR0L = 0xF9;
T0CONbits.TMR0ON=1;
while (INTCONbits.TMR0IF==0);
T0CONbits.TMR0ON=0;
INTCONbits.TMR0IF=0;}
 
Is the value i sent correct?
any suggestion? and if there is any way to ensure that before testing it ( like using any simulator)
 
upand_at_them
Super Member
Re:generating 38khz with pic18f4550 and 4mhz crystal 2012/12/07 08:44:01
No, that value is not correct.  How did you get it?  There are plenty of online PIC timer calculators, such as this one: http://eng-serve.com/pic/pic_timer.html
 
You'll have to use its Timer1 calculator since you're using Timer0 in 16-bit mode.
 
0xFFE6 gets close, but is not exact.
 
Mike