Hi Daniel,
I just created following the example you given, then I connect PT0 to function generator, but as I check variables such as TC0 & overflow why it doesn't change/increase? what is the problem? the code as below:
#pragma CODE_SEG NON_BANKED
interrupt void TIM0_ISR(void)
{
overflow++;
TFLG2 = 0x80; //clear interrupt flag
}
//===========================
// Input Capture Interrupt channel 0
//===========================
interrupt void IC0_ISR(void)
{
new_capture = TC0; //save the value of input capture register
if(first_edge != 0) //first_edge just take care about the first calculating when we don't know the value of previous input
{
//calculate the number of bus cycles//////////////
number_of_cycles = (0xFFFF * (unsigned long int)overflow) + new_capture - old_capture;
frequency = BUS_CLOCK/number_of_cycles;
}
else
first_edge = 1;
overflow = 0;
old_capture = new_capture; //save the IC for next using
TFLG1 = 0x01; //clear interrupt flag on channel 0 (channel1= 0x02, channel2=0x04, channel3=0x08)
}
#pragma CODE_SEG DEFAULT
//==========================
// InitInputCapture for channel 0//
//==========================
void InitInputCapture_0(void)
{
PPST_PPST0 = 0; //set pull-up PPST0 (pull-up=0, pull-down=1)
PERT_PERT0 = 1; //enable pull-up on PERT0
TSCR1 = 0xE0;//0xF0;//enable timer, stop timer during wait and freeze, disable fast flag clear
TIOS_IOS0 = 0; //channel 0 as an input capture (input capture=0, output compare=1)
TCTL4 = 0x01; //capture on rising edge
TIE_C0I = 1; //enable interrupt on channel 0
TSCR2 = 0x80; //timer overflow interrupt enable, counter free runs, timer prescaler is 1
}
void main(void)
{
PE_low_level_init();
InitInputCapture_0(); ///Input Capture Interrupt//
EnableInterrupts; ///Enable interrupt//
}
I appreciate your help.
Best Regards,
Lukman