|
|
View previous topic :: View next topic |
Author |
Message |
prach Guest
|
2 interrupts in same program is not work |
Posted: Tue Mar 16, 2004 10:52 pm |
|
|
hi all, sorry for my enlish.
i want to use a counting press button in setting up time, but when i use 2 interrupts ( rtcc,rb ) in program, interrupts rtcc is not work, can you help me this problem.
thank you.
code c pcwh 1.80
Code: |
#include <16f628A.h>
#fuses XT,NOWDT,NOPROTECT,PUT
#use delay(clock=4000000)
#include "lcd.c"
#define INTS_PER_SECOND 61 // (4000000/(4*64*256))
#byte port_b=0x06
#priority rtcc,rb
BYTE int_count; // Number of interrupts left before a second has elapsed
BYTE last_b;
int time_dec,time_sel,start_mode,free,save_time;
long int time_inc,value,seconds;
process_count(){
value=0;
wait_1:
//----- Debounce switch ---------------------
if(!input(pin_b0)){
++value;
chk_button:
if(!input(pin_bo)){
goto chk_button;
}
//-------------------------------------------
if(seconds==0){
goto exit;
}
lcd_gotoxy(3,1);
printf(lcd_putc,"%lu seconds ",seconds);
lcd_gotoxy(3,2);
printf(lcd_putc,"%lu value ",value);
goto wait_1;
exit:
delay_ms(100);
}
//---- RB Interrupts -----------------------------------------------------
#int_rb
rb_isr ( ) {
byte changes;
changes = last_b ^ port_b;
last_b = port_b;
disable_interrupts(int_rb);
if (bit_test(changes,5 )&& !bit_test(last_b,5)){
//b5 went low
}
if (bit_test(changes,6)&& !bit_test (last_b,6)){
//b6 went low
seconds=30; //set time 30 seconds
process_count();
delay_ms(500);
}
if (bit_test(changes,7)&& !bit_test (last_b,7)){
//b7 went low
}
delay_ms(100); //debounce
enable_interrupts(int_rb);
}
//---- Timer 0 interrupts ------------------------------------------------
#int_rtcc // This function is called every time
void clock_isr() { // the RTCC (timer0) overflows (255->0).
if(--int_count==0) { // per second.
--seconds;
int_count=INTS_PER_SECOND;
}
}
//----- Main --------------------------------------------------------------
void main() {
int_count=INTS_PER_SECOND;
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_64 );
enable_interrupts(INT_RTCC);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
lcd_init();
delay_ms(6);
do {
lcd_gotoxy(1,1);
printf(lcd_putc,"Counter.");
lcd_gotoxy(2,2);
printf(lcd_putc,"%lu second ",seconds);
} while (TRUE);
}
|
|
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Tue Mar 16, 2004 11:37 pm |
|
|
I would suggest you not use delays within interupts.
There are better ways to debounce an input. |
|
|
edi
Joined: 22 Dec 2003 Posts: 82
|
|
Posted: Tue Mar 16, 2004 11:43 pm |
|
|
Netone,
What is your suggest for better debounce an input? |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Tue Mar 16, 2004 11:53 pm |
|
|
edi wrote: | Netone,
What is your suggest for better debounce an input? |
This is what I do.
Code: |
if(PIN_PWR_MON) // Test the inputs status at this time
{ if(bit_test(++debounce_counter_PWR_MON,CounterSize)) // Aproach and test for true status
{ --debounce_counter_PWR_MON; // Remove counter overflow state
PWR_Mon_Alarm=1; // Set true status
} // Make adjustments to the tested bit
} // to change the counter size
else // The input was false
{ if(--debounce_counter_PWR_MON==0) // Aproach and test for false status
{ ++debounce_counter_PWR_MON; // Remove counter from zero state
PWR_Mon_Alarm=0; // Set false status
}
}
|
It compiles very small and runs fast. I just include a lot of these in a routine to service all the inputs and call it frequently. It takes several samples before settings the input variable bit and rejects noise very well. |
|
|
prach Guest
|
|
Posted: Wed Mar 17, 2004 1:32 am |
|
|
i think delay in interrupts is not effect to interrupts rtcc, because i use delay wait before exit. |
|
|
edi
Joined: 22 Dec 2003 Posts: 82
|
|
Posted: Wed Mar 17, 2004 8:16 am |
|
|
Newtone,
Can you please explain your debouncer it's too profesional C code.
What are the variables size? |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Wed Mar 17, 2004 9:55 am |
|
|
edi wrote: | Newtone,
Can you please explain your debouncer it's too profesional C code.
What are the variables size? |
In the following
PIN_PWR_MON is an int1 #bit mapped to an input pin
debounce_counter_PWR_MON is an int8
CounterSize is a constant int8 that specifies how many passes are required to make the change from high to low. It is the power of 2 between 2 and 7. For example 4 would make the counter count between 0 and 7. 5 would make the counter count between 0 and 15.
PWR_Mon_Alarm is an int1 that is the debounced global variable used in other functions to act on the input.
I call this function ever mS to debounce many inputs. In another function I also call every mS, when I detect a change in the state of PWR_Mon_Alarm from 0 to 1, I know it's time to save to EEPROM before the charge on an input capacitor is lost. Doing this allows many task to run concurrently instead of consecutively.
Code: |
if(PIN_PWR_MON) // Test the inputs status at this time
{ if(bit_test(++debounce_counter_PWR_MON,CounterSize)) // Aproach and test for true status
{ --debounce_counter_PWR_MON; // Remove counter overflow state
PWR_Mon_Alarm=1; // Set true status
} // Make adjustments to the tested bit
}
else // The input was false
{ if(--debounce_counter_PWR_MON==0) // Aproach and test for false status
{ ++debounce_counter_PWR_MON; // Remove counter from zero state
PWR_Mon_Alarm=0; // Set false status
}
}
|
|
|
|
|
|
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
|