Lab5

Dependencies:   mbed

Committer:
Supermil
Date:
Tue Nov 21 16:17:32 2017 +0000
Revision:
0:59a8574b663a
lab6 MCP4922;

Who changed what in which revision?

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