4 – pwm output code examples – Maxim Integrated DS4830A Optical Microcontroller User Manual
Page 137
DS4830A User’s Guide
137
14.4 – PWM Output Code Examples
14.4.1 – 9-Bit PWM Output and Pulse Spreading (PS[1:0]= 11, 1-Slot) with Core Clock
Creating a 25% duty cycle with ~20kHz frequency PWM output at Channel 0 (default location):
//PWM Configuration for PW0
PWMCN = 0x0000; //Channel 0, Duty cycle
PWMDATA = 0x007F; //25% Duty cycle for 9-bit resolution
PWMCN = 0x0001; //Channel 0, Config register
PWMDATA = 0x1002; //Default location, 9-bit resolution with core clock with 1-slot pulse spreading, PWMEN
PWMCN = 0x0003; //Channel 0, Delay Configuration
PWMDATA = 0x0000; //No delay
PWMCN_bit.UPDATE = 1; //Update PWM duty cycle
PWMCN_bit.M_EN = 1; //Master Enable
14.4.2 – 9-Bit PWM Output and Pulse Spreading (PS[1:0]= 11, 4-Slots) with Core Clock
Creating a 40% duty cycle with 78.125kHz frequency PWM output at Channel 1 (default location):
//PWM Configuration for PW1
PWMCN = 0x0010; //Channel1 Duty cycle
PWMDATA = 0x00CD; //40% Duty cycle for 9-bit resolution with core clock
PWMCN = 0x0011; //Channel 1Config register
PWMDATA = 0x1032; //Default location, 9-bit resolution with core clock with 4-slot pulse spreading, PWMEN
PWMCN = 0x0013; //Channel 1 Delay Configuration
PWMDATA = 0x0000; //No delay
PWMCN_bit.UPDATE = 1; //Update PWM duty cycle
PWMCN_bit.M_EN = 1; //Master Enable
14.4.3 – 12-Bit PWM Output and Pulse Spreading (PS[1:0]= 01, 8-Slots) with Alternate Location and
Peripheral Clock
Creating a 25% duty cycle with 156.25kHz frequency PWM output at Channel 1 (alternate location) with Peripheral
Clock:
//PWM Configuration for PW1
PWMCN = 0x0010; //Channel 1 Duty cycle
PWMDATA = 0x03FF; //25% Duty cycle for 12-bit resolution
PWMCN = 0x0011; //Channel 1 Config register
PWMDATA = 0x3215; //Alternate location (PW1, Port 2.1), 12-bit resolution with peripheral clock with 8-slot pulse spreading, PWMEN
PWMCN = 0x0013; //Channel 1 Delay Configuration
PWMDATA = 0x0000; //No delay
PWMCN_bit.UPDATE = 1; //Update PWM duty cycle
PWMCN_bit.M_EN = 1; //Master Enable