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.

problem with input capture in dsPIC30F3011

Status
Not open for further replies.

yokel

Junior Member level 3
Joined
Nov 13, 2008
Messages
30
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,529
adpcfg

Dear All,
I am using the input capture of dsPIC30F3011 for calculating the pulse width of a square wave. I am using the following code:

Code:
unsigned int rotateCount=0;
unsigned int timePeriod= 0; current_value=0,previous_value=0;		

void InitIC(void)
{
	IC7CONbits.ICM=3;      // Capture every rising edge
	IC7CONbits.ICBNE=0;  // Input capture buffer is empty
	IC7CONbits.ICOV=0;    // No input capture overflow occured
	IC7CONbits.ICI=0;       // Interrupt on every capture event 
	IC7CONbits.ICTMR=1;  // TMR2 contents are captured on captured event
	IC7CONbits.ICSIDL=0; // Input capture module will continue to operate in CPU Idle mode
	
	IFS1bits.IC7IF = 0;      // Interrupt bit is cleared
	IPC4bits.IC7IP = 3;	  // Set Interrupt priority to 3
	IEC1bits.IC7IE = 1;     // Set the IC7 interrupt enable bit
}

void TMR2_setup(void)
{
	TMR2 = 0x00;			// Clear contents of the timer register 	
	T2CONbits.TCS=1;        	// Timer uses the internal clock when TCS = 0. Using Internal Clock (Fosc/4)
	T2CONbits.T32=0;        	// TMRx and TMRy form a 16-bit timer
	T2CONbits.TCKPS=0;      	// Using 1:1 prescale value 
	T2CONbits.TGATE=0;      	// Timer Gate Accumulation Disabled 
	T2CONbits.TSIDL=0;      	// Continue in Idle Mode 
	T2CONbits.TON=1;        	// Start Timer1 with prescaler settings at 1:1 and 
						// clock source set to the internal instruction cycle
	PR2 = 0xFFFF; 			//Load the Period register with the value 0xFFFF 
	return;
}

void __attribute__((interrupt, no_auto_psv)) _IC7Interrupt (void)
{
	rotateCount=rotateCount + 1;

	if (rotateCount==6)
	{
		previous_value=current_value; 
		current_value=IC7BUF; 
		if(current_value>previous_value) 
		{ 
			timePeriod = current_value-previous_value; 
		} 
		else 
		{ 
			timePeriod = (PR2 - previous_value) + current_value;
 		} 
	
		SendData(timePeriod);   // sending the time period to the host PC
		rotateCount=0;
	}
	IFS1bits.IC7IF = 0;       		//Interrupt bit is cleared
}

But I am not getting any response from the ISR. Please help me to find out the problem in my code.

Thanks.
 

dspic30f3011 input capture module

It would be great if anyone come up with a solution of my problem. I have attached the connection setup I am using in my circuit for the input capture. Please tell me if I am wrong.

Please also take a closer look at the initialization function I am using for the Input Capture and timer2.

thanks
 

init input capture

I assume your 'main()' function is just an infinite loop after calling the init functions.
Scope the input pin to make sure the line is being pulled low ok.
Use the debugger to place a break point in the interrupt function, then single step through the code to make sure it is working.
 

    yokel

    Points: 2
    Helpful Answer Positive Rating
To confirm your ADPCFG & TRISB settings to make sure "AN4/QEA/IC7/CN6/RB4" is digital input. (default is analog input)
The ICI=0 is a special mode. The IC interrupt will be still generated even ICOV=1.
 

    yokel

    Points: 2
    Helpful Answer Positive Rating
btbass said:
I assume your 'main()' function is just an infinite loop after calling the init functions.
Scope the input pin to make sure the line is being pulled low ok.
Use the debugger to place a break point in the interrupt function, then single step through the code to make sure it is working.

Thanks for the reply. But I couldn't understand. I am just a beginner, please provide me some details. (I have set the PORT B as input pin earliar)



thanks
 

I think yager has the answer, I have had the same problems myself. The pin needs to be configured as a digital I/O by setting the coresponding bit in the ADPCFG register. The default reset state is analog input.
If your main function is something like,

Code:
int main(void)
  {
  InitIC();
  TMR2_setup();

  for(;;){
     ;
     }
  }

If you are using the ICD2, PicKit or Real Ice as a debugger, you should be able to place a breakpoint in the interrupt function and then single step through the code to see whats happening.
330R is quite a low value, the input will have to sink 15mA to pull the line low, unless there is a reason for this, I would increase the pullup resistor to something like 4K7 - 10K.
 

    yokel

    Points: 2
    Helpful Answer Positive Rating
dear btbass
my main function is exactly like what you have said.

As you said,
"The pin needs to be configured as a digital I/O by setting the coresponding bit in the ADPCFG register"

I've read the register configuration of ADPCFG but couldn't understand what to do. Please tell me which one is my corresponding bit in the ADPCFG register? I have set the corresponding bit of port B (RB4) as input earliar.

thanks a lot for all the supports.
 

The Port is configured as a digital input when the Tris bit is set and the corresponding ADPCFG bit is set.
The ADPCFG is clear at reset, so the pins default to analog input.
IC7 interrupt is on pin AN4/RB4. So to set it as a digital input.

TRISbits.TRISB4 = 1;
ADPCFGbits.PCFG4 = 1;

That should do the trick.
If you havnt already done so, down load the 'Family Reference Manual' from Microchip. It contains detailed information on all the peripherals.
 

    yokel

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top