![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Mahdi
Joined: 21 Aug 2012 Posts: 47
|
dspic33fj input capture |
Posted: Tue Mar 31, 2015 8:38 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19372
|
|
Posted: Tue Mar 31, 2015 9:18 am |
|
|
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);
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Mahdi
Joined: 21 Aug 2012 Posts: 47
|
|
Posted: Tue Mar 31, 2015 10:06 am |
|
|
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);
}} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19372
|
|
Posted: Tue Mar 31, 2015 10:43 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|