
shit PWM
Dependencies: FastPWM mbed-STM32F103C8T6 mbed
main.cpp@0:7637cf07c096, 2018-03-31 (annotated)
- Committer:
- RuslanUrya
- Date:
- Sat Mar 31 07:02:10 2018 +0000
- Revision:
- 0:7637cf07c096
shit PWM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RuslanUrya | 0:7637cf07c096 | 1 | #include "mbed.h" |
RuslanUrya | 0:7637cf07c096 | 2 | #include "stm32f103c8t6.h" |
RuslanUrya | 0:7637cf07c096 | 3 | #define DELAY 1.0/180 |
RuslanUrya | 0:7637cf07c096 | 4 | |
RuslanUrya | 0:7637cf07c096 | 5 | PwmOut mypwm(PB_6); |
RuslanUrya | 0:7637cf07c096 | 6 | |
RuslanUrya | 0:7637cf07c096 | 7 | |
RuslanUrya | 0:7637cf07c096 | 8 | int main() { |
RuslanUrya | 0:7637cf07c096 | 9 | confSysClock(); |
RuslanUrya | 0:7637cf07c096 | 10 | float f; |
RuslanUrya | 0:7637cf07c096 | 11 | double i = 0; |
RuslanUrya | 0:7637cf07c096 | 12 | mypwm.period(DELAY); // period, sec |
RuslanUrya | 0:7637cf07c096 | 13 | |
RuslanUrya | 0:7637cf07c096 | 14 | while(1) { |
RuslanUrya | 0:7637cf07c096 | 15 | f = (((float)sin (i) + 1.0)/2)*100; //sin in percents 0..100 |
RuslanUrya | 0:7637cf07c096 | 16 | mypwm = f; //duty cycle, percent |
RuslanUrya | 0:7637cf07c096 | 17 | i++; |
RuslanUrya | 0:7637cf07c096 | 18 | if (i > 180) i = 0; |
RuslanUrya | 0:7637cf07c096 | 19 | } |
RuslanUrya | 0:7637cf07c096 | 20 | } |