Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: cc3000_ping_demo_try_2
Fork of mbed by
AnalogOut.h@27:7110ebee3484, 2011-11-29 (annotated)
- Committer:
- emilmont
- Date:
- Tue Nov 29 14:59:27 2011 +0000
- Revision:
- 27:7110ebee3484
- Parent:
- 11:1c1ebd0324fa
- Child:
- 43:e2ed12d17f06
New Libraries 11.11
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| simon.ford@mbed.co.uk | 0:82220227f4fa | 1 | /* mbed Microcontroller Library - AnalogOut | 
| emilmont | 27:7110ebee3484 | 2 | * Copyright (c) 2006-2011 ARM Limited. All rights reserved. | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 3 | */ | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 4 | |
| simon.ford@mbed.co.uk | 0:82220227f4fa | 5 | #ifndef MBED_ANALOGOUT_H | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 6 | #define MBED_ANALOGOUT_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_ANALOGOUT | 
| 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 | |
| simon.ford@mbed.co.uk | 0:82220227f4fa | 19 | /* Class: AnalogOut | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 20 | * An analog output, used for setting the voltage on a pin | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 21 | * | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 22 | * Example: | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 23 | * > // Make a sawtooth output | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 24 | * > | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 25 | * > #include "mbed.h" | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 26 | * > | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 27 | * > AnalogOut tri(p18); | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 28 | * > int main() { | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 29 | * > while(1) { | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 30 | * > tri = tri + 0.01; | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 31 | * > wait_us(1); | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 32 | * > if(tri == 1) { | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 33 | * > tri = 0; | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 34 | * > } | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 35 | * > } | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 36 | * > } | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 37 | */ | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 38 | class AnalogOut : public Base { | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 39 | |
| simon.ford@mbed.co.uk | 0:82220227f4fa | 40 | public: | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 41 | |
| simon.ford@mbed.co.uk | 0:82220227f4fa | 42 | /* Constructor: AnalogOut | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 43 | * Create an AnalogOut connected to the specified pin | 
| 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 | * pin - AnalogOut pin to connect to (18) | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 47 | */ | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 48 | AnalogOut(PinName pin, const char *name = NULL); | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 49 | |
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 50 | /* Function: write | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 51 | * Set the output voltage, specified as a percentage (float) | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 52 | * | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 53 | * Variables: | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 54 | * percent - A floating-point value representing the output voltage, | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 55 | * specified as a percentage. The value should lie between | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 56 | * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%). | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 57 | * Values outside this range will be saturated to 0.0f or 1.0f. | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 58 | */ | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 59 | void write(float value); | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 60 | |
| simon.ford@mbed.co.uk | 5:62573be585e9 | 61 | /* Function: write_u16 | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 62 | * Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF] | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 63 | * | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 64 | * Variables: | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 65 | * value - 16-bit unsigned short representing the output voltage, | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 66 | * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v) | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 67 | */ | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 68 | void write_u16(unsigned short value); | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 69 | |
| simon.ford@mbed.co.uk | 0:82220227f4fa | 70 | /* Function: read | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 71 | * Return the current output voltage setting, measured as a percentage (float) | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 72 | * | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 73 | * Variables: | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 74 | * returns - A floating-point value representing the current voltage being output on the pin, | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 75 | * measured as a percentage. The returned value will lie between | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 76 | * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%). | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 77 | * | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 78 | * Note: | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 79 | * This value may not match exactly the value set by a previous <write>. | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 80 | */ | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 81 | float read(); | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 82 | |
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 83 | |
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 84 | #ifdef MBED_OPERATORS | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 85 | /* Function: operator= | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 86 | * An operator shorthand for <write()> | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 87 | */ | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 88 | AnalogOut& operator= (float percent); | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 89 | AnalogOut& operator= (AnalogOut& rhs); | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 90 | |
| simon.ford@mbed.co.uk | 0:82220227f4fa | 91 | /* Function: operator float() | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 92 | * An operator shorthand for <read()> | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 93 | */ | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 94 | operator float(); | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 95 | #endif | 
| simon.ford@mbed.co.uk | 4:5d1359a283bc | 96 | |
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 97 | #ifdef MBED_RPC | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 98 | virtual const struct rpc_method *get_rpc_methods(); | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 99 | static struct rpc_class *get_rpc_class(); | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 100 | #endif | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 101 | |
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 102 | protected: | 
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 103 | |
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 104 | DACName _dac; | 
| simon.ford@mbed.co.uk | 5:62573be585e9 | 105 | |
| simon.ford@mbed.co.uk | 0:82220227f4fa | 106 | }; | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 107 | |
| rolf.meyer@arm.com | 11:1c1ebd0324fa | 108 | } // namespace mbed | 
| simon.ford@mbed.co.uk | 0:82220227f4fa | 109 | |
| simon.ford@mbed.co.uk | 1:6b7f447ca868 | 110 | #endif | 
| simon.ford@mbed.co.uk | 1:6b7f447ca868 | 111 | |
| emilmont | 27:7110ebee3484 | 112 | #endif | 
