View previous topic :: View next topic |
Author |
Message |
Micro_DSP
Joined: 28 Jun 2018 Posts: 3 Location: Kaacchi
|
dsPIC30F4013 Interrupt Issues |
Posted: Thu Jun 28, 2018 12:49 am |
|
|
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: 19552
|
|
Posted: Thu Jun 28, 2018 2:24 am |
|
|
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
|
Still having the same issues |
Posted: Thu Jun 28, 2018 4:56 am |
|
|
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
|
Toggle Led Test |
Posted: Thu Jun 28, 2018 5:06 am |
|
|
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: 357 Location: South Africa
|
|
Posted: Thu Jun 28, 2018 5:29 am |
|
|
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: 19552
|
|
Posted: Thu Jun 28, 2018 7:10 am |
|
|
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. |
|
|
|