CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

timer1 and rda interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

timer1 and rda interrupt
PostPosted: Sun Sep 08, 2013 2:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Sep 08, 2013 4:08 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 09, 2013 2:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 09, 2013 9:23 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 09, 2013 2:53 pm     Reply with quote

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).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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