View previous topic :: View next topic |
Author |
Message |
erhane
Joined: 01 Jul 2014 Posts: 41
|
Undefined identifier --setup_timer_2 |
Posted: Thu Aug 28, 2014 1:00 am |
|
|
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
|
|
Posted: Thu Aug 28, 2014 1:13 am |
|
|
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: 19520
|
|
Posted: Thu Aug 28, 2014 2:24 am |
|
|
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.
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
|
|
Posted: Thu Aug 28, 2014 7:43 am |
|
|
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: 19520
|
|
Posted: Thu Aug 28, 2014 9:04 am |
|
|
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
|
|
Posted: Thu Aug 28, 2014 9:54 am |
|
|
thats brilliant.
thank you! |
|
|
|