AnsweredAssumed Answered

Problem with SCtimer

Question asked by Pavel Hudeček on Oct 18, 2016
Latest reply on Oct 18, 2016 by Pavel Hudeček

Hi, i using LPC11U68JBD100 on custom board.

 

Pin 52 (P2_18) is connected to the gate of the MOSFET switching speaker.

 

Pin initialization:

#define AUD_port 2
#define AUD_pin1 18

 

Chip_IOCON_PinMuxSet(LPC_IOCON, AUD_port, AUD_pin1, IOCON_FUNC1);
Chip_GPIO_SetPinDIROutput(LPC_GPIO, AUD_port, AUD_pin1);
Chip_GPIO_SetPinState(LPC_GPIO, AUD_port, AUD_pin1, 0);

 

I copied this code from AN11538, i changed the frequency to 1 kHz, timer to SCT1 and output to 2:

#define LPC_SCT LPC_SCT1

 

LPC_SCT->CONFIG |= 1; // unified timer
LPC_SCT->MATCHREL[0].U = (SystemCoreClock/1000)-1; // match 0 @ 10 Hz = 100 msec
LPC_SCT->EVENT[0].STATE = (1 << 0); // event 0 only happens in state 0
LPC_SCT->EVENT[0].CTRL = (0 << 0) | // related to match 0
(1 << 12) | // COMBMODE[13:12] = match condition only
(1 << 14) | // STATELD[14] = STATEV is loaded into state
(1 << 15); // STATEV[15] = 1 (new state is 1)
LPC_SCT->EVENT[1].STATE = (1 << 1); // event 1 only happens in state 1
LPC_SCT->EVENT[1].CTRL = (0 << 0) | // related to match 0
(1 << 12) | // COMBMODE[13:12] = match condition only
(1 << 14) | // STATELD[14] = STATEV is loaded into state
(0 << 15); // STATEV[15] = 0 (new state is 0)
LPC_SCT->OUT[2].SET = (1 << 0); // event 0 will set SCT_OUT0
LPC_SCT->OUT[2].CLR = (1 << 1); // event 1 will clear SCT_OUT0
LPC_SCT->LIMIT_L = 0x0003; // events 0 and 1 are used as counter limit
LPC_SCT->CTRL_L &= ~(1 << 2); // unhalt by clearing bit 2 of CTRL register

Afther I run this code, speaker not beeping. The pin is all time on zero.

 

If I skip change of IOCON at startup, and I only periodically switching port, the speaker beeping.

Outcomes