![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
allcontrol
Joined: 17 Jan 2004 Posts: 3 Location: Mendoza, Argentina
|
Strange behavior with timer1 and int_rda |
Posted: Sat Jan 24, 2004 8:15 pm |
|
|
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);
}
} |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: Strange behavior with timer1 and int_rda |
Posted: Sun Jan 25, 2004 4:02 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
allcontrol
Joined: 17 Jan 2004 Posts: 3 Location: Mendoza, Argentina
|
Re: Strange behavior with timer1 and int_rda |
Posted: Sun Jan 25, 2004 9:41 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
Int ISR problem |
Posted: Sun Jan 25, 2004 11:52 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
allcontrol
Joined: 17 Jan 2004 Posts: 3 Location: Mendoza, Argentina
|
Re: Int ISR problem |
Posted: Mon Jan 26, 2004 10:41 am |
|
|
Bravo
I caught the idea.
I modify it and all runs like a charm.
Thanks a lot to all
Alejandro ![Laughing](images/smiles/icon_lol.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|