| 1 | /***************************************************************************//** |
| 2 | * @file ad9833.h |
| 3 | * @brief Header file of AD9833 Driver for Microblaze processor. |
| 4 | * @author Lucian Sin ([email protected]) |
| 5 | * |
| 6 | ******************************************************************************** |
| 7 | * Copyright 2013(c) Analog Devices, Inc. |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without modification, |
| 12 | * are permitted provided that the following conditions are met: |
| 13 | * - Redistributions of source code must retain the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer. |
| 15 | * - Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in |
| 17 | * the documentation and/or other materials provided with the |
| 18 | * distribution. |
| 19 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 20 | * contributors may be used to endorse or promote products derived |
| 21 | * from this software without specific prior written permission. |
| 22 | * - The use of this software may or may not infringe the patent rights |
| 23 | * of one or more patent holders. This license does not release you |
| 24 | * from the requirement that you obtain separate licenses from these |
| 25 | * patent holders to use this software. |
| 26 | * - Use of the software either in source or binary form, must be run |
| 27 | * on or directly connected to an Analog Devices Inc. component. |
| 28 | * |
| 29 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED |
| 30 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY |
| 31 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 32 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 33 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 34 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 35 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 36 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 38 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 39 | * |
| 40 | *******************************************************************************/ |
| 41 | #ifndef _AD9833_H_ |
| 42 | #define _AD9833_H_ |
| 43 | |
| 44 | /******************************************************************************/ |
| 45 | /******************************* Include Files ********************************/ |
| 46 | /******************************************************************************/ |
| 47 | #include "Communication.h" |
| 48 | |
| 49 | /******************************************************************************/ |
| 50 | /********************* Macros and Constants Definitions ***********************/ |
| 51 | /******************************************************************************/ |
| 52 | /* Supported devices */ |
| 53 | typedef enum { |
| 54 | ID_AD9833, |
| 55 | ID_AD9834, |
| 56 | ID_AD9837, |
| 57 | ID_AD9838, |
| 58 | } AD9833_type; |
| 59 | |
| 60 | #define AD9833_CTRLB28 (1 << 13) |
| 61 | #define AD9833_CTRLHLB (1 << 12) |
| 62 | #define AD9833_CTRLFSEL (1 << 11) |
| 63 | #define AD9833_CTRLPSEL (1 << 10) |
| 64 | #define AD9834_CTRLPINSW (1 << 9) |
| 65 | #define AD9833_CTRLRESET (1 << 8) |
| 66 | #define AD9833_CTRLSLEEP1 (1 << 7) |
| 67 | #define AD9833_CTRLSLEEP12 (1 << 6) |
| 68 | #define AD9833_CTRLOPBITEN (1 << 5) |
| 69 | #define AD9834_CTRLSIGNPIB (1 << 4) |
| 70 | #define AD9833_CTRLDIV2 (1 << 3) |
| 71 | #define AD9833_CTRLMODE (1 << 1) |
| 72 | |
| 73 | /* GPIOs */ |
| 74 | #define AD9834_PSEL_OUT GPIO0_PIN_OUT |
| 75 | #define AD9834_PSEL_LOW GPIO0_LOW |
| 76 | #define AD9834_PSEL_HIGH GPIO0_HIGH |
| 77 | |
| 78 | #define AD9834_FSEL_OUT GPIO1_PIN_OUT |
| 79 | #define AD9834_FSEL_LOW GPIO1_LOW |
| 80 | #define AD9834_FSEL_HIGH GPIO1_HIGH |
| 81 | |
| 82 | #define AD9834_RESET_OUT GPIO2_PIN_OUT |
| 83 | #define AD9834_RESET_LOW GPIO2_LOW |
| 84 | #define AD9834_RESET_HIGH GPIO2_HIGH |
| 85 | |
| 86 | #define AD9834_SLEEP_OUT GPIO3_PIN_OUT |
| 87 | #define AD9834_SLEEP_LOW GPIO3_LOW |
| 88 | #define AD9834_SLEEP_HIGH GPIO3_HIGH |
| 89 | |
| 90 | |
| 91 | #define BIT_F0ADDRESS 0x4000 // Frequency Register 0 address. |
| 92 | #define BIT_F1ADDRESS 0x8000 // Frequency Register 1 address. |
| 93 | #define BIT_P0ADDRESS 0xC000 // Phase Register 0 address. |
| 94 | #define BIT_P1ADDRESS 0xE000 // Phase Register 1 address. |
| 95 | |
| 96 | #define AD9833_SLAVE_ID 1 |
| 97 | |
| 98 | /******************************************************************************/ |
| 99 | /************************** Functions Declarations ****************************/ |
| 100 | /******************************************************************************/ |
| 101 | /* Initialize the SPI communication with the device. */ |
| 102 | char AD9833_Init(AD9833_type device); |
| 103 | /* Transmits 16 bits on SPI. */ |
| 104 | void AD9833_TxSpi(short value); |
| 105 | /* Selects the type of output. */ |
| 106 | char AD9833_OutMode(unsigned char vOutMode); |
| 107 | /* Loads a frequency value in a register. */ |
| 108 | void AD9833_SetFreq(unsigned char registerNumber, unsigned long frequencyValue); |
| 109 | /* Loads a phase value in a register. */ |
| 110 | void AD9833_SetPhase(unsigned char registerNumber, float phaseValue); |
| 111 | /* Select the frequency register to be used. */ |
| 112 | void AD9833_SelectFreqReg(unsigned char freqReg); |
| 113 | /* Select the phase register to be used. */ |
| 114 | void AD9833_SelectPhaseReg(unsigned char phaseReg); |
| 115 | /* Enable / Disable the sleep function. */ |
| 116 | void AD9833_SleepMode(unsigned char sleepMode); |
| 117 | |
| 118 | void AD9834_SelectProgMethod(unsigned char value); |
| 119 | |
| 120 | void AD9834_LogicOutput(unsigned char opbiten, |
| 121 | unsigned char signpib, |
| 122 | unsigned char div2); |
| 123 | |
| 124 | #endif /* _AD9833_H_ */ |