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

dsPIC30F4013 Interrupt Issues

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



Joined: 28 Jun 2018
Posts: 3
Location: Kaacchi

View user's profile Send private message

dsPIC30F4013 Interrupt Issues
PostPosted: Thu Jun 28, 2018 12:49 am     Reply with quote

I need help regarding interrupts in dsPic30F4013. I have written this code below for an interrupt toggling at 500ms but I am getting toggle output at 1.01 sec. Means that the interrupt i am getting is at 1.01 sec instead of 500ms. Can anyone help me in this issue please.
Code:

#include <30F4013.h>
#fuses FRC_PLL16, NOWDT 
#use delay(clock=7.5M)
#define x 58594            // Frequency variable define13 - Eqn 13-1 datasheet


#INT_TIMER2 //
void  TIMER2_isr(void)

   CLEAR_INTERRUPT(INT_TIMER2);
   OUTPUT_TOGGLE(PIN_D3);
   
   }
   
   
}


void main()
 {
    setup_compare(3,COMPARE_PWM | COMPARE_TIMER2);// This is to generate pwm in future
    setup_timer2(TMR_DISABLED);
    setup_timer2(TMR_INTERNAL|TMR_DIV_BY_1,x);
    CLEAR_INTERRUPT(INT_TIMER2);
    enable_interrupts(INT_TIMER2);
    enable_interrupts(INTR_GLOBAL);
     
      while (TRUE)
      {     
         }   
 }
 
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Jun 28, 2018 2:24 am     Reply with quote

Er.

Your figures are screwed by a huge factor. You should be getting a 250Hz output, not a 1/second output....

Your 'clock' is 117.92Mhz, not '7.5M'. You are running off the Frc oscillator at 7.37Mhz, with a 16*PLL. The CCS clock statement requires the actual CPU oscillator frequency.

Remember if an output 'toggles' at an interval, the frequency of the output will be half this.

Code:

#include <30F4013.h>
#fuses FRC_PLL16, NOWDT
#use delay(INTERNAL=117.92MHz)


Your interrupt should be 503* per second

117.92E6 / (4*58595) = 503.1

Every 1.98mSec.

If this is not what you are seeing, then you need to start by the old favorite, of testing what your actual clock rate 'is'. The classic 'toggle an LED' test.

There is the question of whether your chip is rated to run to 30MIPS. Requires the 30F4013-30, and even with this it requires 5v to run to this rate (only rated to 15MIPS at 3.3v)
Micro_DSP



Joined: 28 Jun 2018
Posts: 3
Location: Kaacchi

View user's profile Send private message

Still having the same issues
PostPosted: Thu Jun 28, 2018 4:56 am     Reply with quote

I am still having the same issues instead of the changes. I am still getting 1.015 sec toggle.
I have attached the code and the oscilloscope results.

Code:

#include <30F4013.h>
#fuses FRC_PLL16, NOWDT
#use delay(INTERNAL=117.92MHz)
#define x 58594     // Eqn 13-1 datasheet


#INT_TIMER2 // ISR after 500msec
void  TIMER2_isr(void)

   CLEAR_INTERRUPT(INT_TIMER2);
   OUTPUT_TOGGLE(PIN_B9);
}
void main()
 {
     
    setup_timer2(TMR_DISABLED);
    setup_timer2(TMR_INTERNAL|TMR_DIV_BY_256,x);
    CLEAR_INTERRUPT(INT_TIMER2);
    enable_interrupts(INT_TIMER2);
    enable_interrupts(INTR_GLOBAL);
     
      while (TRUE)
      {     
         }   
 }

 


https://www.dropbox.com/s/ybp3z3i3abggmeb/scope.png?dl=0
Micro_DSP



Joined: 28 Jun 2018
Posts: 3
Location: Kaacchi

View user's profile Send private message

Toggle Led Test
PostPosted: Thu Jun 28, 2018 5:06 am     Reply with quote

The Simple Toggle Led Test is giving me output at 274 nsec (3.663 MHz). But the calculation says that it must be 33.33nsec.

The code i used is stated below:

Code:

#include <30F4013.h>
#fuses FRC_PLL16, NOWDT
#use delay(INTERNAL=117MHz)


void main()
 {
     
      while (TRUE)
      {   
      OUTPUT_TOGGLE(PIN_B9);
         }   
 }
 
alan



Joined: 12 Nov 2012
Posts: 349
Location: South Africa

View user's profile Send private message

PostPosted: Thu Jun 28, 2018 5:29 am     Reply with quote

If you mean your period are 274ns and about 136ns per half cycle then what you are measuring are correct.
Take a look at the asm generated to see why 1 statement in C are not 1 statement in asm.

Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Jun 28, 2018 7:10 am     Reply with quote

For the simple test you should be including a delay in the loop. This allows you to test that the compiler 'knows' how fast you are running.
A jump takes two instruction times, a simple output two more. You are running at 117.92MHz. 29.48MIPS.
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