View previous topic :: View next topic |
Author |
Message |
Mahdi
Joined: 21 Aug 2012 Posts: 47
|
timer1 and rda interrupt |
Posted: Sun Sep 08, 2013 2:44 pm |
|
|
hi buddies.
I want to use rda interrupt for receive uart and timer1 interrupt.
In timer interrupt i use math.c and Math calculations and it have 1.5 ms delay.
My question is how to disable rda interrupt when timer1 overflow start and when the Calculations in timer1 Finished the rda interrupt active and receive correct data?
This is my code but its not work
Code: |
#include <33FJ32GP204.h>
#fuses pr
#fuses ec
#use delay(clock=40MHz)
#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7
#use rs232(UART1, baud=9600, errors)
#INT_TIMER1
void timer1_isr(void)
{
disable_interrupts(INT_RDA);
// for example math loaded and 1.5 ms delay
enable_interrupts(INT_RDA);
}
#include <LCD.C>
int8 c;
#INT_RDA
void rda_isr(void)
{
if(kbhit()){
c=getc();}
}
void main()
{
setup_timer1(TMR_INTERNAL | TMR_DIV_BY_64, 1562); // 5 ms overflow
lcd_init();
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_RDA);
enable_interrupts(INTR_GLOBAL);
} |
v4.130 |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1349
|
|
Posted: Sun Sep 08, 2013 4:08 pm |
|
|
By default interrupt nesting is turned off by the compiler (see the LST file generated and look under main() ). You don't need to disable interrupts in another interrupt while that is true since all interrupts are disabled while in another interrupt with nesting disabled.
However, you shouldn't be doing heavy math calculations in an interrupt either. Use a flag and poll the flag in main and do the math there.
you need a while(TRUE){} at the end of your main or the code will just put the chip to sleep and reset when it wakes up. |
|
|
Mahdi
Joined: 21 Aug 2012 Posts: 47
|
|
Posted: Mon Sep 09, 2013 2:06 am |
|
|
jeremiah wrote: | By default interrupt nesting is turned off by the compiler (see the LST file generated and look under main() ). You don't need to disable interrupts in another interrupt while that is true since all interrupts are disabled while in another interrupt with nesting disabled.
However, you shouldn't be doing heavy math calculations in an interrupt either. Use a flag and poll the flag in main and do the math there.
you need a while(TRUE){} at the end of your main or the code will just put the chip to sleep and reset when it wakes up. |
i want to calculate angular velocity with timer That is accurate.
Your aim is that until one interrupt is active other interrupt is disabled? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Sep 09, 2013 9:23 am |
|
|
The timer signals that the timer has wrapped. So 'record' the values that need to be recorded at this moment, set a flag and exit.
There is never any really good reason to do more in an interrupt, that handle the event it signals.
In the main, just have the loop testing the flag. When it goes true, take the recorded readings, and do the maths.
Even with multiple 'layers' of interrupts enabled, pausing at one level will almost always cause problems. You need to record the values, 'anyway', otherwise the time taken by the arithmetic, with parts of some numbers changing during the sums, will give invalid results...
Best Wishes |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1349
|
|
Posted: Mon Sep 09, 2013 2:53 pm |
|
|
Mahdi wrote: |
Your aim is that until one interrupt is active other interrupt is disabled? |
When interrupt nesting is disabled (The default for the PCD compiler), while in one interrupt handler, all other interrupt handlers are disabled. When you leave the current interrupt handler, any other interrupt handlers that were disabled but had an event will trigger in sequence (again one at a time, but not at the same time). |
|
|
|