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

Need some info for Timer INT

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



Joined: 24 Nov 2010
Posts: 19

View user's profile Send private message

Need some info for Timer INT
PostPosted: Sun Jul 07, 2013 8:08 am     Reply with quote

I need following steps for a project. But I have some confusion regarding enabling and disabling the timer. Also I would like to know whether it can be done using one INT routine or I need two.

1. On external interrupt set the timer value and enable the timer
- set_timer1(xyz)?

2. On the timer interrupt - change the state for A1 (i.e. off <> on)
- not an issue.

3. Set the NEXT timer value and set a flag to mark NEXT timer interrupt
- here is the problem. do I need a 2nd INT (i.e. Timer0/2) or I have to just reload the Timer1 for next trigger?

4. On the NEXT timer interrupt - change the state for A2
- it depends on #3.

5. Reset the flag and disable the timer
- setup_timer_1(T1_DISABLED)? or set_timer1(0)?

6. Repeat step 1
- if the the Timer1 disabled in step-5 then how can it be enabled in setp-1?

Thanks in advance for your help.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sun Jul 07, 2013 9:43 am     Reply with quote

suggestion:
write some code
and see what happens.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Jul 07, 2013 9:52 am     Reply with quote

Seconded.

Mike
leaveme



Joined: 24 Nov 2010
Posts: 19

View user's profile Send private message

PostPosted: Sun Jul 07, 2013 10:10 am     Reply with quote

Actually I would like to know if a timer can be enabled/disabled in a INT ISR call-
setup_timer_1(T1_DISABLED)
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Jul 07, 2013 10:36 am     Reply with quote

leaveme wrote:
Actually I would like to know if a timer can be enabled/disabled in a INT ISR call-
setup_timer_1(T1_DISABLED)


Yes, you can, but that's not what you asked initially.

The regulars here want to see some sign of effort from posters.
That's why we asked to see some code.
It gives us a better idea of what you're trying to do, and how to help.
We also then get some indication of your ability and experience.

Mike
leaveme



Joined: 24 Nov 2010
Posts: 19

View user's profile Send private message

PostPosted: Sun Jul 07, 2013 11:55 am     Reply with quote

Thanks Mike.

Code:

#include <16F767.h>

#fuses HS
#FUSES NOMCLR
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT

#use delay(int=8000000)         //Use 8MHz Internal OSC

int16 value1=61035;
int16 value2=46514;
int1 step=0;

#int_EXT
void  EXT_isr(void)
{   
   step=1;
   //Timer1 need to be enabled here
   //since it is disabled.
   //Can't find the correct function
   set_timer1(value1);    //Reload Timer1 for 1st step
}

#int_TIMER1
void  TIMER1_isr(void)
{
   if(step==1) {
      output_toggle(PIN_B2);
      set_timer1(value2);    //Reload Timer1 for 2nd step
      step=0;
   } else {
      output_toggle(PIN_B3);
      step=1;
      setup_timer_1(T1_DISABLED);
   }
}

void main()
{

   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);


   clear_interrupt(INT_EXT); 
   ext_int_edge(H_TO_L);           //set the falling edge

   enable_interrupts(INT_EXT);     //EXT INT
   enable_interrupts(INT_TIMER1);  //TIMER1 INT
   enable_interrupts(GLOBAL);

   while(TRUE)
   {

   }
}


I need exactly what I pointed in 1st post.
Ttelmah



Joined: 11 Mar 2010
Posts: 19516

View user's profile Send private message

PostPosted: Sun Jul 07, 2013 1:22 pm     Reply with quote

Comments inline:
Code:

#include <16F767.h>

//#fuses HS This enables the _external_ oscillator
#FUSES NOMCLR
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
//Only one oscillator fuse should ever be selected....

#use delay(int=8000000)         //Use 8MHz Internal OSC

int16 value1=61035;
int16 value2=46514;
int1 step=0;

#int_EXT
void  EXT_isr(void)
{   
   step=1;
   set_timer1(value1);    //Reload Timer1 for 1st step
   clear_interrupts(INT_TIMER1); //must clear since it may be set
   enable_interrupts(INT_TIMER1); //enable
}

#int_TIMER1
void  TIMER1_isr(void)
{
   if(step==1) {
      output_toggle(PIN_B2);
      set_timer1(value2);    //Reload Timer1 for 2nd step
      step=0;
   } else {
      output_toggle(PIN_B3);
      step=1;
      disable_interrupts(INT_TIMER1); //disable
   }
}

void main()
{

   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);

   ext_int_edge(H_TO_L);           //set the falling edge
   clear_interrupt(INT_EXT); //This needs to be _after_ changing the edge

   enable_interrupts(INT_EXT);     //EXT INT
   //enable_interrupts(INT_TIMER1);  //TIMER1 INT - you don't want
   //this enabled - yet
   enable_interrupts(GLOBAL);

   while(TRUE)
   {

   }
}


Note where I clear the interrupts. After the edge is set (read the data sheet), and after setting the timeout value, since it may have already triggered with the interrupt disabled.

Best Wishes
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