Hello,
I tried the following code in the LPCxpresso824 board, and the signal of the PWM (pins 12 and 16) is alright, however the signal of the timer (pin 27) is always high when what I want is toogle the output. I tryied with diferent match, diferent events the result is always the same, the pwm works the timer not. I following by the examples in the application note that are in the previous link of this conversation. What I'm doing wrong?
Code_main function:
Config_inputs_outputs();
//timer
Chip_SCT_Init(LPC_SCT);
Chip_SCT_Config(LPC_SCT, SCT_CONFIG_32BIT_COUNTER ); /* UNIFIED */
Chip_SCT_SetMatchCount(LPC_SCT, SCT_MATCH_1, (SystemCoreClock/100)); /* match_1_ */
Chip_SCT_SetMatchReload(LPC_SCT, SCT_MATCH_1, (SystemCoreClock/100));
/* EVENT registers */
Chip_SCT_EventState(LPC_SCT, SCT_EVENT_0, ENABLE_STATE0); /* U: --> state U_ENTRY */
Chip_SCT_EventControl(LPC_SCT, SCT_EVENT_0, (CHIP_SCT_EVENTCTRL_T) ( SCT_EVECTRL_MATCH1 | SCT_COMBMODE_MATCH | SCT_STATELD_1 | SCT_STATEEV_0 ));
Chip_SCT_EnableEventInt(LPC_SCT, SCT_EVT_0);
LPC_SCT->LIMIT_L = 0x00000001;
NVIC_EnableIRQ(SCT_IRQn); /* enable SCT interrupt */
Chip_SCT_ClearControl(LPC_SCT , SCT_CTRL_HALT_L);
//PWM
/* Initialize the SCT as PWM and set frequency */
Chip_SCTPWM_Init(LPC_SCT);
Chip_SCTPWM_SetRate(LPC_SCT, 10000); /* PWM frequency 10 KHz */
/* Setup Board specific output pin */
/* Enable SWM clock before altering SWM */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
/* Connect SCT output 0 to LED pin PIO12, SCT output 1 to LED pin PIO16 */
Chip_SWM_MovablePinAssign(SWM_SCT_OUT1_O, 12);
Chip_SWM_MovablePinAssign(SWM_SCT_OUT0_O, 16);
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
/* Use SCT0_OUT1 pin */
Chip_SCTPWM_SetOutPin(LPC_SCT, 1, 1);
Chip_SCTPWM_SetOutPin(LPC_SCT, 2, 0);
/* Start with 0% duty cycle */
Chip_SCTPWM_SetDutyCycle(LPC_SCT, 1, Chip_SCTPWM_GetTicksPerCycle(LPC_SCT) / 2);
Chip_SCTPWM_SetDutyCycle(LPC_SCT, 2, 0);
Chip_SCTPWM_Start(LPC_SCT);
IRQ_function()
void SCT_IRQHandler (void)
{
/* SCT Interrupt Handler (10 msec) */
static uint8_t cnt = 0;
Chip_GPIO_SetPinToggle(LPC_GPIO_PORT,0, 27); /* toggle pin P0_27 */
Chip_SCT_ClearEventFlag(LPC_SCT, SCT_EVT_0); /* clear event 0 flag */
}