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 CCS Technical Support

Problem using PCD compiler/dspic30f4013

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



Joined: 13 Jun 2012
Posts: 4

View user's profile Send private message

Problem using PCD compiler/dspic30f4013
PostPosted: Sat Aug 18, 2012 9:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Aug 20, 2012 12:00 pm     Reply with quote

there is no while loop, it runs once and goes to sleep
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon Aug 20, 2012 12:50 pm     Reply with quote

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
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