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