Asking for Input Capture Interrupt MCU S12G128 sample code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Asking for Input Capture Interrupt MCU S12G128 sample code

Jump to solution
1,608 Views
lukmankurniawan
Contributor II

Hello,

I just new for using NXP MCU S12G128 and I want to capture digital pulse using interrupt (RISING or FALLING edge detection). After I search all S12G128 example, I cannot find any example for using it, is there any example for that?

Any example would be appreciate.


Best regards,

Lukman

Labels (1)
0 Kudos
1 Solution
1,152 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

I see It has been resolved in this thread:

https://community.nxp.com/thread/358694 

Regards,

Daniel

View solution in original post

9 Replies
1,152 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Lukman,
The S12G128 MCU has the same TIM16B6V3 module as S12ZVL.
So you can refer to:

https://community.nxp.com/docs/DOC-332554 

 

Regards,
Daniel

0 Kudos
1,152 Views
lukmankurniawan
Contributor II

Hi Daniel, 

Since I use S12G128 MCU and use code warrior 5.9.0 version,I cannot import the example you give to me.
Also Any simple example?

Best Regards,

Lukman

0 Kudos
1,152 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Lukman,

We don't have this example ported on S12G.

You can't import that project, however, you can reuse the TIM code.

Regards,

Daniel 

0 Kudos
1,152 Views
lukmankurniawan
Contributor II

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

0 Kudos
1,152 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

Could you please share the whole test project including PE configuration.

Thank you,

Daniel 

0 Kudos
1,152 Views
lukmankurniawan
Contributor II

Hi Daniel,

I have modified my code, now the interrupt is happen, but only once. Would you kindly check my project?
I attached my project on attached file.

I appreciate your help.

 

Best Regards,

 

Lukman

0 Kudos
1,153 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

I see It has been resolved in this thread:

https://community.nxp.com/thread/358694 

Regards,

Daniel

1,152 Views
lukmankurniawan
Contributor II

Hi Daniel,

Yes it solved already, many thanks for your help.

Best Regards,

Lukman

0 Kudos
1,152 Views
lukmankurniawan
Contributor II

Hi Daniel,

Thank you, I will try to reuse it.

I will let you know if get problem.

Best Regards,

Lukman

0 Kudos