For LPC54628 you need to link J14 pin (P3_31) to SCT0,OUT5. See Code below from pin_mux.c
- {pin_num: J14, peripheral: SCT0, signal: 'OUT, 5', pin_signal: PIO3_31/FC9_RTS_SCL_SSEL1/SCT0_OUT5/CTIMER4_MAT2/SCT0_GPI0/EMC_A(20)}
IOCON->PIO[3][31] = ((IOCON->PIO[3][31] &
/* Mask bits to zero which are setting */
(~(IOCON_PIO_FUNC_MASK | IOCON_PIO_DIGIMODE_MASK)))
/* Selects pin function.
* : PORT331 (pin J14) is configured as SCT0_OUT5. */
| IOCON_PIO_FUNC(PIO331_FUNC_ALT2)
/* Select Analog/Digital mode.
* : Digital mode. */
| IOCON_PIO_DIGIMODE(PIO331_DIGIMODE_DIGITAL));
SCT0 and PWM initialization in peripherals.c
/***********************************************************************************************************************
* SCT0 initialization code
**********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'SCT0'
- type: 'sctimer'
- mode: 'basic'
- custom_name_enabled: 'false'
- type_id: 'sctimer_7973000102117ff9c4fa4742aaf3ccb0'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'SCT0'
- config_sets:
- main:
- config:
- clockMode: 'kSCTIMER_System_ClockMode'
- clockSource: 'SynchronousFunctionClock'
- clockSourceFreq: 'BOARD_BootClockPLL180M'
- SCTInputClockSourceFreq: 'custom:0'
- clockSelect: 'kSCTIMER_Clock_On_Rise_Input_0'
- enableCounterUnify: 'true'
- enableBidirection_l: 'false'
- enableBidirection_h: 'false'
- prescale_l: '1'
- prescale_h: '1'
- outInitState: 'SCTIMER_OUTPUT_5_MASK'
- inputsync: ''
- enableIRQ: 'false'
- interrupt:
- IRQn: 'SCT0_IRQn'
- enable_interrrupt: 'enabled'
- enable_priority: 'false'
- priority: '0'
- enable_custom_name: 'false'
- enableLTimer: 'false'
- enableHTimer: 'false'
- pwms:
- 0:
- output: 'kSCTIMER_Out_5'
- level: 'kSCTIMER_HighTrue'
- dutyCyclePercent: '10'
- pwmMode: 'kSCTIMER_EdgeAlignedPwm'
- pwmFrequency: '1000'
- events: []
- states:
- 0:
- pwms: 'pwm0'
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
const sctimer_config_t SCT0_initConfig = {
.enableCounterUnify = true,
.clockMode = kSCTIMER_System_ClockMode,
.clockSelect = kSCTIMER_Clock_On_Rise_Input_0,
.enableBidirection_l = false,
.enableBidirection_h = false,
.prescale_l = 0U,
.prescale_h = 0U,
.outInitState = (uint8_t)(SCT0_OUTPUT_5),
.inputsync = 0U
};
const sctimer_pwm_signal_param_t SCT0_pwmSignalsConfig[1] = {
{
.output = kSCTIMER_Out_5,
.level = kSCTIMER_LowTrue,
.dutyCyclePercent = 100U // 100% means backlight off
}
};
uint32_t SCT0_pwmEvent[1];
static void SCT0_init(void) {
SCTIMER_Init(SCT0_PERIPHERAL, &SCT0_initConfig);
/* Initialization of state 0 */
SCTIMER_SetupPwm(SCT0_PERIPHERAL, &SCT0_pwmSignalsConfig[0], kSCTIMER_EdgeAlignedPwm, 1000U, SCT0_CLOCK_FREQ, &SCT0_pwmEvent[0]);
/* Start the timer */
SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_U);
SCTIMER_UpdatePwmDutycycle(SCT0_PERIPHERAL, kSCTIMER_Out_5, 1U, SCT0_pwmEvent[0]); // backlight full brightness
//SCTIMER_UpdatePwmDutycycle(SCT0_PERIPHERAL, kSCTIMER_Out_5, 50U, SCT0_pwmEvent[0]); // backlight half brightness
//SCTIMER_UpdatePwmDutycycle(SCT0_PERIPHERAL, kSCTIMER_Out_5, 100U, SCT0_pwmEvent[0]); // backlight off
}
BacklightPWM.c which has function for changing duty cycle of PWM signal
void Blacklight_Brightness(uint8_t level)
{
if (level <= 0) {level = 1;}
if (level >100) {level = 100; }
uint8_t dutyCyclePercent = 101-level;
SCTIMER_UpdatePwmDutycycle(SCT0_PERIPHERAL, kSCTIMER_Out_5, dutyCyclePercent, SCT0_pwmEvent[0]);
}
I added the following code to ewmain.c
// Add timer for backlight dimming
#include "BacklightPWM.h"
#include "FreeRTOS.h"
#include "timers.h"
TimerHandle_t xTimerBacklight;
bool Backlight_dimmed = false;
void vTimerCallback( TimerHandle_t xTimer )
{
// Lower backlight intensity
Blacklight_Brightness(25);
Backlight_dimmed = true;
}
int EwInit( void )
{
.
.
EMWI code
.
.
// create backlight timer
xTimerBacklight = xTimerCreate( /* Just a text name, not used by the RTOS
kernel. */
"TimerBacklight",
/* The timer period in ticks, must be
greater than 10*60*1000 = 10 min */
600000 / portTICK_PERIOD_MS,
/* The timers will auto-reload themselves
when they expire. */
pdTRUE,
/* The ID is used to store a count of the
number of times the timer has expired, which
is initialised to 0. */
( void * ) 0,
/* Each timer calls the same callback when
it expires. */
vTimerCallback);
// Start the timer
xTimerStart( xTimerBacklight, 0);
return 1;
}
int EwProcess( void )
{
int timers = 0;
int signals = 0;
int events = 0;
int devices = 0;
XEnum cmd = CoreKeyCodeNoKey;
int noOfTouch;
XTouchEvent* touchEvent;
int touch;
int finger;
XPoint touchPos;
.
.
.
EMWI code
.
.
if ( noOfTouch > 0 )
{
for ( touch = 0; touch < noOfTouch; touch++ )
{
.
.
EMWI code
.
.
}
xTimerReset( xTimerBacklight , 0);
if(Backlight_dimmed)
{
// increase backlight intensity
Blacklight_Brightness(100);
}
}
.
.
.
EMWI code
.
.
return 1;
}