Pulse width modulator for LPC chip not auto-limiting

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

Pulse width modulator for LPC chip not auto-limiting

Jump to solution
1,653 Views
jDrum
Contributor III

Hello,

My code for the PWM (shown below) works OK but does not auto limit.  That is: the MATCHREL[0].L = 65000 has no effect.

My guess is that the auto limit works only for the SCT clock and we are using the BUSCLK.  When I select SCT_CONFIG_CLKMODE_SCTCLK instead, there is no PWM activity.

The code references the "simple PWM" from AN11538_SCTimer_PWM_Cookbook v5.0.pdf.

What are we doing wrong?

jDrum

 

//*********************
/* Chip specific SCT setup - clocks and peripheral reset
There are a lot of registers in the SCT peripheral. Performing
the reset allows the default states of the SCT to be loaded, so
we don't need to set them all and rely on defaults when needed. */
Chip_SCT_Init(LPC_SCT0);

/* SCT1_OUT3 on PIO1_13 mapped to FUNC2 Sample_Pump_Gate */
Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 13, (IOCON_FUNC2 ));


/* Configure the SCT as a 16 bit counter using the bus clock */
LPC_SCT0->CONFIG = SCT_CONFIG_16BIT_COUNTER | SCT_CONFIG_CLKMODE_BUSCLK;


LPC_SCT0->CTRL_L |= ((12-1) << 5); //prescaler is the number in parenthesis

LPC_SCT0->MATCHREL[0].L = 65000; //AUTOMATIC LIMIT??
LPC_SCT0->MATCHREL[1].L = 10000;

LPC_SCT0->EVENT[0].STATE = 0xffffffff; //all states
LPC_SCT0->EVENT[1].STATE = 0xffffffff; //all states

LPC_SCT0->EVENT[0].CTRL = (1<<12); //condition 1 only
LPC_SCT0->EVENT[1].CTRL = (1<<0) | (1<<12); //condition 1 only

LPC_SCT0->OUT[3].SET = (1 << 0); // event 0 will set SCTx_OUT0
LPC_SCT0->OUT[3].CLR = (1 << 1);
/* Initial CTOUT0 state is high */
LPC_SCT0->OUTPUT = 0; //(8 << 0);
LPC_SCT0->RES = (1<<2); // CLEAR ON CONFLICT


LPC_SCT0 -> CTRL_L &= ~(1<<2); // un-halt

 

0 Kudos
1 Solution
1,606 Views
jDrum
Contributor III

Hello Alice,

Thank you for the help. 

We added the line LPC_SCT0->CONFIG |= (1<<17);  //this is the autolimit flag

as you suggested.  The PWM routine now works.

The .h file needs more entries.  The AN11538_SCTimer_PWM_Cookbook v5.0.pdf. also mentions this flag but without explanation.

 

 

View solution in original post

Tags (1)
0 Kudos
6 Replies
1,607 Views
jDrum
Contributor III

Hello Alice,

Thank you for the help. 

We added the line LPC_SCT0->CONFIG |= (1<<17);  //this is the autolimit flag

as you suggested.  The PWM routine now works.

The .h file needs more entries.  The AN11538_SCTimer_PWM_Cookbook v5.0.pdf. also mentions this flag but without explanation.

 

 

Tags (1)
0 Kudos
1,632 Views
jDrum
Contributor III

Hi Alice,

The chip is LPC11U68, and we are running on our own PCB using Link2.

The frequency of the PWM is 61Hz which corresponds to no auto limit. If we change the prescaler, the frequency changes by the expected factor of two. With the set up we sent, a duty cycle of 0 works OK. We did not test the upper range, but will stay in the ~10000 range (and also 0) for the duty cycle.

It would be nice to control the frequency by using the auto limit feature because we need to sync with other data acquire tasks.

We also tried to write to the timer but it didn't have any effect.

Thank you, jDrum

0 Kudos
1,621 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello  jDrum,

The Auto limit register is in  SCT configuration register-> AUTOLIMIT, have you config it?

Alice_Yang_0-1632471101495.png

 

BR

Alice

 

0 Kudos
1,612 Views
jDrum
Contributor III

Thank you Alice,

Looking at SCT_11U6x.h :

The .h file that is in our download does not mention AUTOLIMIT_L.  The closest topic I found had to do with setting the SCT count itself. 

/**
* @brief Set lower count value in State Configurable Timer
* @param pSCT : The base of SCT peripheral on the chip
* @param count : The 16-bit count value
* @return Nothing
*/
STATIC INLINE void Chip_SCT_SetCountL(LPC_SCT_T *pSCT, uint16_t count)
{
pSCT->COUNT_L = count;
}

There is also a define:

#define COUNTUP_TO_LIMIT_THEN_CLEAR_TO_ZERO 0     /*!< Direction for  counter */

I assume that this would be bit 0 (1<<0) in the ->CONFIG

We will try to get one of these to work.

jDrum

0 Kudos
1,611 Views
jDrum
Contributor III

Also,   setting the clock to SCT never worked.  We are using the BUS clock instead.

LPC_SCT0->CONFIG = SCT_CONFIG_16BIT_COUNTER | SCT_CONFIG_CLKMODE_BUSCLK;

jDrum

0 Kudos
1,638 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello jDrum,

Which chip? Please share your whole project , I will check it on my side, thanks.

 

BR

Alice

0 Kudos