Lab 1 Program C

Dependents:   Lab1C

Fork of mbed by -deleted-

Committer:
mattsims12
Date:
Tue Sep 29 03:04:58 2015 +0000
Revision:
44:1c5f591fce58
Parent:
43:aff670d0d510
Lab 1 Program C

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon.ford@mbed.co.uk 0:82220227f4fa 1 /* mbed Microcontroller Library - PwmOut
emilmont 27:7110ebee3484 2 * Copyright (c) 2007-2011 ARM Limited. All rights reserved.
rolf.meyer@arm.com 11:1c1ebd0324fa 3 */
simon.ford@mbed.co.uk 0:82220227f4fa 4
simon.ford@mbed.co.uk 0:82220227f4fa 5 #ifndef MBED_PWMOUT_H
simon.ford@mbed.co.uk 0:82220227f4fa 6 #define MBED_PWMOUT_H
simon.ford@mbed.co.uk 0:82220227f4fa 7
emilmont 27:7110ebee3484 8 #include "device.h"
emilmont 27:7110ebee3484 9
emilmont 27:7110ebee3484 10 #if DEVICE_PWMOUT
emilmont 27:7110ebee3484 11
rolf.meyer@arm.com 11:1c1ebd0324fa 12 #include "platform.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 13 #include "PinNames.h"
rolf.meyer@arm.com 11:1c1ebd0324fa 14 #include "PeripheralNames.h"
simon.ford@mbed.co.uk 0:82220227f4fa 15 #include "Base.h"
simon.ford@mbed.co.uk 0:82220227f4fa 16
simon.ford@mbed.co.uk 0:82220227f4fa 17 namespace mbed {
simon.ford@mbed.co.uk 0:82220227f4fa 18
screamer 43:aff670d0d510 19 /** A pulse-width modulation digital output
simon.ford@mbed.co.uk 5:62573be585e9 20 *
rolf.meyer@arm.com 11:1c1ebd0324fa 21 * Example
screamer 43:aff670d0d510 22 * @code
screamer 43:aff670d0d510 23 * // Fade a led on.
screamer 43:aff670d0d510 24 * #include "mbed.h"
simon.ford@mbed.co.uk 18:b3c9f16cbb96 25 *
screamer 43:aff670d0d510 26 * PwmOut led(LED1);
screamer 43:aff670d0d510 27 *
screamer 43:aff670d0d510 28 * int main() {
screamer 43:aff670d0d510 29 * while(1) {
screamer 43:aff670d0d510 30 * led = led + 0.01;
screamer 43:aff670d0d510 31 * wait(0.2);
screamer 43:aff670d0d510 32 * if(led == 1.0) {
screamer 43:aff670d0d510 33 * led = 0;
screamer 43:aff670d0d510 34 * }
screamer 43:aff670d0d510 35 * }
screamer 43:aff670d0d510 36 * }
screamer 43:aff670d0d510 37 * @endcode
screamer 43:aff670d0d510 38 *
screamer 43:aff670d0d510 39 * @note
screamer 43:aff670d0d510 40 * On the LPC1768 and LPC2368, the PWMs all share the same
simon.ford@mbed.co.uk 18:b3c9f16cbb96 41 * period - if you change the period for one, you change it for all.
simon.ford@mbed.co.uk 18:b3c9f16cbb96 42 * Although routines that change the period maintain the duty cycle
simon.ford@mbed.co.uk 18:b3c9f16cbb96 43 * for its PWM, all other PWMs will require their duty cycle to be
simon.ford@mbed.co.uk 18:b3c9f16cbb96 44 * refreshed.
simon.ford@mbed.co.uk 0:82220227f4fa 45 */
simon.ford@mbed.co.uk 0:82220227f4fa 46 class PwmOut : public Base {
simon.ford@mbed.co.uk 0:82220227f4fa 47
simon.ford@mbed.co.uk 0:82220227f4fa 48 public:
simon.ford@mbed.co.uk 0:82220227f4fa 49
screamer 43:aff670d0d510 50 /** Create a PwmOut connected to the specified pin
rolf.meyer@arm.com 11:1c1ebd0324fa 51 *
screamer 43:aff670d0d510 52 * @param pin PwmOut pin to connect to
rolf.meyer@arm.com 11:1c1ebd0324fa 53 */
rolf.meyer@arm.com 11:1c1ebd0324fa 54 PwmOut(PinName pin, const char *name = NULL);
simon.ford@mbed.co.uk 0:82220227f4fa 55
screamer 43:aff670d0d510 56 /** Set the ouput duty-cycle, specified as a percentage (float)
rolf.meyer@arm.com 11:1c1ebd0324fa 57 *
screamer 43:aff670d0d510 58 * @param value A floating-point value representing the output duty-cycle,
rolf.meyer@arm.com 11:1c1ebd0324fa 59 * specified as a percentage. The value should lie between
rolf.meyer@arm.com 11:1c1ebd0324fa 60 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
screamer 43:aff670d0d510 61 * Values outside this range will be saturated to 0.0f or 1.0f.
rolf.meyer@arm.com 11:1c1ebd0324fa 62 */
rolf.meyer@arm.com 11:1c1ebd0324fa 63 void write(float value);
simon.ford@mbed.co.uk 0:82220227f4fa 64
screamer 43:aff670d0d510 65 /** Return the current output duty-cycle setting, measured as a percentage (float)
simon.ford@mbed.co.uk 0:82220227f4fa 66 *
screamer 43:aff670d0d510 67 * @returns
screamer 43:aff670d0d510 68 * A floating-point value representing the current duty-cycle being output on the pin,
rolf.meyer@arm.com 11:1c1ebd0324fa 69 * measured as a percentage. The returned value will lie between
rolf.meyer@arm.com 11:1c1ebd0324fa 70 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
rolf.meyer@arm.com 11:1c1ebd0324fa 71 *
screamer 43:aff670d0d510 72 * @note
screamer 43:aff670d0d510 73 * This value may not match exactly the value set by a previous <write>.
rolf.meyer@arm.com 11:1c1ebd0324fa 74 */
simon.ford@mbed.co.uk 0:82220227f4fa 75 float read();
rolf.meyer@arm.com 11:1c1ebd0324fa 76
screamer 43:aff670d0d510 77 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
simon.ford@mbed.co.uk 18:b3c9f16cbb96 78 *
screamer 43:aff670d0d510 79 * @note
screamer 43:aff670d0d510 80 * The resolution is currently in microseconds; periods smaller than this
screamer 43:aff670d0d510 81 * will be set to zero.
rolf.meyer@arm.com 11:1c1ebd0324fa 82 */
rolf.meyer@arm.com 11:1c1ebd0324fa 83 void period(float seconds);
simon.ford@mbed.co.uk 0:82220227f4fa 84
screamer 43:aff670d0d510 85 /** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
rolf.meyer@arm.com 11:1c1ebd0324fa 86 */
rolf.meyer@arm.com 11:1c1ebd0324fa 87 void period_ms(int ms);
simon.ford@mbed.co.uk 5:62573be585e9 88
screamer 43:aff670d0d510 89 /** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
rolf.meyer@arm.com 11:1c1ebd0324fa 90 */
rolf.meyer@arm.com 11:1c1ebd0324fa 91 void period_us(int us);
simon.ford@mbed.co.uk 5:62573be585e9 92
screamer 43:aff670d0d510 93 /** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
rolf.meyer@arm.com 11:1c1ebd0324fa 94 */
rolf.meyer@arm.com 11:1c1ebd0324fa 95 void pulsewidth(float seconds);
rolf.meyer@arm.com 11:1c1ebd0324fa 96
screamer 43:aff670d0d510 97 /** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
rolf.meyer@arm.com 11:1c1ebd0324fa 98 */
rolf.meyer@arm.com 11:1c1ebd0324fa 99 void pulsewidth_ms(int ms);
rolf.meyer@arm.com 11:1c1ebd0324fa 100
screamer 43:aff670d0d510 101 /** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
rolf.meyer@arm.com 11:1c1ebd0324fa 102 */
rolf.meyer@arm.com 11:1c1ebd0324fa 103 void pulsewidth_us(int us);
simon.ford@mbed.co.uk 0:82220227f4fa 104
rolf.meyer@arm.com 11:1c1ebd0324fa 105 #ifdef MBED_OPERATORS
screamer 43:aff670d0d510 106 /** A operator shorthand for write()
rolf.meyer@arm.com 11:1c1ebd0324fa 107 */
rolf.meyer@arm.com 11:1c1ebd0324fa 108 PwmOut& operator= (float value);
rolf.meyer@arm.com 11:1c1ebd0324fa 109 PwmOut& operator= (PwmOut& rhs);
simon.ford@mbed.co.uk 0:82220227f4fa 110
screamer 43:aff670d0d510 111 /** An operator shorthand for read()
rolf.meyer@arm.com 11:1c1ebd0324fa 112 */
rolf.meyer@arm.com 11:1c1ebd0324fa 113 operator float();
rolf.meyer@arm.com 11:1c1ebd0324fa 114 #endif
simon.ford@mbed.co.uk 4:5d1359a283bc 115
rolf.meyer@arm.com 11:1c1ebd0324fa 116 #ifdef MBED_RPC
simon.ford@mbed.co.uk 5:62573be585e9 117 virtual const struct rpc_method *get_rpc_methods();
simon.ford@mbed.co.uk 5:62573be585e9 118 static struct rpc_class *get_rpc_class();
rolf.meyer@arm.com 11:1c1ebd0324fa 119 #endif
simon.ford@mbed.co.uk 5:62573be585e9 120
simon.ford@mbed.co.uk 0:82220227f4fa 121 protected:
simon.ford@mbed.co.uk 0:82220227f4fa 122
rolf.meyer@arm.com 11:1c1ebd0324fa 123 PWMName _pwm;
rolf.meyer@arm.com 11:1c1ebd0324fa 124
simon.ford@mbed.co.uk 0:82220227f4fa 125 };
simon.ford@mbed.co.uk 0:82220227f4fa 126
rolf.meyer@arm.com 11:1c1ebd0324fa 127 } // namespace mbed
simon.ford@mbed.co.uk 0:82220227f4fa 128
simon.ford@mbed.co.uk 1:6b7f447ca868 129 #endif
emilmont 27:7110ebee3484 130
emilmont 27:7110ebee3484 131 #endif