PWM What is PWM signal A square wave

  • Slides: 17
Download presentation

PWM • What is PWM signal? • A square wave form with two parameters:

PWM • What is PWM signal? • A square wave form with two parameters: • 1. PWM period (TPWM) and 2. Duty cycle (d)

 • The duty cycle is defined as the percentage of digital ‘high’ to

• The duty cycle is defined as the percentage of digital ‘high’ to digital ‘low + high ’ signals present during a PWM period. It is shown in the figure below, (10%, 50%, 90%). • The PWM resolution is defined as the maximum number of pulses that you can pack into a PWM period. • The PWM period is an arbitrarily time period in which PWM takes place. It is chosen to give best results for your particular use.

Duty cycle/ Duty Time • Duty time is the ‘ON’ time in one period.

Duty cycle/ Duty Time • Duty time is the ‘ON’ time in one period. (td). • td<TPWM • Duty cycle can be determined using following eq. :

Uses of PWM • 1) Create an analog output voltage level digitally. PWM can

Uses of PWM • 1) Create an analog output voltage level digitally. PWM can adjust the average value of the output voltage. – Thermal system – DC Motor speed controllers – Lighting control – Any application where you need a variable DC voltage • 2) To digitally create analog signals for arbitrary waveforms, sounds, music and speech.

SMPS application • System is a DC-DC converter that regulates the output power. Power-electronic

SMPS application • System is a DC-DC converter that regulates the output power. Power-electronic switch is used as a chopper to adjust the average value of the output voltage. PWM signal is applied to the control input (for MOSFET: gate). • System has high efficiency, high performance and smaller size if it is compared to linear regulators. • Duty ratio of the pwm signal is controlled by u. C according to the output voltage feedback. • The higher PWM frequencies produce smoother output DC voltage. However high PWM frequency increases the susceptibility to voltage noises.

Produce a Sine-Wave Using PWM Signal

Produce a Sine-Wave Using PWM Signal

Produce a Sine-Wave Using PWM Signal

Produce a Sine-Wave Using PWM Signal

PWM Signal Generation

PWM Signal Generation

Before&After Filtering The filter output for higher frequency PWM input.

Before&After Filtering The filter output for higher frequency PWM input.

STM 32 F 4 x PWM operation • The timer modules are used to

STM 32 F 4 x PWM operation • The timer modules are used to generate PWM signals • Most of timer modules has output channels that are assigned to I/O pins. • Most of them are defined as Auxiliary Function pins.

Output Pins of Timer Module Channels The channel list fot TMR 1 and TMR

Output Pins of Timer Module Channels The channel list fot TMR 1 and TMR 2 can be seen below. The complete channel list can be seen on table. 9 in the STM 32 f 4 x datasheet (Doc#: Doc. ID 022152 Rev 4 ).

Adjusting the PWM Signal 1. A PWM output channel should be selected 2. Proper

Adjusting the PWM Signal 1. A PWM output channel should be selected 2. Proper clock signals are applied RCC_APB 1 Periph. Clock. Cmd(RCC_APB 1 Periph_TIM 4, ENABLE); // IO PD 15 is selected and it is PD 15 is connected to TMR 4 channel 4. => corresponding timer should be clocked – /* LED is on GPIOD, We want the LED connected to PD 15 should blink*/ – RCC_AHB 1 Periph. Clock. Cmd(RCC_AHB 1 Periph_GPIOD, ENABLE); – GPIO_Init. Structure. GPIO_Pin = GPIO_Pin_15; //PD 15 is selected – GPIO_Init. Structure. GPIO_Mode = GPIO_Mode_AF; //Auxiliary mode is seleceted. // (Not input or not output or not Analog) – GPIO_Init. Structure. GPIO_Speed = GPIO_Speed_100 MHz; – GPIO_Init. Structure. GPIO_OType = GPIO_OType_PP; // push pull output (not open //drain). – GPIO_Init. Structure. GPIO_Pu. Pd = GPIO_Pu. Pd_UP ; // Pull up enable – GPIO_Init(GPIOD, &GPIO_Init. Structure); – GPIO_Pin. AFConfig(GPIOD, GPIO_Pin. Source 15, GPIO_AF_TIM 4); // PD 15 is connected to TMR 4 channel 4. => Configure PD 15 auxiliary mode for TIM 4. (GPIO_AF_TIM 4) –

2. The corresponding timer is adjusted according to the required PWM period: – /*

2. The corresponding timer is adjusted according to the required PWM period: – /* Time base configuration */ – TIM_Time. Base. Structure. TIM_Period = 1000; // a timer period is divided into 1000 pieces. – TIM_Time. Base. Structure. TIM_Prescaler = (int) ((System. Core. Clock /2) / 50000) - 1; – TIM_Time. Base. Structure. TIM_Clock. Division = 0; – TIM_Time. Base. Structure. TIM_Counter. Mode = TIM_Counter. Mode_Up; – TIM_Time. Base. Init(TIM 4, &TIM_Time. Base. Structure); • Here timer 4 is adjusted to 1/50 msec x 1000=1/50 sec. Therefore PWM period is adjusted as 20 msec. and 20 msec is divided into 1000 A PWM period has 1000 x 0. 02 msec. time slots.

3. Set the output channel of the timer: Use TIM_OCInit. Structure, TIM_OCXInit function and

3. Set the output channel of the timer: Use TIM_OCInit. Structure, TIM_OCXInit function and TIM_OCXPreload. Config function. Here X is channel number. – – – – /* PWM 1 Mode configuration: Channel 4 */ TIM_OCInit. Structure. TIM_OCMode = TIM_OCMode_PWM 1; TIM_OCInit. Structure. TIM_Output. State = TIM_Output. State_Enable; TIM_OCInit. Structure. TIM_Pulse = 0; TIM_OCInit. Structure. TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC 4 Init(TIM 4, &TIM_OCInit. Structure); // The settings are loaded to output channel 4 (OC 4) of TIMER 4. (Remember PD 15 is connected to TMR 4 -OC 4) TIM_OC 4 Preload. Config(TIM 4, TIM_OCPreload_Enable); 4. Adjust the Duty cycle: Use TIM_Set. Compare. X function. Here X is channel number. Remember a timer period is divided into 1000, if 25% duty is required 250 of them should be ‘ 1’ and the rest should be ‘ 0’ – TIM_Set. Compare 4(TIM 4, 250); // 25% duty cycle Examine the test_PWM. c file in detail…