Kamil Ondrousek
/
DAC-Chua
Chua chaotic oscillator and MCP4922 DAC
MCP4922.h@0:e5edc0373da0, 2011-05-07 (annotated)
- Committer:
- JLS
- Date:
- Sat May 07 19:27:14 2011 +0000
- Revision:
- 0:e5edc0373da0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JLS | 0:e5edc0373da0 | 1 | /* |
JLS | 0:e5edc0373da0 | 2 | * MCP4922 - DAC library. |
JLS | 0:e5edc0373da0 | 3 | * |
JLS | 0:e5edc0373da0 | 4 | * Copyright (c) 2011 Steven Beard, UK Astronomy Technology Centre. |
JLS | 0:e5edc0373da0 | 5 | * |
JLS | 0:e5edc0373da0 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
JLS | 0:e5edc0373da0 | 7 | * of this software and associated documentation files (the "Software"), to deal |
JLS | 0:e5edc0373da0 | 8 | * in the Software without restriction, including without limitation the rights |
JLS | 0:e5edc0373da0 | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
JLS | 0:e5edc0373da0 | 10 | * copies of the Software, and to permit persons to whom the Software is |
JLS | 0:e5edc0373da0 | 11 | * furnished to do so, subject to the following conditions: |
JLS | 0:e5edc0373da0 | 12 | * |
JLS | 0:e5edc0373da0 | 13 | * The above copyright notice and this permission notice shall be included in |
JLS | 0:e5edc0373da0 | 14 | * all copies or substantial portions of the Software. |
JLS | 0:e5edc0373da0 | 15 | * |
JLS | 0:e5edc0373da0 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
JLS | 0:e5edc0373da0 | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
JLS | 0:e5edc0373da0 | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
JLS | 0:e5edc0373da0 | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
JLS | 0:e5edc0373da0 | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
JLS | 0:e5edc0373da0 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
JLS | 0:e5edc0373da0 | 22 | * THE SOFTWARE. |
JLS | 0:e5edc0373da0 | 23 | */ |
JLS | 0:e5edc0373da0 | 24 | |
JLS | 0:e5edc0373da0 | 25 | #include "mbed.h" |
JLS | 0:e5edc0373da0 | 26 | |
JLS | 0:e5edc0373da0 | 27 | #ifndef MCP4922_H |
JLS | 0:e5edc0373da0 | 28 | #define MCP4922_H |
JLS | 0:e5edc0373da0 | 29 | |
JLS | 0:e5edc0373da0 | 30 | /* Reference: Microchip Technology (2005), MCP4821/MCP4822 DAC Data Sheet. */ |
JLS | 0:e5edc0373da0 | 31 | |
JLS | 0:e5edc0373da0 | 32 | // MCP4922 reference voltage. |
JLS | 0:e5edc0373da0 | 33 | #define MCP4922_VREF 2048 // Reference voltage (mV) |
JLS | 0:e5edc0373da0 | 34 | |
JLS | 0:e5edc0373da0 | 35 | /* Define possible combinations of 16-bit command register bits */ |
JLS | 0:e5edc0373da0 | 36 | #define MCP4922_REG_A1 0x3000 // Channel A gain 1 |
JLS | 0:e5edc0373da0 | 37 | #define MCP4922_REG_B1 0xB000 // Channel B gain 1 |
JLS | 0:e5edc0373da0 | 38 | #define MCP4922_REG_SHDN 0x0000 // Output power down |
JLS | 0:e5edc0373da0 | 39 | |
JLS | 0:e5edc0373da0 | 40 | class MCP4922 { |
JLS | 0:e5edc0373da0 | 41 | public: |
JLS | 0:e5edc0373da0 | 42 | |
JLS | 0:e5edc0373da0 | 43 | MCP4922 (PinName mosi, PinName sclk, PinName cs); |
JLS | 0:e5edc0373da0 | 44 | |
JLS | 0:e5edc0373da0 | 45 | ~MCP4922(); |
JLS | 0:e5edc0373da0 | 46 | |
JLS | 0:e5edc0373da0 | 47 | /*+ |
JLS | 0:e5edc0373da0 | 48 | * frequency: Set the SPI bus clock frequency in Hz. |
JLS | 0:e5edc0373da0 | 49 | * The SPI bus frequency in Hz. Must be within the range |
JLS | 0:e5edc0373da0 | 50 | * supported by both the SPI interface and the DAC chips |
JLS | 0:e5edc0373da0 | 51 | * (~10 KHz to 20 MHz). |
JLS | 0:e5edc0373da0 | 52 | */ |
JLS | 0:e5edc0373da0 | 53 | void frequency( int freq ); |
JLS | 0:e5edc0373da0 | 54 | |
JLS | 0:e5edc0373da0 | 55 | void writeA(int value ); |
JLS | 0:e5edc0373da0 | 56 | |
JLS | 0:e5edc0373da0 | 57 | void writeB(int value ); |
JLS | 0:e5edc0373da0 | 58 | |
JLS | 0:e5edc0373da0 | 59 | void write( int nchans, int values[], int gain=2, int latch=1 ); |
JLS | 0:e5edc0373da0 | 60 | |
JLS | 0:e5edc0373da0 | 61 | void latch_enable(); |
JLS | 0:e5edc0373da0 | 62 | |
JLS | 0:e5edc0373da0 | 63 | void latch_disable(); |
JLS | 0:e5edc0373da0 | 64 | |
JLS | 0:e5edc0373da0 | 65 | private: |
JLS | 0:e5edc0373da0 | 66 | |
JLS | 0:e5edc0373da0 | 67 | MCP4922( const MCP4922& rhs ); |
JLS | 0:e5edc0373da0 | 68 | |
JLS | 0:e5edc0373da0 | 69 | void _init(); |
JLS | 0:e5edc0373da0 | 70 | |
JLS | 0:e5edc0373da0 | 71 | int _ndacs; // The number of DACS in the array |
JLS | 0:e5edc0373da0 | 72 | int _latched; // Is the "not LDAC" pin used (1=yes; 0=no)? |
JLS | 0:e5edc0373da0 | 73 | SPI _spi; // SPI bus object for communicating with DAC. |
JLS | 0:e5edc0373da0 | 74 | DigitalOut** _ncs_array; // Array of pointers to DigitalOut objects |
JLS | 0:e5edc0373da0 | 75 | // connected to "not CS" pins. |
JLS | 0:e5edc0373da0 | 76 | DigitalOut* _nldac; // Pointer to DigitalOut object connected |
JLS | 0:e5edc0373da0 | 77 | // to "not LDAC" pin (if any - NULL if none). |
JLS | 0:e5edc0373da0 | 78 | }; |
JLS | 0:e5edc0373da0 | 79 | |
JLS | 0:e5edc0373da0 | 80 | #endif |