Lab 1 Program C

Dependents:   Lab1C

Fork of mbed by -deleted-

Committer:
simon.ford@mbed.co.uk
Date:
Thu Jan 22 18:32:40 2009 +0000
Revision:
5:62573be585e9
Parent:
4:5d1359a283bc
Child:
11:1c1ebd0324fa
* Added initial RPC release
* Added RTC and helper functions
* Added read_u16()/write_u16() to AnalogIn/Out
* Ticker/Timeout timing fixed!
* mbedinfo() helper added
* error() and printf() added to replace DEBUG() and ERROR()
* DigitalIn supports methods on rise/fall
* SPI and Serial support NC
* LED1-4 also map to 1-4
* Timer object reset fixed
* SPI uses single mode
* SPI3 added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon.ford@mbed.co.uk 0:82220227f4fa 1 /* mbed Microcontroller Library - PwmOut
simon.ford@mbed.co.uk 0:82220227f4fa 2 * Copyright (c) 2007-2008, sford
simon.ford@mbed.co.uk 0:82220227f4fa 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
simon.ford@mbed.co.uk 0:82220227f4fa 8 #include "Base.h"
simon.ford@mbed.co.uk 0:82220227f4fa 9
simon.ford@mbed.co.uk 0:82220227f4fa 10 namespace mbed {
simon.ford@mbed.co.uk 0:82220227f4fa 11
simon.ford@mbed.co.uk 0:82220227f4fa 12 /* Class: PwmOut
simon.ford@mbed.co.uk 0:82220227f4fa 13 * A pulse-width modulation digital output
simon.ford@mbed.co.uk 5:62573be585e9 14 *
simon.ford@mbed.co.uk 5:62573be585e9 15 * Implementation Note:
simon.ford@mbed.co.uk 5:62573be585e9 16 * The period is is common to all PwmOut's, so changing it on one PwmOut will change them all!
simon.ford@mbed.co.uk 0:82220227f4fa 17 */
simon.ford@mbed.co.uk 0:82220227f4fa 18 class PwmOut : public Base {
simon.ford@mbed.co.uk 0:82220227f4fa 19
simon.ford@mbed.co.uk 0:82220227f4fa 20 public:
simon.ford@mbed.co.uk 0:82220227f4fa 21
simon.ford@mbed.co.uk 0:82220227f4fa 22 /* Constructor: PwmOut
simon.ford@mbed.co.uk 0:82220227f4fa 23 * Create a PwmOut connected to the specified pin
simon.ford@mbed.co.uk 0:82220227f4fa 24 *
simon.ford@mbed.co.uk 0:82220227f4fa 25 * Variables:
simon.ford@mbed.co.uk 0:82220227f4fa 26 * pin - PwmOut pin to connect to (21-26)
simon.ford@mbed.co.uk 0:82220227f4fa 27 */
simon.ford@mbed.co.uk 4:5d1359a283bc 28 PwmOut(int pin, const char *name = NULL);
simon.ford@mbed.co.uk 0:82220227f4fa 29
simon.ford@mbed.co.uk 0:82220227f4fa 30 /* Function: write
simon.ford@mbed.co.uk 0:82220227f4fa 31 * Set the ouput duty-cycle, specified as a percentage (float)
simon.ford@mbed.co.uk 0:82220227f4fa 32 *
simon.ford@mbed.co.uk 0:82220227f4fa 33 * Variables:
simon.ford@mbed.co.uk 0:82220227f4fa 34 * percent - A floating-point value representing the output duty-cycle,
simon.ford@mbed.co.uk 0:82220227f4fa 35 * specified as a percentage. The value should lie between
simon.ford@mbed.co.uk 0:82220227f4fa 36 * 0.0f (representing 0v / on 0%) and 1.0f (representing 3.3v / on 100%).
simon.ford@mbed.co.uk 0:82220227f4fa 37 * Values outside this range will be saturated to 0.0f or 1.0f.
simon.ford@mbed.co.uk 0:82220227f4fa 38 */
simon.ford@mbed.co.uk 0:82220227f4fa 39 void write(float percent);
simon.ford@mbed.co.uk 0:82220227f4fa 40
simon.ford@mbed.co.uk 0:82220227f4fa 41
simon.ford@mbed.co.uk 0:82220227f4fa 42 /* Function: read
simon.ford@mbed.co.uk 0:82220227f4fa 43 * Return the current output duty-cycle setting, measured as a percentage (float)
simon.ford@mbed.co.uk 0:82220227f4fa 44 *
simon.ford@mbed.co.uk 0:82220227f4fa 45 * Variables:
simon.ford@mbed.co.uk 0:82220227f4fa 46 * returns - A floating-point value representing the current duty-cycle being output on the pin,
simon.ford@mbed.co.uk 0:82220227f4fa 47 * measured as a percentage. The returned value will lie between
simon.ford@mbed.co.uk 0:82220227f4fa 48 * 0.0f (representing 0v / 0% on) and 1.0f (representing 3.3v / 100% on).
simon.ford@mbed.co.uk 0:82220227f4fa 49 *
simon.ford@mbed.co.uk 0:82220227f4fa 50 * Note:
simon.ford@mbed.co.uk 0:82220227f4fa 51 * This value may not match exactly the value set by a previous <write>.
simon.ford@mbed.co.uk 0:82220227f4fa 52 */
simon.ford@mbed.co.uk 0:82220227f4fa 53 float read();
simon.ford@mbed.co.uk 0:82220227f4fa 54
simon.ford@mbed.co.uk 0:82220227f4fa 55 /* Function: period
simon.ford@mbed.co.uk 0:82220227f4fa 56 * Set the PWM period, specified in seconds (float)
simon.ford@mbed.co.uk 0:82220227f4fa 57 */
simon.ford@mbed.co.uk 0:82220227f4fa 58 void period(float seconds);
simon.ford@mbed.co.uk 0:82220227f4fa 59
simon.ford@mbed.co.uk 5:62573be585e9 60 /* Function: period_ms
simon.ford@mbed.co.uk 5:62573be585e9 61 * Set the PWM period, specified in milli-seconds (int)
simon.ford@mbed.co.uk 5:62573be585e9 62 */
simon.ford@mbed.co.uk 5:62573be585e9 63 void period_ms(int ms);
simon.ford@mbed.co.uk 5:62573be585e9 64
simon.ford@mbed.co.uk 5:62573be585e9 65 /* Function: period_us
simon.ford@mbed.co.uk 5:62573be585e9 66 * Set the PWM period, specified in micro-seconds (int)
simon.ford@mbed.co.uk 5:62573be585e9 67 */
simon.ford@mbed.co.uk 5:62573be585e9 68 void period_us(int us);
simon.ford@mbed.co.uk 5:62573be585e9 69
simon.ford@mbed.co.uk 0:82220227f4fa 70 /* Function: pulsewidth
simon.ford@mbed.co.uk 0:82220227f4fa 71 * Set the PWM pulsewidth, specified in seconds (float)
simon.ford@mbed.co.uk 0:82220227f4fa 72 */
simon.ford@mbed.co.uk 0:82220227f4fa 73 void pulsewidth(float seconds);
simon.ford@mbed.co.uk 0:82220227f4fa 74
simon.ford@mbed.co.uk 0:82220227f4fa 75 /* Function: pulsewidth_ms
simon.ford@mbed.co.uk 0:82220227f4fa 76 * Set the PWM pulsewidth, specified in milli-seconds (int)
simon.ford@mbed.co.uk 0:82220227f4fa 77 */
simon.ford@mbed.co.uk 0:82220227f4fa 78 void pulsewidth_ms(int ms);
simon.ford@mbed.co.uk 0:82220227f4fa 79
simon.ford@mbed.co.uk 0:82220227f4fa 80 /* Function: pulsewidth_us
simon.ford@mbed.co.uk 0:82220227f4fa 81 * Set the PWM pulsewidth, specified in micro-seconds (int)
simon.ford@mbed.co.uk 0:82220227f4fa 82 */
simon.ford@mbed.co.uk 0:82220227f4fa 83 void pulsewidth_us(int us);
simon.ford@mbed.co.uk 0:82220227f4fa 84
simon.ford@mbed.co.uk 0:82220227f4fa 85 /* Function: operator=
simon.ford@mbed.co.uk 5:62573be585e9 86 * A operator shorthand for <write()>
simon.ford@mbed.co.uk 0:82220227f4fa 87 */
simon.ford@mbed.co.uk 0:82220227f4fa 88 PwmOut& operator= (float percent);
simon.ford@mbed.co.uk 0:82220227f4fa 89 PwmOut& operator= (PwmOut& rhs);
simon.ford@mbed.co.uk 0:82220227f4fa 90
simon.ford@mbed.co.uk 0:82220227f4fa 91 /* Function: operator float()
simon.ford@mbed.co.uk 5:62573be585e9 92 * An operator shorthand for <read()>
simon.ford@mbed.co.uk 0:82220227f4fa 93 */
simon.ford@mbed.co.uk 0:82220227f4fa 94 operator float();
simon.ford@mbed.co.uk 4:5d1359a283bc 95
simon.ford@mbed.co.uk 5:62573be585e9 96 // functions to be dropped in time...
simon.ford@mbed.co.uk 5:62573be585e9 97 void write_v(float v);
simon.ford@mbed.co.uk 5:62573be585e9 98 void write_mv(int mv);
simon.ford@mbed.co.uk 5:62573be585e9 99
simon.ford@mbed.co.uk 5:62573be585e9 100 virtual const struct rpc_method *get_rpc_methods();
simon.ford@mbed.co.uk 5:62573be585e9 101 static struct rpc_class *get_rpc_class();
simon.ford@mbed.co.uk 5:62573be585e9 102
simon.ford@mbed.co.uk 0:82220227f4fa 103
simon.ford@mbed.co.uk 0:82220227f4fa 104 protected:
simon.ford@mbed.co.uk 0:82220227f4fa 105
simon.ford@mbed.co.uk 0:82220227f4fa 106 int _id;
simon.ford@mbed.co.uk 0:82220227f4fa 107 };
simon.ford@mbed.co.uk 0:82220227f4fa 108
simon.ford@mbed.co.uk 0:82220227f4fa 109 }
simon.ford@mbed.co.uk 0:82220227f4fa 110
simon.ford@mbed.co.uk 1:6b7f447ca868 111 #endif
simon.ford@mbed.co.uk 1:6b7f447ca868 112