Nikola Cvetković
/
19E042PIM_V1_BM_PWM_PULSE
PWM program which uses PwmOut class determening whether LED state can be seen (19E042PIM).
mian.cpp@1:4397be8fc587, 2021-10-28 (annotated)
- Committer:
- tzwell
- Date:
- Thu Oct 28 11:03:26 2021 +0000
- Revision:
- 1:4397be8fc587
- Parent:
- 0:eb7eef6774a2
Updated comments and code structure
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tzwell | 0:eb7eef6774a2 | 1 | /* |
tzwell | 0:eb7eef6774a2 | 2 | * Primer PWM-a za STM32L476RG napisan |
tzwell | 0:eb7eef6774a2 | 3 | * koristeci mbed.h biblioteku koji demonstrira |
tzwell | 0:eb7eef6774a2 | 4 | * mogucnosti PwmOut objekta preko pulsewidth atributa. |
tzwell | 0:eb7eef6774a2 | 5 | * |
tzwell | 0:eb7eef6774a2 | 6 | * Katedra za Elektroniku i digitalne sisteme |
tzwell | 0:eb7eef6774a2 | 7 | * Elektrotehnicki fakultet |
tzwell | 0:eb7eef6774a2 | 8 | * Beograd |
tzwell | 0:eb7eef6774a2 | 9 | * |
tzwell | 0:eb7eef6774a2 | 10 | * Oktobar 2021. |
tzwell | 0:eb7eef6774a2 | 11 | * |
tzwell | 0:eb7eef6774a2 | 12 | */ |
tzwell | 0:eb7eef6774a2 | 13 | |
tzwell | 0:eb7eef6774a2 | 14 | /* |
tzwell | 0:eb7eef6774a2 | 15 | * Biblioteke za uvoz: |
tzwell | 0:eb7eef6774a2 | 16 | */ |
tzwell | 0:eb7eef6774a2 | 17 | #include "mbed.h" |
tzwell | 0:eb7eef6774a2 | 18 | |
tzwell | 0:eb7eef6774a2 | 19 | /* |
tzwell | 0:eb7eef6774a2 | 20 | * Definisanje makroa: |
tzwell | 0:eb7eef6774a2 | 21 | */ |
tzwell | 0:eb7eef6774a2 | 22 | #define PWM_PERIOD 100 |
tzwell | 0:eb7eef6774a2 | 23 | #define PWM_PULSE_WIDTH 1 |
tzwell | 0:eb7eef6774a2 | 24 | |
tzwell | 0:eb7eef6774a2 | 25 | /* |
tzwell | 0:eb7eef6774a2 | 26 | * Globalne promenljive: |
tzwell | 0:eb7eef6774a2 | 27 | */ |
tzwell | 0:eb7eef6774a2 | 28 | PwmOut DiodicaNaPloci(LED1); // Kreiranje promenljive diode |
tzwell | 0:eb7eef6774a2 | 29 | |
tzwell | 0:eb7eef6774a2 | 30 | /* |
tzwell | 0:eb7eef6774a2 | 31 | * Deklaracija funkcija: |
tzwell | 0:eb7eef6774a2 | 32 | */ |
tzwell | 0:eb7eef6774a2 | 33 | |
tzwell | 0:eb7eef6774a2 | 34 | /* |
tzwell | 0:eb7eef6774a2 | 35 | * Glavna funkcija: |
tzwell | 0:eb7eef6774a2 | 36 | */ |
tzwell | 0:eb7eef6774a2 | 37 | int main() |
tzwell | 0:eb7eef6774a2 | 38 | { |
tzwell | 1:4397be8fc587 | 39 | // Inicijalizacija i funckije koje se jednom izvrsavaju: |
tzwell | 1:4397be8fc587 | 40 | |
tzwell | 0:eb7eef6774a2 | 41 | // Prvo se zada period treperenja diode, a potom trajanje impulsa: |
tzwell | 0:eb7eef6774a2 | 42 | DiodicaNaPloci.period_ms(PWM_PERIOD); // Period treperenja traje 4 sekunde |
tzwell | 0:eb7eef6774a2 | 43 | DiodicaNaPloci.pulsewidth_us(PWM_PULSE_WIDTH); // Dioda ukljucena tokom 2 |
tzwell | 1:4397be8fc587 | 44 | while (true); // Izvrsavanje programa |
tzwell | 0:eb7eef6774a2 | 45 | } |
tzwell | 0:eb7eef6774a2 | 46 | |
tzwell | 0:eb7eef6774a2 | 47 | /* |
tzwell | 0:eb7eef6774a2 | 48 | * Definicija funkcija: |
tzwell | 0:eb7eef6774a2 | 49 | */ |