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 support@ccsinfo.com

Undefined identifier --setup_timer_2

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



Joined: 01 Jul 2014
Posts: 41

View user's profile Send private message Send e-mail

Undefined identifier --setup_timer_2
PostPosted: Thu Aug 28, 2014 1:00 am     Reply with quote

Hello,

I am using dspic30f6015. Trying to enable timer2 interrupt but i am getting that error.

Is there anything that i am missing?
Code:

   enable_interrupts(INT_TIMER2);
   setup_timer_2(T2_DIV_BY_1,119,2);

I am using CCS C v5.008
erhane



Joined: 01 Jul 2014
Posts: 41

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 28, 2014 1:13 am     Reply with quote

i removed error with this changes from looking 30f6015.h file.
Code:

   enable_interrupts(INT_TIMER2);
   setup_timer2(TMR_DIV_BY_1,239);


But not sure. Can you enlighten me?

I am trying to get timer interrupt every 8us with clock=120000000

Thank You
Ttelmah



Joined: 11 Mar 2010
Posts: 19433

View user's profile Send private message

PostPosted: Thu Aug 28, 2014 2:24 am     Reply with quote

The first 'point' is that on the DsPIC's all the timers use the same prescalers. So instead of the 'timer specific' ones like 'T2_DIV_BY_1', the ones used with these chips are 'generic' to all the timers 'TMR_DIV_BY_1'. Hence the changes to the settings. Smile

Now, with your 120MHz master clock, the timer is fed off 30MHz. So needs to count to 30*8 = 240. You also need to tell it to use the internal clock though:
Code:

setup_timer2(TMR_DIV_BY_1 | TMR_INTERNAL, 239);


Be 'aware' though, this is every 240 instructions. Your handler needs to be kept very short, if you are not going to bottleneck....
erhane



Joined: 01 Jul 2014
Posts: 41

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 28, 2014 7:43 am     Reply with quote

Thank you for you answer
my interrupt cycle is:
Code:


#INT_TIMER2
void isr_timer2()
{
   if(ramp_on)
   {
      counter+=1;
      if(counter==periods[i])
      {
         counter=0;
         i+=1;
         output_high(STEP);
         delay_us(1);
         output_low(STEP);
      }
   }
   else if(steady)
   {
      counter+=1;
      if(counter==periods[i])
      {
         counter=0;
         output_high(STEP);
         delay_us(1);
         output_low(STEP);
      }
   }
   

}


how can i calculate whether 8us timer delay is enough or not?
Ttelmah



Joined: 11 Mar 2010
Posts: 19433

View user's profile Send private message

PostPosted: Thu Aug 28, 2014 9:04 am     Reply with quote

Handle the array differently
Copy the current in use value into a static variable when 'i' changes.
Code:

#INT_TIMER2
void isr_timer2()
{
   static time=1;
   if(ramp_on)
   {
      if(++counter==time)
      {
         output_high(STEP);
         counter=0;
         time=periods[++i];
         output_low(STEP);
      }
   }
   else if(steady)
   {
      if(++counter==time)
      {
         output_high(STEP);
         counter=0;
         delay_cycles(6);
         output_low(STEP);
      }
   }
}


This way the time needed to reset the counter, and access an array variable, are used as all/part of the time needed for the stepper pulse. The array is also only accessed when i changes.

This should save about 30% of the time in the routine. To find out, compile the same routine in a little 'wrapper' function, and use the stopwatch feature in MPLAB, to see how long it all takes.
erhane



Joined: 01 Jul 2014
Posts: 41

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 28, 2014 9:54 am     Reply with quote

thats brilliant.
thank you!
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