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

dspic33fj input capture

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



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

dspic33fj input capture
PostPosted: Tue Mar 31, 2015 8:38 am     Reply with quote

hi buddies

i want to measure duty cycle and freq of pwm signal with 1khz freq with input capture.

my code :

Code:
#include <33FJ256MC710.h>
#use delay(internal=7.37m)
#include <lcd.c>
void main()
{
lcd_init();
setup_timer3(TMR_INTERNAL | TMR_DIV_BY_8);
setup_capture(3, CAPTURE_FE | CAPTURE_TIMER3);
int16 p=0;
   while(TRUE)
   {

p = get_capture(3,TRUE);
lcd_gotoxy(1,1);
printf(lcd_putc,"%lu",p);

   }}


but i have random number on lcd
iam for first to use input capture
can any one help me?
(excuse for poor english)
thank you
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Tue Mar 31, 2015 9:18 am     Reply with quote

You have your input signal on pin70?. IC3.
Since you are using capture unit 3, this is where the input has to be.

You really should test for the capture event having happened:
Code:

   if (interrupt_active(INT_IC3))
   {
       //This says an event has happened

       //read the captured value, and clear the interrupt
       p = get_capture(3,TRUE);
       clear_interrupts(INT_IC3);
   }
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Tue Mar 31, 2015 10:06 am     Reply with quote

Ttelmah wrote:
You have your input signal on pin70?. IC3.
Since you are using capture unit 3, this is where the input has to be.

You really should test for the capture event having happened:
Code:

   if (interrupt_active(INT_IC3))
   {
       //This says an event has happened

       //read the captured value, and clear the interrupt
       p = get_capture(3,TRUE);
       clear_interrupts(INT_IC3);
   }

thank you for reply
yes.on pin 70.pin_d10

but yet lcd show random number


Code:
#include <33FJ256MC710.h>
#use delay(internal=7.37m)
#include <lcd.c>

#INT_IC3
void  ic3_isr(void)
{

}
void main()
{
lcd_init();
setup_timer3(TMR_INTERNAL | TMR_DIV_BY_8);
   enable_interrupts(INT_IC3);
   enable_interrupts(INTR_GLOBAL);
setup_capture(3, CAPTURE_EE | INTERRUPT_EVERY_CAPTURE | CAPTURE_TIMER3);
int16 p=0;
   while(TRUE)
   {

if (interrupt_active(INT_IC3))
   {
       //This says an event has happened

       //read the captured value, and clear the interrupt
       p = get_capture(3,TRUE);
      clear_interrupt(INT_IC3);


   }
a++;
lcd_gotoxy(1,1);
printf(lcd_putc,"%lu",p);




   }}
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Tue Mar 31, 2015 10:43 am     Reply with quote

Remember this is a _capture_. You need:
Code:

void main()
{
   int16 old=0;
   //other init code etc...


    //loop etc..
      if (interrupt_active(INT_IC3))
      {
          //This says an event has happened

          //read the captured value, and clear the interrupt
          p = get_capture(3,TRUE);
          clear_interrupt(INT_IC3);
          lcd_gotoxy(1,1);
          printf(lcd_putc,"%lu",p-old);   
          old =p;   
      }

You have to calculate the change between the two capture events, to get the period. Look at ex_capture.c, where this is shown.
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