View previous topic :: View next topic |
Author |
Message |
guest Guest
|
doubt |
Posted: Tue Feb 15, 2005 4:09 pm |
|
|
Hi everyone,
I have a small doubt. I am enabling a timer in PIC that interrupts every 15ms. I have a subroutine, that has a delay statement with delay of 20ms. I would like to know, whether timer interrupts in between the delay statements or not. I believe that delay statements are just NOP commands in Assembly and timer would interrupt in between them, if it overflows. Please post any comments and corrections if I am wrong.
sk |
|
![](templates/subSilver/images/spacer.gif) |
flip
Joined: 15 Feb 2005 Posts: 11
|
doubt |
Posted: Tue Feb 15, 2005 4:16 pm |
|
|
Yes. the timer interrupts when the program is in the delay subroutine. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
flip
Joined: 15 Feb 2005 Posts: 11
|
Timer0 interrupt |
Posted: Tue Feb 15, 2005 5:21 pm |
|
|
I cant get my timer0 interrupt to work do you know what the problem is ?
Code: |
#include <18F458.h> //up/down counter with 3 7 segment displays no max or min
#use delay(clock=20000000)
#fuses HS, OSCSEN, BROWNOUT, BORV20, STVREN, DEBUG, LVP
int t = 0;
#int_TIMER0 // interrupt occurs every 3.2micro sec * 256 = 819.12 micro seconds
TIMER0_isr()
{
if (t++ == 244) // After t gets up to 2441 , 2 seconds has lapsed 819.12 micro seconds * 2442 = 2 seconds
{
t = 0;
output_c(0x03); // output a light every 2 seconds
delay_ms(100);
}
}
void main()
{
set_tris_d(0xFF);
set_tris_a(0xFF);
set_tris_b(0xFF);
set_tris_c(0xFF);
set_tris_e(0xFF);
setup_counters(RTCC_INTERNAL, RTCC_DIV_32); //pulse occurs every 3.2 micro seconds (1/(40MHz/4*32))
enable_interrupts(INT_TIMER0);
enable_interrupts(global);
while(1)
{
output_c(0x01);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
flip
Joined: 15 Feb 2005 Posts: 11
|
Timer0 interrupt |
Posted: Tue Feb 15, 2005 5:22 pm |
|
|
I cant get my timer0 interrupt to work do you know what the problem is ?
Code: |
#include <18F458.h> //up/down counter with 3 7 segment displays no max or min
#use delay(clock=20000000)
#fuses HS, OSCSEN, BROWNOUT, BORV20, STVREN, DEBUG, LVP
int t = 0;
#int_TIMER0 // interrupt occurs every 3.2micro sec * 256 = 819.12 micro seconds
TIMER0_isr()
{
if (t++ == 244) // After t gets up to 2441 , 2 seconds has lapsed 819.12 micro seconds * 2442 = 2 seconds
{
t = 0;
output_c(0x03); // output a light every 2 seconds
delay_ms(100);
}
}
void main()
{
set_tris_d(0xFF);
set_tris_a(0xFF);
set_tris_b(0xFF);
set_tris_c(0xFF);
set_tris_e(0xFF);
setup_counters(RTCC_INTERNAL, RTCC_DIV_32); //pulse occurs every 3.2 micro seconds (1/(40MHz/4*32))
enable_interrupts(INT_TIMER0);
enable_interrupts(global);
while(1)
{
output_c(0x01);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Feb 15, 2005 9:11 pm |
|
|
Rember that any function you call from an isr and from the main program will have interrupts disabled. This includes the delay_ms() routine. |
|
![](templates/subSilver/images/spacer.gif) |
bluetooth
Joined: 08 Jan 2005 Posts: 74
|
|
Posted: Wed Feb 16, 2005 8:19 am |
|
|
Even though fast_io is not specified, I wonder why all the TRIS's are being set to 0xff - makes generating an output really tough....
Microchip DDR = ~Motorola DDR!
My $0.02.... |
|
![](templates/subSilver/images/spacer.gif) |
|