|
|
View previous topic :: View next topic |
Author |
Message |
smarandu
Joined: 13 Jun 2012 Posts: 4
|
Problem using PCD compiler/dspic30f4013 |
Posted: Sat Aug 18, 2012 9:26 am |
|
|
Hi all,
I am very new to programming including CCS programming.
I have written a program to capture 10kHz signal using IC1 rising edge and timer 2. The program compiles successfully but it does not print anything. I also assume it does not capture the signal.
Please help to sort out the problem. I am using DSPICDEM2 Development board.
I have tried the Capture example and gets the same results despite compiling successfully. My other simple rs232 program works well with the terminal window. The program is copied here below.
My advance thanks and appreciation.
Simon.
Code: |
#include <30f4013.h>
#fuses NOWDT, NOPROTECT
#use delay(crystal=7.37 Mhz)
#use rs232(baud=9600, UART1)
int16 Newcapture=0;
int16 FirstCapture=0;
int16 SecondCapture=0;
#int_IC1
void IC1_Interrupt(void)
{
unsigned int16 dummy;
if(!NewCapture)
{
FirstCapture = get_capture(1,FALSE); //Read first capture event.
SecondCapture = get_capture(1,FALSE); //Read second capture event.
NewCapture = TRUE;
}
else
{
dummy = get_capture(1,TRUE); //The TRUE causes the last capture event to
//be retrieved from the capture FIFO buffer
//and to clear out any previous captures.
//This is used to keep the FIFO buffer from
//overflowing while calculating and
//displaying the time. If an overflow
//occurs it will cause any further Input
//Capture interrupts form occuring.
}
}
unsigned int16 GetCaptureDifference(unsigned int16 first, unsigned int16 second)
{
return(second - first);
}
void main()
{
unsigned int16 Time;
unsigned int8 i = 0;
printf("\n\rRESET\n\n\r");
//The following sets up the Input Capture 1 unit to capture timer 2 on the
//rising edge, low to high, of the input signal, and to generate an
//interrupt on every second capture event.
SETUP_CAPTURE(1, CAPTURE_RE | INTERRUPT_SECOND_CAPTURE | CAPTURE_TIMER2);
setup_timer2(TMR_INTERNAL|TMR_DIV_BY_1,0xFF); //enable Timer 2
enable_interrupts(INT_IC1); //enable
enable_interrupts(INTR_GLOBAL);
if(NewCapture)
{
Time = GetCaptureDifference(FirstCapture, SecondCapture);
printf("\r\rPeriod: %8.1w microseconds",((unsigned int32)Time*64));
NewCapture = FALSE;
}
} |
|
|
|
drolleman
Joined: 03 Feb 2011 Posts: 116
|
|
Posted: Mon Aug 20, 2012 12:00 pm |
|
|
there is no while loop, it runs once and goes to sleep |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Aug 20, 2012 12:50 pm |
|
|
and, since 'NewCapture' won't be set for some time, nothing will print as the code runs through.
As a minor comment, make this an int1. Saves RAM, and much faster. A single bit is tested true/false, in one instruction. A 16bit variable, requires comparing two bytes. Probably about 6 instructions...
Best Wishes |
|
|
|
|
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
|