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.

Frequency measurement using input capture module in dspic30f5011

Status
Not open for further replies.
Hi,

What about my recommendations of post#19?

Klaus
 

Hi,
With 32 bit timer and 1:1 prescaler I can't handle the 16 bit lsb and 16 bit msb values.So that I come back to 16 bit timer with 256 prescaler. But with this timer I am getting the values with error like 0.3 to 0.6.So how to reduce the error.

Thanks and Regards
M SAI KIRAN.
 

Hi,

I don´t understand.

With 32 bit timer and 1:1 prescaler I can't handle the 16 bit lsb and 16 bit msb values.
What´s wrong with it?

I bit more detailes, please.

Klaus
 

Hi,
With 32 bit timer,the input capture channel captures the 16 bit lsb that is from timer 2.If timer 2 values are maximum then values will be updated into timer 3.But I have only one channel available on my controller as per the design. when I want the higher values the input capture captures the overflow result.So,that why I am uisng 16 bit timer and 256 prescaler.

Thanks and Regards,
M SAI KIRAN.
 

Hi,

It seems you insist on the 16 bit values.
According the previously made calculations it is not possible to work with 16 bits.
So
* either use the 32 bits for your full desired frequency range
* or use the 16 bit with decreased frequency range. A prescaler won´t change resolution:

There is no way round.

*****

But if you setup the timer to 32 bit mode, you should calaculate with 32 bits. Not 16 bits anymore.

Combine the 16 bits of timer 2 with the 16 bits of timer3 to get a 32 bit value.
Now you have a huge dynamic.

***
You didn´t say where exactley you see a problem .. so I don´t know how to help you.
--> show your code. Describe what test you perform. Describe what result you expect and describe the unecpected result.

****
But I have only one channel available on my controller as per the design
WHAT channel?

Klaus
 

Hi,

I have configured 2 input capture channels to capture two 16 bits individually( MSB LSB) of 32 bits and timer as 32-bit by combining timer2 and timer3. here is my code
*************** input capture *************************
Code:
void IC_INIT(void)
{
	// Register 13-1: ICxCON: Input Capture x Control Register in datasheet  
	IC2CONbits.ICM= 0b011;				// Input Capture Mode Select (Every rising edge)
	IC2CONbits.ICBNE=0;					// Input Capture Buffer Empty Status (Read Only)
	IC2CONbits.ICOV=0;					// Input Capture Overflow Status Flag (Read Only)
	IC2CONbits.ICI= 00;					// Select Number of Captures per Interrupt bits (00 = Interrupt on every capture event)
	IC2CONbits.ICTMR=1;					// Input Capture Timer Select bits 1=TMR2 contents are captured on captured event)
	IC2CONbits.ICSIDL=0;    				// Input Capture Module Stop in Idle Control(0=Input capture module will continue to operate in CPU Idle mode)
	
	IC3CONbits.ICM= 0b011;				// Input Capture Mode Select (Every rising edge)
	IC3CONbits.ICBNE=0;					// Input Capture Buffer Empty Status (Read Only)
	IC3CONbits.ICOV=0;					// Input Capture Overflow Status Flag (Read Only)
	IC3CONbits.ICI= 00;					// Select Number of Captures per Interrupt bits (00 = Interrupt on every capture event)
	IC3CONbits.ICTMR=0;					// Input Capture Timer Select bits 0=TMR3 contents are captured on captured event)
	IC3CONbits.ICSIDL=0;    				// Input Capture Module Stop in Idle Control(0=Input capture module will continue to operate in CPU Idle mode)
	IPC1bits.IC2IP = 5;
	// Register 6-6: IFS1: Interrupt Flag Status Register 1
	IFS0bits.IC2IF = 0;       			// Input Capture Channel 2 Interrupt Flag Status )0=Interrupt bit is cleared
	// Register 6-9: IEC1: Interrupt Enable Control Register 1
	IEC0bits.IC2IE = 1;     			// Input Capture Channel 2 Interrupt Enable bit (1 = Interrupt request enabled) 
	printf("Ic ready\n");
	
}

void __attribute__((__interrupt__,no_auto_psv)) _IC2Interrupt(void)
{
	
		
	LSB = IC2BUF;
	MSB = IC3BUF; 			
	IFS0bits.IC2IF= 0; //Clear bit IC1IF (IFS<2>)

}
****************** timer *****************************
Code:
void timer_init(void)
{
 	T2CON			=0;							//disable Timer2
 	TMR2			=0x0000;					        //Timer2 reg
 	PR2				=0xFFFF;						//PR reg of Timer2
 	T2CONbits.TSIDL	= 0;							// configuring timer3
	T2CONbits.TCKPS	= 0b00;	                 			// 1:1 prescaler	
	T2CONbits.T32		= 1;							//Timer2 & Timer3 Configured as 32-bit Timer	
	T3CON			= 0;							//desabling timer3
	TMR3			= 0X0000;					        // TIMER3 REGISTER
	PR3				= 0xFFFF;					// time period						
	IFS0bits.T3IF		= 0;							// clear interrupt flag 
	IPC1bits.T3IP		= 7;							// set interrupt priority
	IEC0bits.T3IE		= 1;							// interrupt enable
	T2CONbits.TON		= ON;						// enable timer2
	T3CONbits.TON		= ON;						// enable timer3
	printf("Timer ready\n");
	
}



void __attribute__((__interrupt__,no_auto_psv)) _T3Interrupt(void)
{	
	IFS0bits.T3IF	= 0;
}

The problem is i'm getting 0 every time in MSB.

Regards
Sai
 

Hi,
Is there an wrong in my code or Is there any need to short the two channels that I used to get the required output.Otherwise any changes in my program.

Thanks and Regards,
M SAI KIRAN.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top