Software AN3301
32/35 Doc ID 18161 Rev 1
2.6.5 PWM initialization and interrupt handling
The following is an example for PWM initialization and interrupt servicing routine.
A: Initialization
void STMPE812A_PWM_Initialization (void) {
/*Enabling the Soft Reset in the System Control Register (0x03)*/
STMPE812A_SoftReset ();
/*Enabling the PWM and GPIO Clocks in the System Control Register (0x03)*/
STMPE812A_SetClock (STMPE812A_ENABLE, STMPE812A_PWM_CLK|STMPE812A_GPIO_CLK);
/*Setting the Port - 2 as a special function in the Port Function Control Register
(0x04)*/
STMPE812A_SetPortFunction (STMPE812A_PORT2, STMPE812A_PORT_FUNC_SPECIAL_FUNC);
/*Setting the Port - 1 as a special function in the Port Function Control Register
(0x04)*/
STMPE812A_SetPortFunction (STMPE812A_PORT1, STMPE812A_PORT_FUNC_SPECIAL_FUNC);
/*Setting the Burst_Length [1:0] as ‘8mS’ in the PWMClockDiv Register (0x50) */
STMPE812A_SetPWMBurstLengh (STMPE812A_PWM_BURSTLENGTH_8MS);
/*Setting the Div [4:0] value as ‘0’ in the PWMClockDiv Register (0x50)
respectively*/
STMPE812A_SetPWMClockDivider (0);
/*Setting the Brightness [7:4] as ‘Duty Cycle Ratio 8: 8 (50.00%)’, BurstMultiplier
[3:2] value as ‘1’ and Off_State [1] as ‘PWM Output “LOW” when PWM not running’ in
the PWMControl1 Register (0x51) respectively*/
STMPE812A_ConfigurePWM (STMPE812A_PWM_DUTY_CYCLE_50_00, 1,
STMPE812A_PWM_OFF_STATE_HIGH);
/*Setting the INT_Mode [7] as ‘Normal Interrupt Mode’ in the Interrupt Control
Register (0x08)*/
STMPE812A_SetInterruptMode(STMPE812A_INT_MODE_NORMAL);
/*Setting the INT_Type [1] as ‘Level Interrupt Type’ in the Interrupt Control
Register (0x08)*/
STMPE812A_SetInterruptType (STMPE812A_INT_TYPE_LEVEL);
/*Enabling the Global Interrupt in the Interrupt Control Register (0x08)*/
STMPE812A_EnableGlobalInterrupt (TRUE);