ADF4360 - See http://mbed.org/forum/helloworld/topic/1430

Committer:
AjK
Date:
Mon Nov 22 13:21:24 2010 +0000
Revision:
1:4037b46f2040
Parent:
0:528dac948be7
Child:
2:e4d7ec6aeceb
1.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 0:528dac948be7 1 /*
AjK 0:528dac948be7 2 Copyright (c) 2010 Andy Kirkham
AjK 0:528dac948be7 3
AjK 0:528dac948be7 4 Permission is hereby granted, free of charge, to any person obtaining a copy
AjK 0:528dac948be7 5 of this software and associated documentation files (the "Software"), to deal
AjK 0:528dac948be7 6 in the Software without restriction, including without limitation the rights
AjK 0:528dac948be7 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
AjK 0:528dac948be7 8 copies of the Software, and to permit persons to whom the Software is
AjK 0:528dac948be7 9 furnished to do so, subject to the following conditions:
AjK 0:528dac948be7 10
AjK 0:528dac948be7 11 The above copyright notice and this permission notice shall be included in
AjK 0:528dac948be7 12 all copies or substantial portions of the Software.
AjK 0:528dac948be7 13
AjK 0:528dac948be7 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
AjK 0:528dac948be7 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
AjK 0:528dac948be7 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AjK 0:528dac948be7 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AjK 0:528dac948be7 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AjK 0:528dac948be7 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
AjK 0:528dac948be7 20 THE SOFTWARE.
AjK 0:528dac948be7 21 */
AjK 0:528dac948be7 22
AjK 0:528dac948be7 23 #ifndef MODADF4360_H
AjK 0:528dac948be7 24 #define MODADF4360_H
AjK 0:528dac948be7 25
AjK 0:528dac948be7 26 #include "mbed.h"
AjK 0:528dac948be7 27
AjK 0:528dac948be7 28 #define GET_CNTL_LATCH(pos,mask) return(control_latch>>pos)&mask
AjK 0:528dac948be7 29 #define SET_CNTL_LATCH(pos,mask,n) control_latch&=~(mask<<pos);control_latch|=((n&mask)<<pos)
AjK 0:528dac948be7 30 #define GET_N_LATCH(pos,mask) return(counterNlatch>>pos)&mask
AjK 0:528dac948be7 31 #define SET_N_LATCH(pos,mask,n) counterNlatch&=~(mask<<pos);counterNlatch|=((n&mask)<<pos)
AjK 0:528dac948be7 32 #define GET_R_LATCH(pos,mask) return(counterRlatch>>pos)&mask
AjK 0:528dac948be7 33 #define SET_R_LATCH(pos,mask,n) counterRlatch&=~(mask<<pos);counterRlatch|=((n&mask)<<pos)
AjK 0:528dac948be7 34
AjK 0:528dac948be7 35 /** @defgroup Control_Latch The Control Latch */
AjK 0:528dac948be7 36 /** @defgroup Counter_N_Latch The Counter N Latch */
AjK 0:528dac948be7 37 /** @defgroup Counter_R_Latch The Counter R Latch */
AjK 0:528dac948be7 38
AjK 1:4037b46f2040 39 /**
AjK 1:4037b46f2040 40 * @author Andy Kirkham
AjK 1:4037b46f2040 41 * @see Control_Latch
AjK 1:4037b46f2040 42 * @see Counter_N_Latch
AjK 1:4037b46f2040 43 * @see Counter_R_Latch
AjK 1:4037b46f2040 44 *
AjK 1:4037b46f2040 45 * <b>MODADF4360</b> Test library
AjK 1:4037b46f2040 46 *
AjK 1:4037b46f2040 47 * Standard example:
AjK 1:4037b46f2040 48 * @code
AjK 1:4037b46f2040 49 * #include "mbed.h"
AjK 1:4037b46f2040 50 * #include "MODADF4360.h"
AjK 1:4037b46f2040 51 *
AjK 1:4037b46f2040 52 * DigitalOut led1(LED1);
AjK 1:4037b46f2040 53 * ADF4360 adf(p5, p6, p7, p8);
AjK 1:4037b46f2040 54 *
AjK 1:4037b46f2040 55 * int main() {
AjK 1:4037b46f2040 56 *
AjK 1:4037b46f2040 57 * // Setup all the parts of the Control Latch
AjK 1:4037b46f2040 58 * adf.prescalerValue(1);
AjK 1:4037b46f2040 59 * adf.cpGain(1);
AjK 1:4037b46f2040 60 * //... set all the parts you need, then...
AjK 1:4037b46f2040 61 *
AjK 1:4037b46f2040 62 * // Once all the parts ate set, write them to the device.
AjK 1:4037b46f2040 63 * adf.controlLatchWrite();
AjK 1:4037b46f2040 64 *
AjK 1:4037b46f2040 65 * // repeat for N and R latches.
AjK 1:4037b46f2040 66 *
AjK 1:4037b46f2040 67 * while(1) {
AjK 1:4037b46f2040 68 * led1 = !led1;
AjK 1:4037b46f2040 69 * wait(1);
AjK 1:4037b46f2040 70 * }
AjK 1:4037b46f2040 71 * }
AjK 1:4037b46f2040 72 * @endcode
AjK 1:4037b46f2040 73 */
AjK 0:528dac948be7 74 class ADF4360 {
AjK 0:528dac948be7 75 public:
AjK 0:528dac948be7 76
AjK 0:528dac948be7 77 ADF4360(PinName mosi, PinName miso, PinName sclk, PinName le) {
AjK 0:528dac948be7 78 _le = new DigitalOut(le);
AjK 0:528dac948be7 79 _le->write(1);
AjK 0:528dac948be7 80 _ssp = new SPI(mosi, miso, sclk);
AjK 0:528dac948be7 81 _ssp->format(8,0);
AjK 0:528dac948be7 82 _ssp->frequency(1000000);
AjK 0:528dac948be7 83 };
AjK 0:528dac948be7 84
AjK 0:528dac948be7 85 ~ADF4360() { delete(_le); delete(_ssp); };
AjK 0:528dac948be7 86
AjK 0:528dac948be7 87 /** @ingroup Control_Latch */
AjK 0:528dac948be7 88 int prescalerValue(void) { GET_CNTL_LATCH(22,3); }
AjK 0:528dac948be7 89 /** @ingroup Control_Latch */
AjK 0:528dac948be7 90 void prescalerValue(int i) { SET_CNTL_LATCH(22,3UL,i); }
AjK 0:528dac948be7 91
AjK 0:528dac948be7 92 /** @ingroup Control_Latch */
AjK 0:528dac948be7 93 int powerDown2(void) { GET_CNTL_LATCH(21,1); }
AjK 0:528dac948be7 94 /** @ingroup Control_Latch */
AjK 0:528dac948be7 95 void powerDown2(int i) { SET_CNTL_LATCH(21,1UL,i); }
AjK 0:528dac948be7 96
AjK 0:528dac948be7 97 /** @ingroup Control_Latch */
AjK 0:528dac948be7 98 int powerDown1(void) { GET_CNTL_LATCH(20,1); }
AjK 0:528dac948be7 99 /** @ingroup Control_Latch */
AjK 0:528dac948be7 100 void powerDown1(int i) { SET_CNTL_LATCH(20,1UL,i); }
AjK 0:528dac948be7 101
AjK 0:528dac948be7 102 /** @ingroup Control_Latch */
AjK 0:528dac948be7 103 int currentSetting2(void) { GET_CNTL_LATCH(17,7); }
AjK 0:528dac948be7 104 /** @ingroup Control_Latch */
AjK 0:528dac948be7 105 void currentSetting2(int i) { SET_CNTL_LATCH(17,7UL,i); }
AjK 0:528dac948be7 106
AjK 0:528dac948be7 107 /** @ingroup Control_Latch */
AjK 0:528dac948be7 108 int currentSetting1(void) { GET_CNTL_LATCH(14,7); }
AjK 0:528dac948be7 109 /** @ingroup Control_Latch */
AjK 0:528dac948be7 110 void currentSetting1(int i) { SET_CNTL_LATCH(14,7UL,i); }
AjK 0:528dac948be7 111
AjK 0:528dac948be7 112 /** @ingroup Control_Latch */
AjK 0:528dac948be7 113 int outputPowerLevel(void) { GET_CNTL_LATCH(12,3); }
AjK 0:528dac948be7 114 /** @ingroup Control_Latch */
AjK 0:528dac948be7 115 void outputPowerLevel(int i) { SET_CNTL_LATCH(12,3UL,i); }
AjK 0:528dac948be7 116
AjK 0:528dac948be7 117 /** @ingroup Control_Latch */
AjK 0:528dac948be7 118 int muteTillLockDetect(void) { GET_CNTL_LATCH(11,1); }
AjK 0:528dac948be7 119 /** @ingroup Control_Latch */
AjK 0:528dac948be7 120 void muteTillLockDetect(int i) { SET_CNTL_LATCH(11,1UL,i); }
AjK 0:528dac948be7 121
AjK 0:528dac948be7 122 /** @ingroup Control_Latch */
AjK 0:528dac948be7 123 int cpGain(void) { GET_CNTL_LATCH(10,1); }
AjK 0:528dac948be7 124 /** @ingroup Control_Latch */
AjK 0:528dac948be7 125 void cpGain(int i) { SET_CNTL_LATCH(10,1UL,i); }
AjK 0:528dac948be7 126
AjK 0:528dac948be7 127 /** @ingroup Control_Latch */
AjK 0:528dac948be7 128 int cpOutput(void) { GET_CNTL_LATCH(9,1); }
AjK 0:528dac948be7 129 /** @ingroup Control_Latch */
AjK 0:528dac948be7 130 void cpOutput(int i) { SET_CNTL_LATCH(9,1UL,i); }
AjK 0:528dac948be7 131
AjK 0:528dac948be7 132 /** @ingroup Control_Latch */
AjK 0:528dac948be7 133 int phaseDetectPol(void) { GET_CNTL_LATCH(8,1); }
AjK 0:528dac948be7 134 /** @ingroup Control_Latch */
AjK 0:528dac948be7 135 void phaseDetectPol(int i) { SET_CNTL_LATCH(8,1UL,i); }
AjK 0:528dac948be7 136
AjK 0:528dac948be7 137 /** @ingroup Control_Latch */
AjK 0:528dac948be7 138 int muxControl(void) { GET_CNTL_LATCH(5,7); }
AjK 0:528dac948be7 139 /** @ingroup Control_Latch */
AjK 0:528dac948be7 140 void muxControl(int i) { SET_CNTL_LATCH(5,7UL,i); }
AjK 0:528dac948be7 141
AjK 0:528dac948be7 142 /** @ingroup Control_Latch */
AjK 0:528dac948be7 143 int counterReset(void) { GET_CNTL_LATCH(4,1); }
AjK 0:528dac948be7 144 /** @ingroup Control_Latch */
AjK 0:528dac948be7 145 void counterReset(int i) { SET_CNTL_LATCH(4,1UL,i); }
AjK 0:528dac948be7 146
AjK 0:528dac948be7 147 /** @ingroup Control_Latch */
AjK 0:528dac948be7 148 int corePowerLevel(void) { GET_CNTL_LATCH(2,3); }
AjK 0:528dac948be7 149 /** @ingroup Control_Latch */
AjK 0:528dac948be7 150 void corePowerLevel(int i) { SET_CNTL_LATCH(2,3UL,i); }
AjK 0:528dac948be7 151
AjK 0:528dac948be7 152 void controlLatchWrite(void) {
AjK 0:528dac948be7 153 _le->write(0);
AjK 0:528dac948be7 154 _ssp->write((control_latch >> 16) & 0xFF);
AjK 0:528dac948be7 155 _ssp->write((control_latch >> 8) & 0xFF);
AjK 0:528dac948be7 156 _ssp->write((control_latch & 0xFF) & ~(3UL << 0));
AjK 0:528dac948be7 157 _le->write(1);
AjK 0:528dac948be7 158 }
AjK 0:528dac948be7 159
AjK 0:528dac948be7 160 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 161 int divideBy2Select(void) { GET_N_LATCH(23,1); }
AjK 0:528dac948be7 162 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 163 void divideBy2Select(int i) { SET_N_LATCH(23,1UL,i); }
AjK 0:528dac948be7 164
AjK 0:528dac948be7 165 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 166 int divideBy2(void) { GET_N_LATCH(22,1); }
AjK 0:528dac948be7 167 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 168 void divideBy2(int i) { SET_N_LATCH(22,1UL,i); }
AjK 0:528dac948be7 169
AjK 0:528dac948be7 170 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 171 int nCPGain(void) { GET_N_LATCH(21,1); }
AjK 0:528dac948be7 172 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 173 void nCPGain(int i) { SET_N_LATCH(21,1UL,i); }
AjK 0:528dac948be7 174
AjK 0:528dac948be7 175 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 176 int counterB(void) { GET_N_LATCH(8,0x1FFF); }
AjK 0:528dac948be7 177 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 178 void counterB(int i) { SET_N_LATCH(8,0x1FFFUL,i); }
AjK 0:528dac948be7 179
AjK 0:528dac948be7 180 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 181 int counterA(void) { GET_N_LATCH(2,0x1F); }
AjK 0:528dac948be7 182 /** @ingroup Counter_N_Latch */
AjK 0:528dac948be7 183 void counterA(int i) { SET_N_LATCH(2,0x1FUL,i); }
AjK 0:528dac948be7 184
AjK 0:528dac948be7 185 void counterNWrite(void) {
AjK 0:528dac948be7 186 _le->write(0);
AjK 0:528dac948be7 187 _ssp->write((counterNlatch >> 16) & 0xFF);
AjK 0:528dac948be7 188 _ssp->write((counterNlatch >> 8) & 0xFF);
AjK 0:528dac948be7 189 _ssp->write(((counterNlatch & 0xFF) & ~(0x3CUL << 0)) | (2UL << 0));
AjK 0:528dac948be7 190 _le->write(1);
AjK 0:528dac948be7 191 }
AjK 0:528dac948be7 192
AjK 0:528dac948be7 193 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 194 int bandSelectClock(void) { GET_R_LATCH(20,3); }
AjK 0:528dac948be7 195 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 196 void bandSelectClock(int i) { SET_R_LATCH(20,3UL,i); }
AjK 0:528dac948be7 197
AjK 0:528dac948be7 198 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 199 int testModeBit(void) { GET_R_LATCH(19,1); }
AjK 0:528dac948be7 200 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 201 void testModeBit(int i) { SET_R_LATCH(19,1UL,i); }
AjK 0:528dac948be7 202
AjK 0:528dac948be7 203 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 204 int lockDetect(void) { GET_R_LATCH(18,1); }
AjK 0:528dac948be7 205 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 206 void lockDetect(int i) { SET_R_LATCH(18,1UL,i); }
AjK 0:528dac948be7 207
AjK 0:528dac948be7 208 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 209 int antiBacklash(void) { GET_R_LATCH(16,3); }
AjK 0:528dac948be7 210 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 211 void antiBacklash(int i) { SET_R_LATCH(16,3UL,i); }
AjK 0:528dac948be7 212
AjK 0:528dac948be7 213 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 214 int counterRef(void) { GET_R_LATCH(2,0x3FFF); }
AjK 0:528dac948be7 215 /** @ingroup Counter_R_Latch */
AjK 0:528dac948be7 216 void counterRef(int i) { SET_R_LATCH(2,0x3FFFUL,i); }
AjK 0:528dac948be7 217
AjK 0:528dac948be7 218 void counterRWrite(void) {
AjK 0:528dac948be7 219 _le->write(0);
AjK 0:528dac948be7 220 _ssp->write((counterRlatch >> 16) & 0xFF);
AjK 0:528dac948be7 221 _ssp->write((counterRlatch >> 8) & 0xFF);
AjK 0:528dac948be7 222 _ssp->write(((counterRlatch & 0xFF) & ~(0x3CUL << 0)) | (1UL << 0));
AjK 0:528dac948be7 223 _le->write(1);
AjK 0:528dac948be7 224 }
AjK 0:528dac948be7 225
AjK 0:528dac948be7 226 protected:
AjK 0:528dac948be7 227
AjK 0:528dac948be7 228 uint32_t control_latch;
AjK 0:528dac948be7 229 uint32_t counterNlatch;
AjK 0:528dac948be7 230 uint32_t counterRlatch;
AjK 0:528dac948be7 231
AjK 0:528dac948be7 232 SPI *_ssp;
AjK 0:528dac948be7 233 DigitalOut *_le;
AjK 0:528dac948be7 234 };
AjK 0:528dac948be7 235
AjK 0:528dac948be7 236
AjK 0:528dac948be7 237 #endif