|
|
View previous topic :: View next topic |
Author |
Message |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
Interrupt flags clear in C |
Posted: Sun Feb 12, 2006 3:26 am |
|
|
Hi all
How can I clear interrupt flags in C
I check in the help and in 16F876A heade file and I do't find anything
on the subject.
I am new with C, working many years with PIC assembler.
Joseph Gross |
|
|
Ttelmah Guest
|
|
Posted: Sun Feb 12, 2006 3:31 am |
|
|
clear_interrupt(INT_XXX);
This was added about a year ago, but is not in the printed manual, or the version that comes as the 'help' file. I think it is in the latest downloadable .pdf.
Have a look at 'readme.txt', in your compiler's install directory. It contains details of many such changes, and is an essential 'addendum' to the manual.
Best Wishes |
|
|
vanderlei.vg
Joined: 18 Aug 2014 Posts: 5
|
clear_interrupt |
Posted: Tue Aug 19, 2014 8:25 pm |
|
|
I tryed to "clear_interrupt(INT_TMR2)" inside the ISR but it seems doesnt work.
I have a PCM version 4.3.0.285
Fragment of the (ISR) program:
Code: | #INT_TIMER2 //Diretiva de identificação da interrupção do timer 0
void TIMER2 (void) //Função de tratamento da interrupção externa
{
output_low(BICO2);
clear_interrupt(int_timer2);
disable_Interrupts(INT_TIMER2);
}
|
I need to have the INT_TIMER2 cleared and disable when the ISR is finished.
As the clear doesnt works inside the ISR so I "clear" outside the ISR.
I want to know if it is possible to make a clear inside the ISR?
If yes, what is my mistake?
thanks,
Vandelei |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 19, 2014 8:46 pm |
|
|
The compiler automatically clears the interrupt with hidden code.
That's not the problem. To help us find the problem, please
answer the following questions:
1. What is your PIC ?
2. Post your setup_timer_2() function statement, showing all the parameters.
3. What is the oscillator frequency of your PIC ? Post your #use delay()
statement.
4. What is your compiler version. It's not 4.3.0.285. It's a 4-digit number
given at the top of the .LST file. The .LST file will be in your project
directory after a successful compilation. It will be a number such as
4.068, or 4.106, or 4.141, etc.
5. If possible, post a small, complete program that demonstrates the
problem. |
|
|
vanderlei.vg
Joined: 18 Aug 2014 Posts: 5
|
|
Posted: Tue Aug 19, 2014 8:56 pm |
|
|
Ops!! CCS PCM C Compiler, Version 4.109, 53252 18-ago-14 18:08
Please take in account that this is my first program in C.
Code: | #include<16F1939.h>
#device ADC = 8 //Define 8 bits para o resultado da conversão AD
#use delay (clock = 8M)
#fuses HS, NOWDT, PUT, BROWNOUT, NOLVP, NOIESO, NOVCAP, NOFCMEN, NOCLKOUT, PLL_SW
#use fast_io(A)
#use fast_io(B)
#use fast_io(D)
int ad0; //Variável para armazenamento da conversão
short int PROXIMO=0;
/* ENTRADAS */
#define RPM_CLOCK PIN_B0
#define TINJ_POT PIN_A0
/* SAÍDAS */
#define BICO1 PIN_D0
#define BICO2 PIN_D1
#define BICO3 PIN_D2
#define BICO4 PIN_D3
#define IGN14 PIN_D4
#define IGN23 PIN_D5
#define RESULTADO_ADC PIN_D6
/* ......................................................... INTERRUPÇÕES */
#INT_EXT
void noventa_graus ()
{
PROXIMO=1;
//SET_ADC_CHANNEL(0); //Configura o canal de leitura 0
delay_us(300); //Tempo de ajuste do canal (necessário)
ad0 = READ_ADC(); //Faz a conversão AD e a salva na variável ad0
}
#INT_TIMER0 //Diretiva de identificação da interrupção do timer 0
void TIMER0 (void) //Função de tratamento da interrupção externa
{
output_low(BICO1);
clear_interrupt(int_timer0);
disable_Interrupts(INT_TIMER0);
}
#INT_TIMER1 //Diretiva de identificação da interrupção do Timer 1
void TIMER1 (void) //Função de tratamento da interrupção externa
{
disable_interrupts(INT_TIMER1); //Desabilita interrupção do Timer 1
output_low(IGN23);
output_low(IGN14);
clear_interrupt(INT_TIMER1);
set_timer1(61536); /*Retorna o valor inicial aos registradores TMR1H e TMR1L*/
clear_interrupt(INT_TIMER1);
}
#INT_TIMER2 //Diretiva de identificação da interrupção do timer 2
void TIMER2 (void) //Função de tratamento da interrupção externa
{
output_low(BICO2);
clear_interrupt(int_timer2);
disable_Interrupts(INT_TIMER2);
}
#INT_TIMER4 //Diretiva de identificação da interrupção do timer 4
void TIMER4 (void) //Função de tratamento da interrupção externa
{
output_low(BICO4);
clear_interrupt(int_timer4);
disable_Interrupts(INT_TIMER4);
}
#INT_TIMER6 //Diretiva de identificação da interrupção do timer 6
void TIMER6 (void) //Função de tratamento da interrupção externa
{
output_low(BICO3);
clear_interrupt(int_timer6);
disable_Interrupts(INT_TIMER6);
}
/* ......................................................... MAIN */
void main()
{
Set_Tris_A(0b00000001);
Set_Tris_B(0b00000001);
Set_tris_D(0b00000000);
output_D(0b00000000); //Coloca em 0 toda a porta D
SETUP_ADC_PORTS(sAN0); //Configura a entrada analógica AN0
/*Configura o a frequência do oscilador para o conversor A/D em fosc/8 (TAD = 1uS)*/
SETUP_ADC(ADC_CLOCK_DIV_8);
SET_ADC_CHANNEL(0); //Configura o canal de leitura 0
/* Configura o Timer 0 para contagem interna e prescaler de 1:256 */
SETUP_TIMER_0(RTCC_INTERNAL | RTCC_DIV_256);
set_timer0(20); //Inicializa o registrador TMR0 = 20 vai gerar cutoff
/* Configura o Timer 1 para contagem interna e prescaler de 1:1 */
SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_1);
SET_TIMER1(61536); //Inicializa os registradores TMR1H e TMR1E
/* Configura o Timer 2 prescaler de 1:16 post 1:16 */
SETUP_TIMER_2(T2_DIV_BY_16, ad0, 16);
//SET_TIMER1(20); //
/* Configura o Timer 4 prescaler de 1:16 post 1:16 */
SETUP_TIMER_4(T4_DIV_BY_16, ad0, 16);
//SET_TIMER1(20); //
/* Configura o Timer 6 prescaler de 1:16 post 1:16 */
SETUP_TIMER_6(T6_DIV_BY_16, ad0, 16);
//SET_TIMER1(20); //
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
ext_int_edge(0,L_TO_H);
delay_ms(300);
PROXIMO=0;
/* Processo para sincronização com o sinal de RPM_CLOCK*/
while(!(PROXIMO)); //Fica aqui enquanto PROXIMO = 0
delay_us(30);
PROXIMO=0;
while(true)
{
/* 1º Pulso , giro 1 , 0-720 Graus (360 graus do giro 2) , BICO 1 */
while(!(PROXIMO)); //Fica aqui enquanto PROXIMO = 0
if (ad0<25)
{
output_high(RESULTADO_ADC);
output_low(BICO1);
}
else
{
ad0=ad0-25;
ad0=253-ad0;
output_high(BICO1);
output_low(RESULTADO_ADC);
clear_interrupt(INT_TIMER0);
set_timer0(ad0);
enable_interrupts(INT_TIMER0); //Habilita interrupção do Timer 0
}
PROXIMO=0;
/* 2º Pulso , giro 1, 90 Graus, IGN-23 */
while(!(PROXIMO)); //Fica aqui enquanto PROXIMO = 0
output_high(IGN23);
clear_interrupt(INT_TIMER2);
disable_Interrupts(INT_TIMER2);
output_low(BICO2);
clear_interrupt(INT_TIMER1);
set_timer1(61536);
enable_interrupts(INT_TIMER1); //Habilita interrupção do Timer 1
PROXIMO=0;
/* 3º Pulso , giro 1, 180 Grau, BICO 3 */
while(!(PROXIMO)); //Fica aqui enquanto PROXIMO = 0
if (ad0<25)
{
output_high(RESULTADO_ADC);
output_low(BICO3);
}
else
{
ad0=ad0-22;
output_low(RESULTADO_ADC);
output_high(BICO3);
clear_interrupt(INT_TIMER6);
SETUP_TIMER_6(T6_DIV_BY_16, ad0, 16);
enable_interrupts(INT_TIMER6); //Habilita interrupção do Timer 6
}
PROXIMO=0;
/* 4º Pulso , giro 1, 270 Graus, IGN-14 */
while(!(PROXIMO)); //Fica aqui enquanto PROXIMO = 0
output_high(IGN14);
clear_interrupt(INT_TIMER0);
disable_Interrupts(INT_TIMER0);
output_low(BICO1);
clear_interrupt(INT_TIMER1);
set_timer1(61536);
enable_interrupts(INT_TIMER1); //Habilita interrupção do Timer 1
PROXIMO=0;
/* 5º Pulso , giro 2, 360 Graus (0 Grau) BICO 4 */
while(!(PROXIMO)); //Fica aqui enquanto PROXIMO = 0
if (ad0<25)
{
output_high(RESULTADO_ADC);
output_low(BICO4);
}
else
{
ad0=ad0-22;
output_high(BICO4);
output_low(RESULTADO_ADC);
clear_interrupt(INT_TIMER4);
SETUP_TIMER_4(T4_DIV_BY_16, ad0, 16);
enable_interrupts(INT_TIMER4); //Habilita interrupção do Timer 4
}
PROXIMO=0;
/* 6º Pulso , giro 2, 450 Graus (90 Graus) IGN-23 */
while(!(PROXIMO)); //Fica aqui enquanto PROXIMO = 0
output_high(IGN23);
clear_interrupt(INT_TIMER6);
disable_Interrupts(INT_TIMER6);
output_low(BICO3);
clear_interrupt(INT_TIMER1);
set_timer1(61536);
enable_interrupts(INT_TIMER1); //Habilita interrupção do Timer 1
PROXIMO=0;
/* 7º Pulso , giro 2, 540 Graus (180 Graus) BICO 2 */
while(!(PROXIMO)); //Fica aqui enquanto PROXIMO = 0
if (ad0<25)
{
output_high(RESULTADO_ADC);
output_low(BICO2);
}
else
{
ad0=ad0-22;
output_low(RESULTADO_ADC);
output_high(BICO2);
clear_interrupt(INT_TIMER2);
SETUP_TIMER_2(T2_DIV_BY_16, ad0, 16);
enable_interrupts(INT_TIMER2); //Habilita interrupção do Timer 2
}
PROXIMO=0;
/* 8º Pulso , giro2, 630 Graus (270 Graus) IGN-14 */
while(!(PROXIMO)); //Fica aqui enquanto PROXIMO = 0
output_high(IGN14);
clear_interrupt(INT_TIMER4);
disable_Interrupts(INT_TIMER4);
output_low(BICO4);
clear_interrupt(INT_TIMER1);
set_timer1(61536);
enable_interrupts(INT_TIMER1); //Habilita interrupção do Timer 1
PROXIMO=0;
}
} |
Vanderlei |
|
|
vanderlei.vg
Joined: 18 Aug 2014 Posts: 5
|
|
Posted: Tue Aug 19, 2014 9:38 pm |
|
|
More infos:
1) The signal on PIN_B0 is a squarewave, freq. 10 up to 450Hz
2) The outputs have leds.
Vanderlei |
|
|
vanderlei.vg
Joined: 18 Aug 2014 Posts: 5
|
|
Posted: Sun Aug 24, 2014 9:17 am |
|
|
Hi,
do you have any orientation about my doubts?
thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 24, 2014 9:54 am |
|
|
The reason you are not getting any replies is:
We don't want to look at a program with 5 timer interrupts running at the
same time. We would not write a program that way.
Instead, we would have one timer interrupt, and then have a state
machine inside the interrupt code, and the state machine code would
produce all the pulses. |
|
|
|
|
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
|