LPC4367 Timer Capture issue

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LPC4367 Timer Capture issue

2,001件の閲覧回数
gauravmore
Contributor III

Hi,

I am using LPC4637 based Evaluation board OEM13088 for development. I am trying to explore the Timer capture functionality since it is the requirement in our product to measure the frequency .

I have implemented the code where I am using Timer 2 and T2_CAP0 line (P6_1) to measure the frequency. I am getting the interrupt of the timer but the Frequency which i have measured is exceeding the expected one, rather it is not stable at all. I verified the input to the capture line, It is one of the input from out development board Circuit, 

I checked with LPC546xx board and it is working properly. So the input the capture line is proper. Not I am not able to get the same result with LPC4367 controller.

Following is the initialization code for the same.

スポイラ

#define CAP_NUMB 0
#define TIMER2_PRESCALER 10

ui32_timerFreq = Chip_Clock_GetRate(CLK_MX_TIMER2);//Chip_Clock_GetSystemClockRate();//(PRESCALE_COUNT+1);

Chip_GPIO_Init(LPC_GPIO_PORT);

Chip_SCU_PinMux(0x6,1, MD_PLN_FAST, SCU_MODE_FUNC5);
LPC_GIMA->CAP0_IN[2][0]|= (2 << 4) | (1 << 1);//0x20


Chip_TIMER_Init(LPC_TIMER2);
Chip_RGU_TriggerReset(RGU_TIMER2_RST);
while (Chip_RGU_InReset(RGU_TIMER2_RST)) {}

// Chip_TIMER_Init(LPC_TIMER2);

Chip_TIMER_Reset(LPC_TIMER2);

// Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER2, TIMER_CAPSRC_RISING_CAPN, CAP_NUMB);

Chip_TIMER_PrescaleSet(LPC_TIMER2, TIMER2_PRESCALER);


Chip_TIMER_ClearCapture(LPC_TIMER2, CAP_NUMB );//
Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER2, CAP_NUMB);//
// Chip_TIMER_CaptureFallingEdgeEnable (LPC_TIMER2, CAP_NUMB );//
Chip_TIMER_CaptureEnableInt(LPC_TIMER2,CAP_NUMB);//

NVIC_EnableIRQ(TIMER2_IRQn);
NVIC_ClearPendingIRQ(TIMER2_IRQn);

Chip_TIMER_Enable(LPC_TIMER2);

After this I am able to get the capture evet but the value is exceeding the frequency value. Also find the attached code which I am working on.

Similar issue was there in the Forum but there no reply for the same.

Please check for the issue and solution for the same. Also let me know if required any more information.

Thanks

Gaurav More

 

 

ラベル(2)
0 件の賞賛
返信
6 返答(返信)

1,989件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Gaurav,

I have checked your code briefly, I think the code is correct. The TImer2 counts internal clock, when the T2_CAP0 signal is coming, the Counter0f T2 is latched to capture register and interrupt is triggered..

But I think you have to add the line to reset the counter explicitly when the T2 counter reaches to match register for example match0

//STATIC INLINE void Chip_TIMER_SetMatch(LPC_TIMER_T *pTMR, int8_t matchnum, uint32_t //matchval)

Chip_TIMER_SetMatch(LPC_TIMER2,0,0xFFFFFFFF);

Chip_TIMER_ResetOnMatchEnable((LPC_TIMER2, 0);

pls have a try.

BR

XiangJun Rong

 

0 件の賞賛
返信

1,987件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

BTW, I think you'd better set up the #define TIMER2_PRESCALER 1

At the time being, what is your problem?

BR

XiangJun Rong

0 件の賞賛
返信

1,983件の閲覧回数
gauravmore
Contributor III

Hi XiangJun Rong,

Thanks for the reply,

I check the modification suggested by you both the match set and the Timer prescaler, but still no success,

I also shifted from internal clock to external clock but still the same result.

I also check whether the problem is with the waveform input, but that is also proper

Any other input please suggest, mean while I will check other possible ways, w.r.t  logic implemented 

Thanks

Gaurav More

0 件の賞賛
返信

1,973件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport
Hi, I suggest you initialize a GPIO output pin, in the void TIMER2_IRQHandler(void), toggle the GPIO, you can compare the capturing signal and GPIO output pin with an oscilloscope. Pls have a try BR XiangJun Rong
0 件の賞賛
返信

1,960件の閲覧回数
gauravmore
Contributor III

Hi XiangJun Rong,

Thanks for the reply,

I checked the line and got the issue, I had not configured the falling edge trigger option,

I enabled it and now both the line toggling and the input to the capture is matching. 

gauravmore_2-1628668946004.png

 Yellow line is the line toggled and the blue one is the ZCD input from the development board.

 

 

 

#define CAP_NUMB  0
#define TIMER2_PRESCALER   1
#define UPPER_LIMIT_32	0xFFFFFFFF   

ui32_timerFreq = Chip_Clock_GetRate(CLK_MX_TIMER2);//Chip_Clock_GetSystemClockRate();//(PRESCALE_COUNT+1);

    Chip_GPIO_Init(LPC_GPIO_PORT);

    Chip_SCU_PinMux(0x6,1, MD_PLN_FAST, SCU_MODE_FUNC5);
    LPC_GIMA->CAP0_IN[2][0]|=  (2 << 4) ;//| (1 << 1);//0x20

    Chip_SCU_PinMuxSet(0x02, 12,(SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS |SCU_MODE_FUNC0));
    Chip_GPIO_SetPinState(LPC_GPIO_PORT,1,12,true);
    Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT,1,12);


	Chip_TIMER_Init(LPC_TIMER2);
	Chip_RGU_TriggerReset(RGU_TIMER2_RST);
	while (Chip_RGU_InReset(RGU_TIMER2_RST)) {}

	Chip_TIMER_Reset(LPC_TIMER2);

//	Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER2, TIMER_CAPSRC_BOTH_CAPN, CAP_NUMB);

	Chip_TIMER_PrescaleSet(LPC_TIMER2, TIMER2_PRESCALER);

	Chip_TIMER_ClearCapture(LPC_TIMER2, CAP_NUMB );
	Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER2, CAP_NUMB);
	Chip_TIMER_CaptureFallingEdgeEnable (LPC_TIMER2, CAP_NUMB );
	Chip_TIMER_CaptureEnableInt(LPC_TIMER2,CAP_NUMB);

	Chip_TIMER_SetMatch(LPC_TIMER2,0,0xFFFFFFFF);
	Chip_TIMER_ResetOnMatchEnable(LPC_TIMER2,0);


	NVIC_EnableIRQ(TIMER2_IRQn);
	NVIC_ClearPendingIRQ(TIMER2_IRQn);

	Chip_TIMER_Enable(LPC_TIMER2);

 

Also need to change the Prescaler to 1 and now I am running the at 100Mhz both controller and timer as well.

But there is one observation,  if we consider the clock freq 100Mhz , then expected difference for complete cycle is around 200 counts but the difference observed is not as per the expectation. 

see the below screen shot

gauravmore_0-1628668224357.png

gauravmore_1-1628668249661.png

 It is not stable to 50Hz it is fluctuating between 49Hz to 50Hz. Here the variable "ui32_current_half_cycle_time" is just a difference between the current and previous capture value of timer 2. And as per the formula the value come around 20Mhz 

channels[0].ui32_frequency = (uint32_t)(((uint64_t)ui32_timerFreq*(uint64_t)1000)/(uint64_t)channels[0].ui32_current_half_cycle_time);

Got the reason, changed the Prescaler to 0 from 1 and kept only Rising edge trigger. Now it is coming closer to the expected value.

Also attached the code which w.r.t Capture functionality for LPC4367 over OEM13088.

Please check w.r.t the configuration and the if there is any thing you find that need to be modified pls suggest.

Thanks

Gaurav More

 

0 件の賞賛
返信

1,970件の閲覧回数
gauravmore
Contributor III

Hi 

Yes checking the same at my end, Will update you once it is done with screen shots.

Thanks

Gaurav More

0 件の賞賛
返信