LPC5536 CTIMER0 confusion

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

LPC5536 CTIMER0 confusion

ソリューションへジャンプ
6,676件の閲覧回数
Bela1
Contributor III

Ladies and Gentlemen,

I am trying to set up CTIMER0 for a periodic interrupt. Unfortunately it doesn't work and I'm getting confused.

My questions are:

1- In the Reference Manual -> SYSCON capital, page 223, AHBCLKCTRL1 register has bit26, called TIMER0. Is this bit the clock enable for CTIMER0? Is TIMER0 and CTIMER0 the same thing?

2- when I turn AHBCLKCTRLSET[1], bit26 to 1, I immediately loose the connection between MCUXpresso and MCULINK PRO. That means, I cannot debug anymore. I have to close the debug perspective and open it again.

3- There's another enable bit: SYSCON->CTIMERGLOBALSTARTEN, bit0. Here I can also enable CTIMER0 CLK. Are both enables necessary?

4- In case I don't turn AHBCLKCTRLSET[1], 26 bit to 1, I can debug the chip, but all the instructions to set in the CTIMER0 section, they have no effect at all. I single step through them, but there's no change in the registers.

5- I also can't set to 0 the CTIMERCLKDIV[0] register - I'd like to enable the clock divider

6- CTIMERCLKSEL[0] also cannot select FRO1M, if I try to write this register 0x04, there's no effect.

Since CTIMER0 doesn't work, of course, I don't get any interrupt on it.

Here's the part of my code, which must configure CTIMER0:

// Set up Ctimer0 to generate a periodic interrupt

SYSCON -> CLKUNLOCK =0x01 ; // enables configuration of clocks

SYSCON -> CLOCK_CTRL |= FRO1MHZ_CLK_ENA ; // enable the 1MHz RC oscillator

SYSCON -> AHBCLKCTRLSET[1] |= TIMER0_CLK_EN ; //

SYSCON -> CTIMERCLKDIV[0] = 0x0 ; // ** divider clock runs, division by 1

SYSCON -> CTIMERCLKSEL[0] = FRO1M; // ** CTimer0 clock is 1MHz from FRO

SYSCON -> CLKUNLOCK = 0x00 ; // disables configuration of clocks

SYSCON -> PRESETCTRLCLR[1] |= TIMER0_RST; // reset timer 0

SYSCON -> CTIMERGLOBALSTARTEN |= CTIMER0_CLK_EN; // Ctimer 0 gets clock

CTIMER0 -> TCR |= CEN ; // CTIMER0 Counter enable

CTIMER0 -> PR = 1000U ; // Prescaler set to 1000. 1MHz : 1000 = 1kHz to timer0

CTIMER0 -> MSR[0] = 1000U ; // Match shadow register, also 1000, results in 1sec timer0

CTIMER0 -> MR[0] = 1000U ; // beginning value

CTIMER0 -> MCR |= MR0S | MR0RL | MR0I ; // stop on match, reload MR0 from shadow, generate IT

NVIC -> ISER[0] |= 1U<<10 ; // Enable Interrupt No 10 (Timer0)

 

7- I got bit 10 from the file LPC5536.h, line 93. I didn't find any other documentation, if this interrupt is really from CTIMER0. Is it right?

Other parts of my - at the moment still primitive - code are properly working, I can debug them - whenever the debugger works.

 

 

0 件の賞賛
返信
1 解決策
6,587件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls try the following code, it works on my EVK board

#define TIMER0_RST 1<<26

#define TIMER0_CLK_EN 1<<26

#define FRO1MHZ_CLK_ENA 1<<6

#define FRO1M 0x04

void CTimerInit(void)

{

// Set up Ctimer0 to generate a periodic interrupt

SYSCON->PRESETCTRLSET[1] = TIMER0_RST; // reset timer 0

SYSCON->PRESETCTRLCLR[1] = TIMER0_RST; // reset timer 0

 

//SYSCON->CLKUNLOCK =0x01 ; // enables configuration of clocks

SYSCON->CLOCK_CTRL |= FRO1MHZ_CLK_ENA ; // enable the 1MHz RC oscillator

SYSCON->AHBCLKCTRLSET[1] |= TIMER0_CLK_EN ; //

SYSCON->CTIMERCLKDIV[0] = 0x0 ; // ** divider clock runs, division by 1

SYSCON->CTIMERCLKSEL[0] = FRO1M; // ** CTimer0 clock is 1MHz from FRO

//SYSCON->CLKUNLOCK = 0x01 ; // disables configuration of clocks

 

 

CTIMER0->PR = 1000U ; // Prescaler set to 1000. 1MHz : 1000 = 1kHz to timer0

CTIMER0->MSR[0] = 1000U ; // Match shadow register, also 1000, results in 1sec timer0

CTIMER0->MR[0] = 1000U ; // beginning value

CTIMER0->CTCR=0x00;

CTIMER0->EMR=0x00;

CTIMER0->PWMC=0x00;

CTIMER0->MCR |= 1<<24|3<<0; // stop on match, reload MR0 from shadow, generate IT

NVIC->ISER[0] |= 1U<<10 ; // Enable Interrupt No 10 (Timer0)

NVIC->ICPR[0] |= 1U<<10 ;

NVIC->IPR[10]=0x00;

//SYSCON->CTIMERGLOBALSTARTEN |= CTIMER0_CLK_EN; // Ctimer 0 gets clock

CTIMER0->TCR |= 0x01; // CTIMER0 Counter enable

}

 

 

void CTIMER0_IRQHandler(void)

{

//clear flag

CTIMER0->IR|=1<<0;

GPIO_PortToggle(GPIO, BOARD_LED_PORT, 1u << BOARD_LED_PIN);

}

Hope it can help you

元の投稿で解決策を見る

0 件の賞賛
返信
11 返答(返信)
6,469件の閲覧回数
jcmyao
Contributor I

It does work! Your solution works in my EVK board. Thanks.

 

0 件の賞賛
返信
6,629件の閲覧回数
Bela1
Contributor III

Dear XiangJun Rong,

I discovered, that there's an error in the attached code. I corrected already from line 113 to 117, I access CTIMER0 now.

Now, my code compiles properly, runs until line 103 properly. From line 103 I single step. When I reach line 113 (CTIMER0->TCR |= CEN the connection breaks between MCUXpresso and MCU-LINK Pro. See the screenshot please. In case I don't single stem but run at full speed, the connection also breaks. I only try to watch a variable, CheckTimer. No other registers are watched.

How can I debug this code? Is it impossible?

Bela1_0-1719826356228.png

 

0 件の賞賛
返信
6,637件の閲覧回数
Bela1
Contributor III

My questions are:
- How can I be sure, that CTIMER0 is properly configured and it counts?
- How can I avoid the lost of connection between MCUXpresso and MCU-LINK Pro?

0 件の賞賛
返信
6,636件の閲覧回数
Bela1
Contributor III

Dear XiangJun Rong,

thank You for the suggestions. Unfortunately, I am still in trouble.

As I understand Your answer, CTIMER0 and TIMER0 are the same thing, only the terminology is different in the documentation. It's OK then.

The root of my problem is: I need to have a periodic interrupt in about every second. I try to set it up, but without a success.
My idea is: CTIMER0 runs, counts about 1 sec long and generates the necessary interrupt and starts all over again.
This interrupt doesn't happen, and I am trying to find out why. Maybe the counter doesn't work, maybe it is misconfigured, maybe I set the interrupt the wrong way or something else?
First, I try to check the counter.

TIMER0_CLK_EN is defined as 26 in a header file, it is not a problem.

My code runs until the breakpoint in line 103 without any problem. The first instruction is in line 77, there are only includes and comments before. The IRQ service routine is at the end of my code.

As I try to debug my code, I single step after line 103. Everything is fine, until I try to see the CTIMER0 registers. When the command in line 108 turns the clock ON, I immediately loose the connection between MCUXpresso and MCU-LINK PRO.

In case I don't watch the CTIMER0 registers in debug perspective, than I am able to single step through my code (IRQ doesn't come whether I single step or I let it run full speed).
If I stop the clock to CTIMER0 later in the code, I am able to look into the register-bank of CTIMER0, but I only see all zeroes there, like it wouldn't be configured at all.

Bela1_0-1719820715607.png

 

0 件の賞賛
返信
6,620件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls refer to SDK example of CTimer.

You can download SDK from the link:

https://mcuxpresso.nxp.com/en/welcome

xiangjun_rong_0-1719892282135.png

I suppose that the CTimer registers writing has to follow up a sequence.

After you enable the CTimer gated clock and set up the CTimer clock source, then follow up the sequence.

 CTIMER4->CTCR=0x00;
CTIMER4->PR=0x00;
CTIMER4->MCR=0x03;
CTIMER4->PWMC=0x00;
CTIMER4->MR[0]=0x2000;
CTIMER4->MSR[0]=0x2000;
Pls have a try

BR

XiangJun Rong

0 件の賞賛
返信
6,604件の閲覧回数
Bela1
Contributor III

Dear xiangjun_rong,

I tried to implement Your code. The only modification is, I modified to CTIMER0 instead of CTIMER4.

When the clock of CTIMER0 is enabled, line 128, I immediately loose the connection between MCUXpresso and MCU-LINK Pro.

I cannot find out, how to resolve this problem:

Bela1_0-1719904037688.png

The only workaround is not to enable the clock for CTIMER0, by commenting line 128 out - see the screenshot please.

Of course, without clock, it is not possible to configure and run the CTIMER0. But, there's no loss of connection, the other parts of my code works.

I don't know what to do. Please recommend me a solution.

0 件の賞賛
返信
6,598件の閲覧回数
Bela1
Contributor III
Another experience:
Whether the clock is enabled to CTIMER0 in AHBCLKCTRL[1], or it is not enabled, I cannot modify SYSCON-> CTIMERCLKDIV, cannot set the HALT bit to zero.
Also, CTIMERCLKSEL remains 0x07 (no clock), even if my code sets it to 0x00 (main clk).
When CTIMER0 clock is enabled in SYSCON->AHBCLKCTRL1, and I try to modify any registers in CTIMER0 domain, I loose the connection between MCUXpresso and MCU-Link pro.
Why I cannot select the clock source for CTIMER0? Is there any restriction to SYSCON->CTIMERCLKSEL0 ?
0 件の賞賛
返信
6,588件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls try the following code, it works on my EVK board

#define TIMER0_RST 1<<26

#define TIMER0_CLK_EN 1<<26

#define FRO1MHZ_CLK_ENA 1<<6

#define FRO1M 0x04

void CTimerInit(void)

{

// Set up Ctimer0 to generate a periodic interrupt

SYSCON->PRESETCTRLSET[1] = TIMER0_RST; // reset timer 0

SYSCON->PRESETCTRLCLR[1] = TIMER0_RST; // reset timer 0

 

//SYSCON->CLKUNLOCK =0x01 ; // enables configuration of clocks

SYSCON->CLOCK_CTRL |= FRO1MHZ_CLK_ENA ; // enable the 1MHz RC oscillator

SYSCON->AHBCLKCTRLSET[1] |= TIMER0_CLK_EN ; //

SYSCON->CTIMERCLKDIV[0] = 0x0 ; // ** divider clock runs, division by 1

SYSCON->CTIMERCLKSEL[0] = FRO1M; // ** CTimer0 clock is 1MHz from FRO

//SYSCON->CLKUNLOCK = 0x01 ; // disables configuration of clocks

 

 

CTIMER0->PR = 1000U ; // Prescaler set to 1000. 1MHz : 1000 = 1kHz to timer0

CTIMER0->MSR[0] = 1000U ; // Match shadow register, also 1000, results in 1sec timer0

CTIMER0->MR[0] = 1000U ; // beginning value

CTIMER0->CTCR=0x00;

CTIMER0->EMR=0x00;

CTIMER0->PWMC=0x00;

CTIMER0->MCR |= 1<<24|3<<0; // stop on match, reload MR0 from shadow, generate IT

NVIC->ISER[0] |= 1U<<10 ; // Enable Interrupt No 10 (Timer0)

NVIC->ICPR[0] |= 1U<<10 ;

NVIC->IPR[10]=0x00;

//SYSCON->CTIMERGLOBALSTARTEN |= CTIMER0_CLK_EN; // Ctimer 0 gets clock

CTIMER0->TCR |= 0x01; // CTIMER0 Counter enable

}

 

 

void CTIMER0_IRQHandler(void)

{

//clear flag

CTIMER0->IR|=1<<0;

GPIO_PortToggle(GPIO, BOARD_LED_PORT, 1u << BOARD_LED_PIN);

}

Hope it can help you

0 件の賞賛
返信
6,574件の閲覧回数
Bela1
Contributor III

Dear XiangJun Rong,

Thank You very much, the code, You sent seems to work perfect.

Shall I give another question please?

When I let the code run in debug perspective on full speed, it is OK.

But, when I try to single step, at the moment I enable the clock for CTimer0, debugging is not more possible. The connection between MCUXpresso and MCU-Link Pro is broken:

Bela1_0-1719993924560.png

It only happens when I try to watch the CTimer0 registers.

Is this the normal behavior of this setup, or there's still something wrong?

0 件の賞賛
返信
6,541件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I have tried to run the void CTimerInit(void) code on my LPC5536-EVK board based on MCUXPrresso tools step by step,

I have not problem.

Maybe it is related to probe

BR

XiangJun Rong

0 件の賞賛
返信
6,640件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I suppose that the line is incorrect.

#define TIMER0_CLK_EN 1<<26

SYSCON -> AHBCLKCTRLSET[1] |= TIMER0_CLK_EN ;

You can write it as:

SYSCON -> AHBCLKCTRLSET[1] = TIMER0_CLK_EN ;

or

SYSCON -> AHBCLKCTRL[1] |= TIMER0_CLK_EN ;

After you set the bit 26 of SYSCON -> AHBCLKCTRL[1] , you can access the CTimer0 register.

The target of SYSCON->CTIMERGLOBALSTARTEN register is that all the CTimer modules can synchronize if they use the same clock as tick.

Ctimerx clock diagram for LPC553x:

xiangjun_rong_0-1719814501733.png

 

Hope it can help you

BR

XiangJun Rong

0 件の賞賛
返信