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 CCS Technical Support

Strange behavior with timer1 and int_rda

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



Joined: 17 Jan 2004
Posts: 3
Location: Mendoza, Argentina

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Strange behavior with timer1 and int_rda
PostPosted: Sat Jan 24, 2004 8:15 pm     Reply with quote

The following code just read a character and send it back.
When I comment the int_timer1 function the program works OK.
If I comment out this routine so the compiler put it into the object code
the program doesn't work.

Any clue are welcome



//Configuración general

#device PIC16F876 ADC=10

#include <16F876.h>

//#include "modbus.h"

#define FREC_MHZ 4000000

#fuses XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP,NOCPD,WRT

#use delay(clock=FREC_MHZ)

#use rs232(baud=9600,parity=N, xmit=PIN_C6,rcv=PIN_C7,errors,bits=8)

#priority rda,timer1

#use fast_io(A)

#use fast_io(B)

#use fast_io(C)





#define txon output_high(PIN_c6)

#define out1_on output_high(PIN_b1)

#define out1_off output_low(PIN_b1)

#define buzzer_on output_high(PIN_a2)

#define buzzer_off output_low(PIN_a2)





#define rts_off output_high(PIN_c5)

#define rts_on output_low(PIN_c5)





#define pin_rx input(PIN_c7)



//Funciones

beep()

{

buzzer_on;

delay_ms(10);

buzzer_off;

delay_ms(10);

}



#INT_TIMER1

clock_isr() {

beep();

}



#int_rda

void serial_isr() {

char a;

a=getc();

printf("%C",a);

}







main()

{





//Variables locales del main





// Inicializo variables



// Definición de puertos 0=out 1=inp

set_tris_a (0b011011); //Define el puerto A

set_tris_b (0b11000000); //Define el puerto B

set_tris_c (0b10000000); //Define el puerto C



buzzer_off;



// habilito interrupciones

enable_interrupts(GLOBAL);

enable_interrupts(INT_RDA);



//Reset general

OUTPUT_B(0);

OUTPUT_C(0);



//Inicialización de pin de TX de RS232 en -12V

txon;





//Ciclo de SCAN

while (TRUE)

{



out1_on;

delay_ms(100);

out1_off;

delay_ms(100);



}

}
Ttelmah
Guest







Re: Strange behavior with timer1 and int_rda
PostPosted: Sun Jan 25, 2004 4:02 am     Reply with quote

allcontrol wrote:
The following code just read a character and send it back.
When I comment the int_timer1 function the program works OK.
If I comment out this routine so the compiler put it into the object code
the program doesn't work.

Any clue are welcome



//Configuración general

#device PIC16F876 ADC=10

#include <16F876.h>

//#include "modbus.h"

#define FREC_MHZ 4000000

#fuses XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP,NOCPD,WRT

#use delay(clock=FREC_MHZ)

#use rs232(baud=9600,parity=N, xmit=PIN_C6,rcv=PIN_C7,errors,bits=8)

#priority rda,timer1

#use fast_io(A)

#use fast_io(B)

#use fast_io(C)





#define txon output_high(PIN_c6)

#define out1_on output_high(PIN_b1)

#define out1_off output_low(PIN_b1)

#define buzzer_on output_high(PIN_a2)

#define buzzer_off output_low(PIN_a2)





#define rts_off output_high(PIN_c5)

#define rts_on output_low(PIN_c5)





#define pin_rx input(PIN_c7)



//Funciones

beep()

{

buzzer_on;

delay_ms(10);

buzzer_off;

delay_ms(10);

}



#INT_TIMER1

clock_isr() {

beep();

}



#int_rda

void serial_isr() {

char a;

a=getc();

printf("%C",a);

}







main()

{





//Variables locales del main





// Inicializo variables



// Definición de puertos 0=out 1=inp

set_tris_a (0b011011); //Define el puerto A

set_tris_b (0b11000000); //Define el puerto B

set_tris_c (0b10000000); //Define el puerto C



buzzer_off;



// habilito interrupciones

enable_interrupts(GLOBAL);

enable_interrupts(INT_RDA);



//Reset general

OUTPUT_B(0);

OUTPUT_C(0);



//Inicialización de pin de TX de RS232 en -12V

txon;





//Ciclo de SCAN

while (TRUE)

{



out1_on;

delay_ms(100);

out1_off;

delay_ms(100);



}

}

1) You have not included the code for 'clock_isr', so making any comment about what happens here is impossible.
2) General rule of thumb, is _keep interrupt handlers short_. The 'buzz' routine, is going to take at least 20mSec to execute, and also (since you then use msec delays both inside the ISR, and outside), implies that the interrupts will be disabled for large parts of the 'main' code. Use a 'toggle' variable instead, and turn the buzz on, the first time the routine is called, then off the next time, and don't use any 'delays' inside the interrupt handler.

Best Wishes
allcontrol



Joined: 17 Jan 2004
Posts: 3
Location: Mendoza, Argentina

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: Strange behavior with timer1 and int_rda
PostPosted: Sun Jan 25, 2004 9:41 am     Reply with quote

Clock_isr just play a beep, but I never enable it, just is the code.
When I comment it:

//#INT_TIMER1
//clock_isr() {
//beep();
//}

The program works OK.

I want to know why this happen.

Thanks
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

Int ISR problem
PostPosted: Sun Jan 25, 2004 11:52 am     Reply with quote

For exactly the reason he told you..

"don't use any 'delays' inside the interrupt handler"

Being in an interrupt handler that long is begging for problems! By their very nature ISRs MUST be short and quick to avoid timing issues....

If you follow his suggestion of setting a "beep" flag inside the ISR and controlling Beep in Main it should work fine.

Dave
allcontrol



Joined: 17 Jan 2004
Posts: 3
Location: Mendoza, Argentina

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: Int ISR problem
PostPosted: Mon Jan 26, 2004 10:41 am     Reply with quote

Bravo

I caught the idea.
I modify it and all runs like a charm.

Thanks a lot to all

Alejandro Laughing
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