PWM

From ThaiEasyElecWiki
Jump to: navigation, search

PWM driver is provided for buzzer and LCD backlight control. Mini SUN7 doesn't have on-board buzzer but necessary functions are nested in the code. Defining BUZZ_PIN will enable buzzer function, but the user has to provide all necessary register definitions. Code below is an example when the buzzer is controlled using P1.11 which is PWM[0].6.

#define BUZZ_PWM			0
#define BUZZ_PWM_PORT		6

#define BUZZ_DPRT			LPC_GPIO1->DIR
#define BUZZ_PRTS			LPC_GPIO1->SET
#define BUZZ_PRTC			LPC_GPIO1->CLR
#define BUZZ_PIN			11UL

Please note that the user has to select function PWM for the port manually. For example:

LPC_IOCON->P1_11 |= 3

And then to generate a beep, simply use buzz_start(buzz_type_t type). buzz_type are available in 4 patterns:

typedef enum
{
	SHORT_BEEP = 0,
	LONG_BEEP,
	BEEP_BEEP,
	BEEP_BEEP_BEEP
} buzz_type_t;

The backlight can be controlled using PWM function directly. All initializations is provided in TSLCDInit:

PWMSetFreq(LCD_ADJ_PWM,300);
PWMSetDuty(LCD_ADJ_PWM,LCD_ADJ_PWM_PORT,0);
PWMStart(LCD_ADJ_PWM);
PWMSetDuty(LCD_ADJ_PWM,LCD_ADJ_PWM_PORT,900);

The user can change backlight duty cycle for more or less brightness using the same function. Example below show how to decrease duty cycle to 50%.

PWMStop(LCD_ADJ_PWM);
PWMSetDuty(LCD_ADJ_PWM,LCD_ADJ_PWM_PORT,500);
PWMStart(LCD_ADJ_PWM);
Personal tools
Namespaces
Variants
Actions
Navigation
Articles and Tutorials
Shortcut (mini SUN7)
Toolbox