Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Input Capture period calculations

Status
Not open for further replies.

Jinzpaul4u

Full Member level 4
Full Member level 4
Joined
Feb 1, 2012
Messages
231
Helped
59
Reputation
118
Reaction score
60
Trophy points
1,328
Location
India
Visit site
Activity points
2,822
Hello there,

I'm using the dsPIC33fj256gp710 MCU to obtain the pulse width of a PWM generator using Input Capture module(rising and falling edge of the pulse).
The program works fine, and I can obtain a time period. However, I need to do some further calculations with the period value, and I don't really know how to convert the obtained value into a number that can be used in regular math functions. The time period I normally get is 960ms (I've connected an oscilloscope to the circuit as well to get this value).

mean while I am using timer counter register to check time period.The essential portions of the code are shown below (with comments):

HTML:
unsigned int timeperiod1=0;
unsigned int timeperiod2=0;

void __attribute__((__interrupt__)) _IC1Interrupt(void)
{
unsigned int t1,t2;

if(PORTDbits.RD8) // rising edge of the pulse
{	timePeriod1=0;
	TMR2=0;// timer counter become reseted 
	t1=IC1BUF; // present time period value
	T2CONbits.TON = 1;// Start Timer
	
	
}
else if(!PORTDbits.RD8)// falling edge of the pulse
{
	T2CONbits.TON = 0;// Stop Timer	
	timeperiod1=TMR2; // time period calculation based on timer
	t2=IC1BUF;       // updated value
	timeperiod2=t2-t1; //  time period calculation based on inputcapture
		
}


}

Here I am getting both timeperiod1 and timeperiod2 are equal. that is=18192

based on timer Period calculation
HTML:
Fosc=80MHz // using PLL
Fcy =Fosc/4=20MHz // timer frequency 
Tcy =1/Fcy= 50ns // timer period
prescaler=1:1
TMR1 increments (increases by 1) every 1 x Tcy seconds =50ns.

Total time period is =18192 * 50n=0.9096ms

but actual time period in osciloscope is=960ms.

could someone tell me how I could achieve this or what I am doing wrong in the code I have?

This may seem really basic, but I'm quite inexperienced and could really use some help in this situation.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top