Escolar Documentos
Profissional Documentos
Cultura Documentos
PEMROGRAMAN
MIKROKONTROLER LANJUT
Materi
1. A Conceptual of Power Electronics Device and Control System based on microcontroller
2. Controlling DC–DC Converters (SMPS) with Microcontroller (Concept of isolated controller for DC-DC Converter)
3. Controlling DC–DC Converters (SMPS) with Microcontroller (Design of Voltage and Current Sensor )
4. Controlling DC–DC Converters (SMPS) with Microcontroller (Concept of programmable DC power supply)
5. Controlling DC–DC Converters (SMPS) with Microcontroller (Concept of DC-DC converter for PV MPPT)
6. Controlling DC–AC Converters (Inverter) with Microcontroller
7. Controlling DC–AC Converters (Inverter) with Microcontroller (Scalar Control)
8. Digital Firing Angle Control of Thyristor with Microcontroller
9. UART Serial Communication (Pooling method)
10. UART Serial Communication (Interrupt method)
11. UART Serial Communication (DMA method)
12. Programming Microcontroller with Matlab (Simulink & Waijung Blockset)
13. Programming Microcontroller with Matlab (LCD Character and ADC)
14. Programming Microcontroller with Matlab Regular DAC and Arbitrary Waveform Generator
15. Programming Microcontroller with Matlab Basic PWM and Advanced PWM
16. Programming Microcontroller with Matlab Timer Encoder And Timer Capture
2
1
12/17/2016
Ilmu Pendukung
Belajar mikrokontroler lanjutan memerlukan ilmu
pendukung yang lain untuk meng-aplikasikan ke sistem
elektronik yang kompleks, diantaranya:
• Bahasa Pemrograman
• Rangkaian Listrik.
• Rangkaian Elektronika.
• Elektronika digital.
• Elektronika Daya.
• Teknik sistem kendali/teknik pengaturan
2
12/17/2016
Minggu Ke - 1
3
12/17/2016
PC or
High Level
Controller
device
Microcontroller,
FPGA, etc IGBT, MOSFET
4
12/17/2016
5
12/17/2016
PS9552
Example
IGBT/MOSFET
Gate Driver
11
FOD3182 PS9552 TLP250
12
6
12/17/2016
Setting Dead-Time
• The inverter control circuit
provides output to drive its
load by switching IGBT1
(Upper Arm) and IGBT2
(Lower Arm) alternately on
and off .
• If the dead-time is
insufficient, IGBT1 and
IGBT2 could both switch on,
causing a short-circuit Normal Operation of the Short Circuit of the Inverter
current and breakdown Inverter Control Circuit Control Circuit
of the IGBTs
13
Setting Dead-Time
14
7
12/17/2016
15
Current sharing resistors used to Isolating diodes used for parallel Outputs connected in series include
parallel two converters redundant connection of two converters reverse voltage protection diodes
16
8
12/17/2016
17
18
9
12/17/2016
19
20
10
12/17/2016
21
22
11
12/17/2016
23
24
Transformerless Power Supply
12
12/17/2016
Minggu Ke - 2
25
26
13
12/17/2016
27
Control
28
14
12/17/2016
Control
29
15
12/17/2016
32
GND for Control Side
16
12/17/2016
GND for
GND for IGBT/MOSFET
IGBT/MOSFET (floating)
(floating)
33
GND for Control Side
Concept of isolated controller for
DC-DC Converter
34
GND for Control Side
17
12/17/2016
Voltage Sensor
differential
ampifier
GND for Control Side
GND for Isolation
35
Amplifier (floating)
Concept of isolated controller for
differential
ampifier
GND for Control Side
GND for Isolation
36
Amplifier (floating)
18
12/17/2016
GND
GND for Power Side for IGBT/MOSFET Voltage Sensor
DC-DC Converter
Driver (floating)
differential
ampifier
38
19
12/17/2016
39
40
20
12/17/2016
41
42
21
12/17/2016
43
44
22
12/17/2016
45
46
23
12/17/2016
Minggu Ke - 3
47
48
24
12/17/2016
Current
Current is the rate of electric charge through a point. The unit of measure is the Ampere or Amp (A)
Resistance
Given a piece of conducting material connected to a voltage difference V, which drives through it a
current I, the resistance is defined as
Power
The power dissipated by a resistor is
49
50
25
12/17/2016
51
52
26
12/17/2016
53
The differential output of the AMC1200 can either directly drive an analog-to-digital converter
(ADC) input or cane further filtered before being processed by the ADC. 54
27
12/17/2016
28
12/17/2016
R-Shunt as
Isolated
current sensor
Voltage divider as
voltage sensor
57
shunt-based current sensing in smart electricity meter (e-meter)
58
29
12/17/2016
Vsen= ∗ Vs= ∗
Vsen = ∗ _
Vs= ∗ ∗ _
59
Vsen= ∗ P=
.
Vsen= ∗ 60
. P=
. .
Vsen= ∗ 60
.
Vsen= 0.05564 ∗ 60 P=
.
Vsen= 3.3384 P= 60.70
30
12/17/2016
Vsen= ∗ P=
Vsen= ∗ 60
P=
Vsen= ∗ 60
Vsen= 0.05564 ∗ 60 P=
Vsen= 3.3384 P= 0.06070
Vrsh = ℎ∗ ℎ Prsh = ℎ ∗ ℎ
Vrsh = 10 ∗ 1 Prsh = 10 ∗ 1
Vrsh = 10 Prsh = 100
31
12/17/2016
Vrsh = ℎ∗ ℎ Prsh = ℎ ∗ ℎ
Vrsh = 10 ∗ 0.1 Prsh = 10 ∗ 0.1
Vrsh = 1 Prsh = 10
63
Vrsh = ℎ∗ ℎ Prsh = ℎ ∗ ℎ
Vrsh = 10 ∗ 0.01 Prsh = 10 ∗ 0.01
Vrsh = 0.1 Prsh = 1
Rsh value are acceptable, but Rsh value are value are
need amplifier and high ADC acceptable
resulotion Low power dissipation
64
32
12/17/2016
65
66
33
12/17/2016
Minggu Ke - 4
67
68
34
12/17/2016
69
70
35
12/17/2016
Configure GPIO
for Multi channel ADC
71
72
36
12/17/2016
• Untuk memulai
pemrograman pada
MDK-ARM, Buka project
window, cari sub folder 1. Click
Application/User
kemudian buka main.c
• Selanjutnya anda harus
menambahkan file LCD 2. Click File lcd driver
driver yaitu : berhasil
• lcd_character.c ditambahkan
• lcd_character.h
3. Click
• Selanjutnya atur
inisialisasi LCD melalui
wizard
73
int main(void)
#include "stm32f4xx_hal.h" {
#include "lcd_character.h" char buffer[20];
#include "stdio.h“ HAL_Init();
/* Configure the system clock */
/* Private variables -------------------------*/ SystemClock_Config();
ADC_HandleTypeDef hadc1; /* Initialize all configured peripherals */
DMA_HandleTypeDef hdma_adc1; MX_GPIO_Init();
TIM_HandleTypeDef htim2; MX_DMA_Init();
MX_ADC1_Init();
__IO uint16_t ADC_value[8]; MX_TIM2_Init();
HAL_ADC_Start_DMA(&hadc1,(uint32_t*) &ADC_value,8);
/* Private function prototypes ---------*/ lcd_init();
void SystemClock_Config(void); lcd_gotoxy(0,0);
static void MX_GPIO_Init(void); lcd_puts("Tes ADC");
static void MX_DMA_Init(void); while (1)
static void MX_ADC1_Init(void); {
static void MX_TIM2_Init(void); sprintf(buffer,"P1 %4d P2 %4d",ADC_value[4],ADC_value[5]);
lcd_gotoxy(0,1);
lcd_puts(buffer);
HAL_Delay(100);
}
} 74
37
12/17/2016
PWM Frequency ?
Compare Value
Timer CNT
Timer_CNT_Clock
PWM Ouput
PWM period 75
PWM Frequency ?
_ ( )
( ) = (1)
_ ( )
= (2)
( )
76
38
12/17/2016
PWM Frequency ?
Timer 1 merupakan timer dibawah kendali APB 2 serpti pada gambar berikut :
77
PWM Frequency ?
PWM Frequency ?
MAX INTERFACE MAX TIMER
Timer Type Resolution Prescaler Channels APB
CLOCK CLOCK*
TIM1, TIM8 Advanced 16bit 16bit 4 SysClk/2 SysClk 2
TIM2, TIM5 General purpose 32bit 16bit 4 SysClk/4 SysClk, SysClk/2 1
TIM3, TIM4 General purpose 16bit 16bit 4 SysClk/4 SysClk, SysClk/2 1
TIM9 General purpose 16bit 16bit 2 SysClk/2 SysClk 2
TIM10, TIM11 General purpose 16bit 16bit 1 SysClk/2 SysClk 2
TIM12 General purpose 16bit 16bit 2 SysClk/4 SysClk, SysClk/2 1
TIM13, TIM14 General purpose 16bit 16bit 1 SysClk/4 SysClk, SysClk/2 1
TIM6, TIM7 Basic 16bit 16bit 0 SysClk/4 SysClk, SysClk/2 1
78
39
12/17/2016
PWM Frequency ?
Dalam hal ini, diasumsikan timer 1 menggunakan frekwensi yang paling tinggi sehingga dipilih pre scaler 0,
maka :
= è = 168000000
Karena counter pada microcontroller berupa bilangn bulat, maka semua perhitungan berlaku pembulatan kebawah
sehingga menjadi 16801, Timer CNT dihitung mulai 0 to 16800.
79
80
40
12/17/2016
81
10000
82
41
12/17/2016
83
84
42
12/17/2016
• Untuk memulai
pemrograman pada MDK-
ARM, Buka project
window, cari sub folder
Application/User 1. Click
kemudian buka main.c
• Selanjutnya anda harus
menambahkan file keypad
dan LCD driver yaitu :
• keypad_4x4.c
2. Click File lcd driver
• keypad_4x4.h berhasil
• lcd_character.c ditambahkan
• lcd_character.h
• Selanjutnya atur 3. Click
inisialisasi file keypad dan
LCD melalui wizard
85
1. Click
86
43
12/17/2016
88
44
12/17/2016
45
12/17/2016
91
46
12/17/2016
93
47
12/17/2016
95
Measure V, I
iref = 7.5; //example reference value
v_limit = 3.5; //example limit voltage
N iin=read_current_value();
V < V_imit
vin=read_voltage_value();
Y
if(vin < v_limit)
N
I <Iref { if(iin < iref) duty += DUTY_STEP;
else duty -= DUTY_STEP;
Y
}
Decrease Increase Decrease else duty -= DUTY_STEP;
Duty Cycle Duty Cycle Duty Cycle update_duty_cycle(duty);
}
END }
96
48
12/17/2016
97
98
49
12/17/2016
Minggu Ke - 5
99
100
50
12/17/2016
102
51
12/17/2016
Voltage Sensor
GND
for IGBT/MOSFET
Driver (grounded)
Controller Side
differential
ampifier
Current
measurement GND for Isolation
Amplifier (grounded)
103
Work flow
1. We need define CPU clcok
Clock Init
ADC_Init(); 2. We need Multi channel ADC to read Voltage and Current value
104
52
12/17/2016
float power,l_power;
#define MPPT_STEP 5
void mppt_PO(void)
{ float iin,vin;
iin=read_current_value();
vin=read_voltage_value();
power = vin * iin;
if(power < l_power) updown ^= 1;
if(!updown) vinref -= MPPT_STEP;
else vinref += MPPT_STEP;
l_power = power;
convert_vref_to_duty();
}
105
???
l_power = power;
l_vin = vin;
convert_vref_to_duty();
}
}
106
53
12/17/2016
INCREMENTAL CONDUCTANCE
float power,l_power;
#define MPPT_STEP 5
void mppt_INCCOND(void)
{
float delta_i,delta_v,delta_p;
float f_iin,f_vin;
iin=read_current_value();
vin=read_voltage_value();
power = f_iin * f_vin;
delta_p = power - l_power;
delta_i = f_iin - fl_iin;
delta_v = f_vin - fl_vin;
if(delta_v)
{
ineq = delta_p / delta_v;
if(ineq > 0) vinref += MPPT_STEP;
else if(ineq < 0) vinref -= MPPT_STEP;
}
else
{
if(delta_i > 0) vinref += MPPT_STEP;
else if(delta_i < 0) vinref -= MPPT_STEP;
}
fl_iin = f_iin;
fl_vin = f_vin;
l_power = power;
convert_vref_to_duty();
}
108
54
12/17/2016
???
l_power = power;
convert_vref_to_duty();
}
109
???
l_power = power;
convert_vref_to_duty();
}
110
55
12/17/2016
TEMPERATURE METHOD
float power,l_power;
#define MPPT_STEP 5
void mppt_combined_PO_CV(void)
{
float f_iin,f_vin;
???
l_power = power;
convert_vref_to_duty();
}
111
A B
Firefly algorithm
A B
112
56
12/17/2016
A B
113
MPPT Application for hybrid Charging
57
12/17/2016
116
58
12/17/2016
Minggu Ke - 6
117
118
59
12/17/2016
119
60
12/17/2016
PWM ADC
Microcontroller
121
122
61
12/17/2016
Single-Phase VSI
Three-Phase VSI
123
Setting Dead-Time
• The inverter control circuit
provides output to drive its
load by switching IGBT1
(Upper Arm) and IGBT2
(Lower Arm) alternately on
and off .
• If the dead-time is
insufficient, IGBT1 and
IGBT2 could both switch on,
causing a short-circuit Normal Operation of the Short Circuit of the Inverter
current and breakdown Inverter Control Circuit Control Circuit
of the IGBTs
124
62
12/17/2016
Setting Dead-Time
125
126
63
12/17/2016
127
128
64
12/17/2016
129
65
12/17/2016
131
132
66
12/17/2016
133
134
67
12/17/2016
135
136
68
12/17/2016
Vc
137
69
12/17/2016
(a) half-bridge bipolar PWM, (b) H-bridge unipolar PWM, and (c) three-phase VSI bipolar PWM.
139
(a) triangular carrier PWM and (b) sawtooth carrier PWM (right weighted). 140
70
12/17/2016
142
71
12/17/2016
143
144
72
12/17/2016
Minggu Ke - 7
145
146
73
12/17/2016
147
NFO is the natural field orientation
74
12/17/2016
= t è = ∗ t
Example
10
= 0.2
50
= 0.2
149
Speed
Scalar Control with V/f constant
2000
1500
1000
500
-500
300
200
100
-100
-200
-300
Vfset Vr
50
40
30
20
10
0 2 4 6 8 10 12 14
Time (s)
150
75
12/17/2016
Speed
2000
added with acceleration and deceleration time
1500
1000
500
Scalar Control with V/f constant
-500
150
100
50
-50
-100
-150
Vfset Vr
50
40
30
20
10
0
-10
0 2 4 6 8 10 12 14
Time (s) 151
Speed
2000
1500
added with acceleration and deceleration time
1000
500
-500
Scalar Control with V/f constant
100
1000
0
500
-100
0
-200
-500
-300
With
Isa Isb Isc
ACC & 150
DEC 100
50
-50
-100
Significant -150
reduce Vfset Vr
starting 50
current 40
30
20
10
-10
152
0 2 4 6 8 10 12 14
Time (s)
76
12/17/2016
153
arm-fast-math for fast computation
154
77
12/17/2016
155
arm-fast-math for fast computation
vr=a*sin((float)2*phi*f * t )+ ofset;
vs=a*sin(((float)2*phi*f * t) +(2*phi/3)) + ofset;
vt=a*sin(((float)2*phi*f * t) -(2*phi/3)) + ofset;
156
78
12/17/2016
Vr =a*arm_sin_f32((float)2*phi*f * t )+ ofset;
Vr =a*arm_sin_f32((float)2*phi*f
+(a/6)*arm_sin_f32((float)6*phi*f * t)
+ ofset; 157
158
79
12/17/2016
Minggu Ke - 8
159
160
80
12/17/2016
161
162
81
12/17/2016
163
AC Source
Microcontroller
AC Source
164
SCR/TRIAC driver
82
12/17/2016
MCU
165
166
83
12/17/2016
167
168
84
12/17/2016
169
170
85
12/17/2016
171
86
12/17/2016
173
174
87
12/17/2016
Minggu Ke - 9
175
176
88
12/17/2016
177
• Pin selection
• We are looking for free pins where is possible to create wire loopback connection
178
89
12/17/2016
179
Image from
STM32F429
datasheet
180
90
12/17/2016
Hardware
connection
RX <-TX
TX->RX
181
182
91
12/17/2016
183
184
92
12/17/2016
185
186
93
12/17/2016
Peripheral Initializations
Cube MX UART init start in
main.c file
MX_USART1_UART_Init();
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
187
MX_USART1_UART_Init();
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
188
94
12/17/2016
MX_USART1_UART_Init();
Cube MX create for us
function which handle UART
Init UART1 structure initialization
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
189
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
190
95
12/17/2016
HAL_UART_MspInit callback
191
HAL_UART_Init(&huart1);
HAL_UART_MspInit callback
192
96
12/17/2016
HAL_UART_Init(&huart1);
Function wrote parameters
from structure into UART1
HAL_UART_MspInit callback registers
193
194
97
12/17/2016
195
98
12/17/2016
Init GPIO and NVIC for UART 6. UART1 GPIOS, NVIC and RCC init
197
Init GPIO and NVIC for UART 6. UART1 GPIOS, NVIC and RCC init
99
12/17/2016
199
Created by user
Peripheral Initializations
200
100
12/17/2016
201
Created by user
Peripheral Initializations
202
101
12/17/2016
203
/* USERfunction
• Call transmit CODE BEGIN
from3 while
*/ loop
/* Infinite loop */
while (1)
{
HAL_UART_Transmit(&huart1,data,10,
1000);
}
/* USER CODE END 3 */
204
102
12/17/2016
205
206
103
12/17/2016
Minggu Ke - 10
207
UART Interrupt
208
104
12/17/2016
209
• Pin selection
• It will be same as previous lab we use again PA9 and PA10
210
105
12/17/2016
Hardware
loopback
211
212
106
12/17/2016
213
214
107
12/17/2016
215
216
108
12/17/2016
217
218
109
12/17/2016
219
220
110
12/17/2016
221
222
111
12/17/2016
223
Generated in stm32f4xx_it.c
224
112
12/17/2016
225
226
113
12/17/2016
227
Process interrupt
Start process with interrupt generation at end of information
process
HAL_UART_Transmit_IT
228
114
12/17/2016
229
230
115
12/17/2016
231
2. UART1 send
Start process with interrupt generation at end of
process
buffer
HAL_UART_Transmit_IT
3. UART1 Tx
4. Send more data
register empty
end of process callback 5. Buffer sent or manage error
HAL_UART_TxCpltCallback
232
116
12/17/2016
233
234
117
12/17/2016
235
236
118
12/17/2016
Minggu Ke - 11
237
UART DMA
238
119
12/17/2016
239
• Pin selection
• It will be same as previous lab we use again PA9 and PA10
240
120
12/17/2016
Hardware
loopback
241
242
121
12/17/2016
243
244
122
12/17/2016
245
246
123
12/17/2016
247
248
124
12/17/2016
249
250
125
12/17/2016
251
Defined by user
process Error callback
HAL_UART_ErrorCallback
252
126
12/17/2016
253
254
127
12/17/2016
Generated in stm32f4xx_it.c
255
256
128
12/17/2016
257
258
129
12/17/2016
Process interrupt
Start process with DMA end of transfer information from DMA and
interrupt generation at end of process UART
HAL_UART_Receive_DMA
259
260
130
12/17/2016
261
262
131
12/17/2016
263
264
132
12/17/2016
265
266
133
12/17/2016
Minggu Ke - 12
267
268
134
12/17/2016
Waijung Blockset
"Waijung" or "ไวจัง", a Thai slang for "so fast", is a Simulink Blockset that can be used to
easily and automatically generate C code from your Matlab/Simulink simulation models
for many kinds of microcontrollers (Targets).
Waijung Blockset and STM32F4 Target has been completely redesigned with many new
features and improvements, based on our experiences on developing RapidSTM32
Blockset and "real-world applications with ease of use" philosophy.
.
269
270
135
12/17/2016
271
Waijung Blockset
272
136
12/17/2016
Waijung Blockset
Simple and Highly Flexible Target Setup
273
137
12/17/2016
275
276
138
12/17/2016
277
278
139
12/17/2016
279
280
140
12/17/2016
281
141
12/17/2016
283
284
142
12/17/2016
286
143
12/17/2016
287
288
144
12/17/2016
290
145
12/17/2016
Block Library
name
Target Waijung blockset /STM32F4
setup Target / Device configuration
Digital
Input Waijung blockset /STM32F4
Target / on-chip peripheral
Digital /IO
Output
AND
291
AND
Simulink / Logic and Bit
OR
Operation
NOT
292
146
12/17/2016
293
Simulink / Sink
% Pulse Width = (Time for which LED is ON) x 100 / Period
Scope Here Period corresponds to switch ON + switch OFF time i.e. 1 + 3 =
4 sec. So the answer is:
= (1) x 100 / 4 = 25 %
294
147
12/17/2016
Block Library
name
Target Waijung blockset /STM32F4
setup Target / Device configuration
Digital
Input Waijung blockset /STM32F4
Target / on-chip peripheral
Digital /IO
Output
AND
Simulink / Logic and Bit
OR
Operation
NOT
Simulink / Commonly used
Delay
library
295
BOUNCING/DE-BOUNCING
• Bouncing is the non-ideal behavior of mechanical switches which creates multiple electric transitions
when a single input from the user is entered. It takes some time for the input to reach at a stable state.
• The bouncing effect is illustrated on figure below. From the figure, we can see that in the beginning the
switch is in ON state. When user enter the input to switch it OFF, then it takes around 0.01 to 100 msec
before the switch is actually switched OFF. A similar effect can be observed when the switch goes from
OFF state to ON state.
296
148
12/17/2016
BOUNCING/DE-BOUNCING
Bouncing is an undesirable effect so it must be removed when designing a
circuit. There are number of ways by which we can avoid bouncing. The process
of avioding bouncing is called de-bouncing. The most easy and commonly used
technique for debouncing is analog filtering. A resistor capacitor (RC) circuit is
used to filterout the rapid changes in the switch output. Depending on the
nature of the switch, the values of RC circuit is chosen in such a way that input
threshold is not crossed while bouncing is still occuring.
297
BOUNCING/DE-BOUNCING
In other than hardware techniques available to overcome debouncing, software programming can also
help to aviod it. This will eliminate the need to additional RC circuit. In RC block, the user can also set the
time interval in Waijung Blockset have Debounce block in Simulink Library: Waijung Blockset >> STM32F4
Target >> On-chip Peripherals >> IO by setting parameter of Debounce block.
298
149
12/17/2016
Minggu Ke - 13
299
300
150
12/17/2016
301
302
151
12/17/2016
304
152
12/17/2016
305
306
153
12/17/2016
307
154
12/17/2016
309
Regular ADC in a Simulink
155
12/17/2016
311
ADC Experiment 1
312
156
12/17/2016
ADC Experiment 2
313
ADC Experiment 3
314
157
12/17/2016
ADC Experiment 3
315
316
158
12/17/2016
Minggu Ke - 14
317
318
159
12/17/2016
Regular DAC
319
320
160
12/17/2016
321
Regular DAC in a Simulink
This example demonstrates how to use the Regular DAC Block to output 2 analog signals
1. Triangular Waveform frequency 1kHz, Amplitude 0 - 2V
2. Sinusoidal Waveform frequency 1kHz, Ampliture 0.5 - 2.5V
Note that:
The values used to drive DAC Module in this example are derived from native Simulink block from Simulink
Source block library. This approach is not suitable for generating high-frequency signals. This is because the
Source blocks compute each value by solving relevant equation analytically, hence there is computation
time lost. 322
161
Regular DAC in a Simulink Regular DAC in a Simulink
324
323
12/17/2016
162
12/17/2016
DAC Experiment 1
325
DAC Experiment 1
326
163
12/17/2016
DAC Experiment 1
327
DAC Experiment 1
328
164
12/17/2016
DAC Experiment 2
329
DAC Experiment 2
330
165
12/17/2016
DAC
Arbitrary Waveform Generator
331
DAC Arbitrary Waveform Generator
332
166
12/17/2016
333
DAC Arbitrary Waveform Generator
334
167
12/17/2016
DAC Arbitrary Waveform Generator Two analog signals should be output from pins A4 and A5 as shown below
335
336
168
12/17/2016
Minggu Ke - 15
337
338
169
12/17/2016
conditions applies.
1. Up to a maximum number of 4 edge-aligned
PWM signals (channels) can be generated per
timer.
2. Each timer has 16-bit counter that
determines the PWM period.
3. PWM period can not be changed during run-
time.
Clock Computation
PWM signal frequency is determined by the value TIMx_ARR and a duty cycle is determined
by the value TIMx_CCRx. The timer's clock is computed as follows:
TIMx_CLK = HCLK/APBxPrescaler
where TIM2,3,4,5,6,7,12,13,14 uses APB1 and TIM1,8,9,10,11 uses APB2.
The timer's auto reload value (TIMx_ARR) that determines the PWM period for each timer is
Basic PWM
computed from:
TIMx_ARR = (TIMx_CounterClock * PWM_period) - 1
where TIMx_CounterClock = TIMx_CLK / (TIMx_Prescaler + 1).
STM32F4 Target searches for the optimal TIMx_ARR automatically using the following
constraints
1. TIMx_Prescaler <= 65535
2. TIMx_ARR is as near a whole number as possible, i.e. min(TIMx_ARR -
floor(TIMx_ARR))
The duty cycle is computed from:
TIMx_CCRx = TIMx_ARR * (Duty Cycle / 100)
340
170
12/17/2016
341
PWM Experiment 1
This example demonstrates how to use the Basic
PWM Block to configure Timer 4 generate Active
High PWM signals with 0.02 seconds period.
342
171
12/17/2016
PWM Experiment 2
343
PWM Experiment 2
344
172
12/17/2016
Controlling
Basic PWM PWM Duty Cycle With ADC
345
Controlling
Basic PWM PWM Duty Cycle With ADC
346
173
12/17/2016
347
348
174
12/17/2016
349
350
175
12/17/2016
Description
351
An example of waveform capture PWM output CH1, CH1N, CH2 and CH2N. Due to Dead-time 1uS (equal to
10% of period 10uS), so the duty cycle measurement of CH1 will be 10% instead of 20%.
Advanced PWM
352
176
12/17/2016
Minggu Ke - 16
353
354
177
12/17/2016
Encoder Read
Output port
1. READY , Return status of PWM capture
operation, value is non-zero when data is
ready.
2. +Width (sec), Positive pulse width value, in
unit of seconds.
3. +Duty (%), Positive duty cycle value, in
percentage.
4. Frequency (Hz), PWM frequency, in unit of
Hz.
356
178
12/17/2016
Output port
1. READY , Return status of PWM capture
operation, value is non-zero when data
is ready.
2. +Width (sec), Positive pulse width
value, in unit of seconds.
3. +Duty (%), Positive duty cycle value, in
percentage.
4. Frequency (Hz), PWM frequency, in
unit of Hz.
357
358
179
12/17/2016
eka@pens.ac.id, epyk@pens.ac.id
Politeknik Elektronika Negeri Surabaya
©2016
359
Terima kasih
360
180