Problem with SCtimer

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

Problem with SCtimer

Jump to solution
674 Views
pavelhudecek
Contributor III

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.

Labels (2)
Tags (1)
0 Kudos
1 Solution
464 Views
pavelhudecek
Contributor III

Update:

I found that registers SCT1 behave as read-only.

I added this code to the startup:

Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SCT0_1);

But SCT1 registers are still treated as read-only.

I noticed that I2C is during initialization resets yet, so I tried it with the SCT:

Chip_SYSCTL_PeriphReset(RESET_SCT1);

Bingo!
Now it works properly.

View solution in original post

1 Reply
465 Views
pavelhudecek
Contributor III

Update:

I found that registers SCT1 behave as read-only.

I added this code to the startup:

Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SCT0_1);

But SCT1 registers are still treated as read-only.

I noticed that I2C is during initialization resets yet, so I tried it with the SCT:

Chip_SYSCTL_PeriphReset(RESET_SCT1);

Bingo!
Now it works properly.