Matthias Grob
/
FlyBed2
My fully self designed first stable working Quadrocopter Software.
Servo_PWM/Servo_PWM.cpp@5:06e978fd147a, 2014-07-06 (annotated)
- Committer:
- maetugr
- Date:
- Sun Jul 06 05:51:25 2014 +0000
- Revision:
- 5:06e978fd147a
- Parent:
- 1:5e2b81f2d0b4
switched from dedicated PWM Motor Driver to Interrupt Motor Driver which works on every Pin because PWM crashed a lot of I2C Sensor Values!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maetugr | 5:06e978fd147a | 1 | #include "Servo_PWM.h" |
maetugr | 5:06e978fd147a | 2 | #include "mbed.h" |
maetugr | 5:06e978fd147a | 3 | |
maetugr | 5:06e978fd147a | 4 | Servo_PWM::Servo_PWM(PinName Pin, int frequency) : ServoPin(Pin) { |
maetugr | 5:06e978fd147a | 5 | SetFrequency(frequency); |
maetugr | 5:06e978fd147a | 6 | ServoPin = 0; |
maetugr | 5:06e978fd147a | 7 | // initialize ESC |
maetugr | 5:06e978fd147a | 8 | SetPosition(0); // zero throttle |
maetugr | 5:06e978fd147a | 9 | } |
maetugr | 5:06e978fd147a | 10 | |
maetugr | 5:06e978fd147a | 11 | void Servo_PWM::SetFrequency(int frequency) { |
maetugr | 5:06e978fd147a | 12 | ServoPin.period(1.0/frequency); |
maetugr | 5:06e978fd147a | 13 | } |
maetugr | 5:06e978fd147a | 14 | |
maetugr | 5:06e978fd147a | 15 | void Servo_PWM::SetPosition(int position) { |
maetugr | 5:06e978fd147a | 16 | if (position > 1000) |
maetugr | 5:06e978fd147a | 17 | position = 1000; |
maetugr | 5:06e978fd147a | 18 | if (position < 0) |
maetugr | 5:06e978fd147a | 19 | position = 0; |
maetugr | 5:06e978fd147a | 20 | ServoPin.pulsewidth_us(position+1000); |
maetugr | 5:06e978fd147a | 21 | } |
maetugr | 5:06e978fd147a | 22 | |
maetugr | 5:06e978fd147a | 23 | void Servo_PWM::operator=(int position) { |
maetugr | 5:06e978fd147a | 24 | SetPosition(position); |
maetugr | 5:06e978fd147a | 25 | } |