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

Timer interrupt problem

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



Joined: 28 Jul 2005
Posts: 3

View user's profile Send private message

Timer interrupt problem
PostPosted: Wed Aug 10, 2005 9:15 am     Reply with quote

Hi, I`ve got a problem. I want to set the timer0 to interrupt every 833us to send a bit, but when I use the instruction set_timer0(61371) to make the timer0 interrupt every 833us it seem that the timer is not interrupting every 833us because the data that I recived (I`m sending data via serial to PC) is not the data that I should recive, I don`t understand why.

#int_rtcc
rtcc_isr()
{
set_timer0(61371);
clear_interrupt(int_rtcc);
if(numeroentradas<=9)
{
espera=1;
numeroentradas++;
}

}

void main()
{
setup_timer_0(RTCC_INTERNAL);
set_rtcc(61371);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
while(TRUE)
{
output_bit(TX1,0);
while(espera==0);
espera=0;
output_bit(TX1,0);
while(espera==0);
espera=0;
output_bit(TX1,1);
while(espera==0);
espera=0;
output_bit(TX1,0);
while(espera==0);
espera=0;
output_bit(TX1,0);
while(espera==0);
espera=0;
output_bit(TX1,0);
while(espera==0);
espera=0;
output_bit(TX1,0);
while(espera==0);
espera=0;
output_bit(TX1,0);
while(espera==0);
espera=0;
output_bit(TX1,1);
while(espera==0);
espera=0;
output_bit(TX1,1);
while(espera==0);
espera=0;
numeroentradas=0;
}
}
ckielstra



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

View user's profile Send private message

PostPosted: Wed Aug 10, 2005 9:27 am     Reply with quote

You didn't enable the Timer0 interrupt.

Code:
 clear_interrupt(int_rtcc);

This line is not required, the CCS compiler generates code to clear the interrupt.

This code looks like a software based serial port, do you know CCS has inbuilt functions for this which have been tested, have a lot of functionality and are easy to use?

Code:
#use RS232 (BAUD=1200, XMIT=TX1)

putc(0x02);
mcisabel



Joined: 28 Jul 2005
Posts: 3

View user's profile Send private message

PostPosted: Wed Aug 10, 2005 9:37 am     Reply with quote

Hi, thanks for the answer but I try whit the timer0 interrupt enable and nothing, and yes I know about the rs232 features but I already using that for other serial port. I just like to know why the timer doesn`t do what I want.
ckielstra



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

View user's profile Send private message

PostPosted: Wed Aug 10, 2005 10:30 am     Reply with quote

Quote:
and yes I know about the rs232 features but I already using that for other serial port.

Using the STREAM parameter you can create as many serial ports as you like, only using them simultaneously is difficult.

Try changing your code to:
Code:
#int_rtcc
rtcc_isr()
{
  set_timer0(61371);
  if(numeroentradas<=9)
  {
    espera=1;
    numeroentradas=0;
  }
  numeroentradas++;
}


Problem with a setup like this where the data generation is seperated from the timing interrupt is that your communication routine is blocking the main program, i.e. you can't execute other functions in between without the risk of generating data jitter. Better is to have the interrupt routine do both the timing and transmitting the data.

Many interrupt driven serial port drivers have been published in this forum and on the internet. I can recommend the book Serial Communications from Roger L. Stevens which has a good desciption of several serial protocols like RS232, SPI and I2C and a lot of code examples for the PIC (assembly code).
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Aug 10, 2005 7:25 pm     Reply with quote

Is this a PIC18 or PIC16?

The CCP module might be better for what you want to do.

Also if you use a timer int and are setting the timer to a value, remember to account for the overhead of the interrupt in your timing.
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