Library
Fork of mbed by
AnalogOut.h@0:a8fa94490a0a, 2012-09-22 (annotated)
- Committer:
- gokmenascioglu
- Date:
- Sat Sep 22 10:32:07 2012 +0000
- Revision:
- 0:a8fa94490a0a
alican library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gokmenascioglu | 0:a8fa94490a0a | 1 | /* mbed Microcontroller Library - AnalogOut |
gokmenascioglu | 0:a8fa94490a0a | 2 | * Copyright (c) 2006-2011 ARM Limited. All rights reserved. |
gokmenascioglu | 0:a8fa94490a0a | 3 | */ |
gokmenascioglu | 0:a8fa94490a0a | 4 | |
gokmenascioglu | 0:a8fa94490a0a | 5 | #ifndef MBED_ANALOGOUT_H |
gokmenascioglu | 0:a8fa94490a0a | 6 | #define MBED_ANALOGOUT_H |
gokmenascioglu | 0:a8fa94490a0a | 7 | |
gokmenascioglu | 0:a8fa94490a0a | 8 | #include "device.h" |
gokmenascioglu | 0:a8fa94490a0a | 9 | |
gokmenascioglu | 0:a8fa94490a0a | 10 | #if DEVICE_ANALOGOUT |
gokmenascioglu | 0:a8fa94490a0a | 11 | |
gokmenascioglu | 0:a8fa94490a0a | 12 | #include "platform.h" |
gokmenascioglu | 0:a8fa94490a0a | 13 | #include "PinNames.h" |
gokmenascioglu | 0:a8fa94490a0a | 14 | #include "PeripheralNames.h" |
gokmenascioglu | 0:a8fa94490a0a | 15 | #include "Base.h" |
gokmenascioglu | 0:a8fa94490a0a | 16 | |
gokmenascioglu | 0:a8fa94490a0a | 17 | namespace mbed { |
gokmenascioglu | 0:a8fa94490a0a | 18 | |
gokmenascioglu | 0:a8fa94490a0a | 19 | /* Class: AnalogOut |
gokmenascioglu | 0:a8fa94490a0a | 20 | * An analog output, used for setting the voltage on a pin |
gokmenascioglu | 0:a8fa94490a0a | 21 | * |
gokmenascioglu | 0:a8fa94490a0a | 22 | * Example: |
gokmenascioglu | 0:a8fa94490a0a | 23 | * > // Make a sawtooth output |
gokmenascioglu | 0:a8fa94490a0a | 24 | * > |
gokmenascioglu | 0:a8fa94490a0a | 25 | * > #include "mbed.h" |
gokmenascioglu | 0:a8fa94490a0a | 26 | * > |
gokmenascioglu | 0:a8fa94490a0a | 27 | * > AnalogOut tri(p18); |
gokmenascioglu | 0:a8fa94490a0a | 28 | * > int main() { |
gokmenascioglu | 0:a8fa94490a0a | 29 | * > while(1) { |
gokmenascioglu | 0:a8fa94490a0a | 30 | * > tri = tri + 0.01; |
gokmenascioglu | 0:a8fa94490a0a | 31 | * > wait_us(1); |
gokmenascioglu | 0:a8fa94490a0a | 32 | * > if(tri == 1) { |
gokmenascioglu | 0:a8fa94490a0a | 33 | * > tri = 0; |
gokmenascioglu | 0:a8fa94490a0a | 34 | * > } |
gokmenascioglu | 0:a8fa94490a0a | 35 | * > } |
gokmenascioglu | 0:a8fa94490a0a | 36 | * > } |
gokmenascioglu | 0:a8fa94490a0a | 37 | */ |
gokmenascioglu | 0:a8fa94490a0a | 38 | class AnalogOut : public Base { |
gokmenascioglu | 0:a8fa94490a0a | 39 | |
gokmenascioglu | 0:a8fa94490a0a | 40 | public: |
gokmenascioglu | 0:a8fa94490a0a | 41 | |
gokmenascioglu | 0:a8fa94490a0a | 42 | /* Constructor: AnalogOut |
gokmenascioglu | 0:a8fa94490a0a | 43 | * Create an AnalogOut connected to the specified pin |
gokmenascioglu | 0:a8fa94490a0a | 44 | * |
gokmenascioglu | 0:a8fa94490a0a | 45 | * Variables: |
gokmenascioglu | 0:a8fa94490a0a | 46 | * pin - AnalogOut pin to connect to (18) |
gokmenascioglu | 0:a8fa94490a0a | 47 | */ |
gokmenascioglu | 0:a8fa94490a0a | 48 | AnalogOut(PinName pin, const char *name = NULL); |
gokmenascioglu | 0:a8fa94490a0a | 49 | |
gokmenascioglu | 0:a8fa94490a0a | 50 | /* Function: write |
gokmenascioglu | 0:a8fa94490a0a | 51 | * Set the output voltage, specified as a percentage (float) |
gokmenascioglu | 0:a8fa94490a0a | 52 | * |
gokmenascioglu | 0:a8fa94490a0a | 53 | * Variables: |
gokmenascioglu | 0:a8fa94490a0a | 54 | * percent - A floating-point value representing the output voltage, |
gokmenascioglu | 0:a8fa94490a0a | 55 | * specified as a percentage. The value should lie between |
gokmenascioglu | 0:a8fa94490a0a | 56 | * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%). |
gokmenascioglu | 0:a8fa94490a0a | 57 | * Values outside this range will be saturated to 0.0f or 1.0f. |
gokmenascioglu | 0:a8fa94490a0a | 58 | */ |
gokmenascioglu | 0:a8fa94490a0a | 59 | void write(float value); |
gokmenascioglu | 0:a8fa94490a0a | 60 | |
gokmenascioglu | 0:a8fa94490a0a | 61 | /* Function: write_u16 |
gokmenascioglu | 0:a8fa94490a0a | 62 | * Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF] |
gokmenascioglu | 0:a8fa94490a0a | 63 | * |
gokmenascioglu | 0:a8fa94490a0a | 64 | * Variables: |
gokmenascioglu | 0:a8fa94490a0a | 65 | * value - 16-bit unsigned short representing the output voltage, |
gokmenascioglu | 0:a8fa94490a0a | 66 | * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v) |
gokmenascioglu | 0:a8fa94490a0a | 67 | */ |
gokmenascioglu | 0:a8fa94490a0a | 68 | void write_u16(unsigned short value); |
gokmenascioglu | 0:a8fa94490a0a | 69 | |
gokmenascioglu | 0:a8fa94490a0a | 70 | /* Function: read |
gokmenascioglu | 0:a8fa94490a0a | 71 | * Return the current output voltage setting, measured as a percentage (float) |
gokmenascioglu | 0:a8fa94490a0a | 72 | * |
gokmenascioglu | 0:a8fa94490a0a | 73 | * Variables: |
gokmenascioglu | 0:a8fa94490a0a | 74 | * returns - A floating-point value representing the current voltage being output on the pin, |
gokmenascioglu | 0:a8fa94490a0a | 75 | * measured as a percentage. The returned value will lie between |
gokmenascioglu | 0:a8fa94490a0a | 76 | * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%). |
gokmenascioglu | 0:a8fa94490a0a | 77 | * |
gokmenascioglu | 0:a8fa94490a0a | 78 | * Note: |
gokmenascioglu | 0:a8fa94490a0a | 79 | * This value may not match exactly the value set by a previous <write>. |
gokmenascioglu | 0:a8fa94490a0a | 80 | */ |
gokmenascioglu | 0:a8fa94490a0a | 81 | float read(); |
gokmenascioglu | 0:a8fa94490a0a | 82 | |
gokmenascioglu | 0:a8fa94490a0a | 83 | |
gokmenascioglu | 0:a8fa94490a0a | 84 | #ifdef MBED_OPERATORS |
gokmenascioglu | 0:a8fa94490a0a | 85 | /* Function: operator= |
gokmenascioglu | 0:a8fa94490a0a | 86 | * An operator shorthand for <write()> |
gokmenascioglu | 0:a8fa94490a0a | 87 | */ |
gokmenascioglu | 0:a8fa94490a0a | 88 | AnalogOut& operator= (float percent); |
gokmenascioglu | 0:a8fa94490a0a | 89 | AnalogOut& operator= (AnalogOut& rhs); |
gokmenascioglu | 0:a8fa94490a0a | 90 | |
gokmenascioglu | 0:a8fa94490a0a | 91 | /* Function: operator float() |
gokmenascioglu | 0:a8fa94490a0a | 92 | * An operator shorthand for <read()> |
gokmenascioglu | 0:a8fa94490a0a | 93 | */ |
gokmenascioglu | 0:a8fa94490a0a | 94 | operator float(); |
gokmenascioglu | 0:a8fa94490a0a | 95 | #endif |
gokmenascioglu | 0:a8fa94490a0a | 96 | |
gokmenascioglu | 0:a8fa94490a0a | 97 | #ifdef MBED_RPC |
gokmenascioglu | 0:a8fa94490a0a | 98 | virtual const struct rpc_method *get_rpc_methods(); |
gokmenascioglu | 0:a8fa94490a0a | 99 | static struct rpc_class *get_rpc_class(); |
gokmenascioglu | 0:a8fa94490a0a | 100 | #endif |
gokmenascioglu | 0:a8fa94490a0a | 101 | |
gokmenascioglu | 0:a8fa94490a0a | 102 | protected: |
gokmenascioglu | 0:a8fa94490a0a | 103 | |
gokmenascioglu | 0:a8fa94490a0a | 104 | DACName _dac; |
gokmenascioglu | 0:a8fa94490a0a | 105 | |
gokmenascioglu | 0:a8fa94490a0a | 106 | }; |
gokmenascioglu | 0:a8fa94490a0a | 107 | |
gokmenascioglu | 0:a8fa94490a0a | 108 | } // namespace mbed |
gokmenascioglu | 0:a8fa94490a0a | 109 | |
gokmenascioglu | 0:a8fa94490a0a | 110 | #endif |
gokmenascioglu | 0:a8fa94490a0a | 111 | |
gokmenascioglu | 0:a8fa94490a0a | 112 | #endif |