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

need a help to generate 9600 Baud rate for timer2 of PIC18

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







need a help to generate 9600 Baud rate for timer2 of PIC18
PostPosted: Wed Jun 17, 2009 12:06 am     Reply with quote

Dear all,

I am writing a POCSAG encoder using PIC18f2525 chip. All my function routines are working fine except I am not getting a very good accurate 512 Baud rate. I used a 11.0592 Mhz XTAL and I tried to generated 9600 BPS interrupts. 18Ticks of 9600 will generate very accurate 512 Baud rate. I am hoping someone can save my pain of this in interrupt for timer2. The version of compiler I am using is 4.093.

Thanks in advance

Mark H
Australia
Ttelmah
Guest







PostPosted: Wed Jun 17, 2009 8:40 am     Reply with quote

Are you using the UART for something else?. If not, just use it.
There won't be any 'off the shelf' code to match what you want, since you are doing unusual counting etc.. The 'odds' are that you would be better wth a slower interrupt. as it stands, you only have 286 machine cycles between interrupts. Subtract the overhead of handling the interrupt themselves, and the work of rotating the byte concerned, and you risk interfering with the timing, if anything else is going on at the same time.
You don't say whether you want to send or receive, or both?.
Realistically, from your master clock, using Timer2, use /4 prescaler, divide by 135 (134 counts), then use the /10 postscaler, to give an interrupt at 512 times per second. This would be the 'simplest' for sending. For receiving, you would need to sample faster, but I'd still not go up to 9600. Instead stick to something like 2048, by just cuttng the prescaler to /1. You are going to be doing a surprising amount in the interrupt, so keep the rate down, to have any hope of it working.

Best Wishes
mark h
Guest







PostPosted: Wed Jun 17, 2009 9:10 am     Reply with quote

Dear Ttelmah,

I am not using uart for the Pocsag Encoder application. Yes Uart is used for ring buffer in this application for receiving data ( from my rs232 from PC applicationin) #int_rda with rcie = 1. This project was written for Mega8 in Codevison C for AVR. I ported code to PIC18f2525 and all OK
except the timing for timer2.

Yes. I am send Pocsag Coding in 32 bit codeword(called a frame) for at least from 1 batch (17 frame = 1 batch) to n batch.

You suggested as follow:
Realistically, from your master clock, using Timer2, use /4 prescaler, divide by 135 (134 counts), then use the /10 postscaler, to give an interrupt at 512 times per second. This would be the 'simplest' for sending.

So toutps3~toutps0 --> 0101 /10 post scale
PR2 = 134
t2ckps1~t2ckps0 --> 01 /4 prescale

I will try tomorrow.

Thanks & Best Regards,

Mark H
Australia
markh
Guest







PostPosted: Thu Jun 18, 2009 5:20 am     Reply with quote

Dear Dear Ttelmah,

I followed your suggestion as follows for interrupts
for 11.0592Mhz Xtal

#int_TIMER2
void TIMER2_isr(void)
{
timeset = 1;
}

void delay_512bps(void)
{

timeset =0;
tmr2ie =1;
while(!timeset);
tmr2ie =0;
}

of course I used
setup_timer_2(T2_DIV_BY_4,134,10);
gieh = 1;
giel = 1;


it works well now with almost perfect timing (when I nearused with my frequency metre I got 4010 us rather than 3906 us (512 bps). anyway I will add some offset to the PR2 value.

Thanks again for your good advice.

BTW, pocsag paging protocol info can be found by googling
"pocsag protocol"

Best regards from Down under

Mark H
Sydney, Australia[/list]
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