GROZEA ION / AD5235
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AD5235.h Source File

AD5235.h

00001 #ifndef AD5235_H
00002 #define AD5235_H
00003  
00004 #include "mbed.h"
00005 //Data Sheet http://www.analog.com/media/en/technical-documentation/data-sheets/AD5235.pdf
00006 
00007 //Control Registers
00008 #define CMD_NOP 0x00 //0- Do nothing
00009     //EEMEM No.-Address-----EEMEM Content for …
00010     //1         0000        RDAC1
00011     //2         0001        RDAC2
00012     //3         0010        USER1
00013     //4         0011        USER2
00014     //…         …           …
00015     //15        1110        USER13
00016     //16        1111        RAB1 tolerance
00017 
00018     //Instruction 3 writes two data bytes (16 bits of data) to EEMEM.
00019     //In the case of Address 0 and Address 1, only the last 10 bits
00020     //are valid for wiper position setting.
00021     //Basicaly it is CMD_USER2MEM + User mem address + user = B0011A3A2A1A0 + user
00022     //  A3  A2  A1  A0  
00023     //  0   0   0   0   RDAC1
00024     //  0   0   0   1   RDAC2
00025     //  1   1   1   1   Tolerance   Read Only
00026 
00027 class AD5235 {
00028     SPI& spi;
00029     DigitalOut cs;    
00030 public:
00031     AD5235(SPI& _spi, PinName _cs);
00032     void storeEEMEM2RDAC(uint8_t w);//1 - Restore EEMEM (A0) contents to RDAC (A0) register. See Table 16.
00033     void storeRDAC2EEMEM(uint8_t w);//2 - Store wiper setting. Store RDAC (A0) setting to EEMEM (A0). See Table 15. - Use a delay of 50ms!!!
00034     void setEEMEM(uint8_t w, uint16_t v);//3 - Store contents of Serial Register Data Byte 0 and Serial Register Data Bytes 1 (total 16 bits) to EEMEM (ADDR). See Table 18.- Use a delay of 50ms!!!/RDAC1 is 0, RDAC2 is 1, User1 is 2....User13 is 14
00035     void stepDown6Db(uint8_t w);//4 - Decrement by 6 dB. Right-shift contents of RDAC (A0) register, stop at all 0s.
00036     void stepDownAll6Db(void);//5 - Decrement all by 6 dB. Right-shift contents of all RDAC registers, stop at all 0s.
00037     void stepDown1(uint8_t w);//6 - Decrement contents of RDAC (A0) by 1, stop at all 0s.
00038     void stepDown1All(void);//7 - Decrement contents of all RDAC registers by 1, stop at all 0s.
00039     void refreshAllRDAC(void);//8 - Reset. Refresh all RDACs with their corresponding EEMEM previously stored values. - Use a delay of 30us!!!
00040     uint16_t getEEMEM(uint8_t w);//9 - Read contents of EEMEM (ADDR) from SDO output in the next frame. See Table 19. - Use a delay of 30us!!!
00041     uint16_t getWiper(uint8_t w);//10 - Read RDAC wiper setting from SDO output in the next frame. See Table 20. - Use a delay of 30us!!!
00042     void setWiper(uint8_t w, uint16_t v);//11 - Write contents of Serial Register Data Byte 0 and Serial Register Data Byte 1 (total 10 bits) to RDAC (A0). See Table 14.
00043     void stepUp6Db(uint8_t w);//12 - Increment by 6 dB: Left-shift contents of RDAC (A0),stop at all 1s. See Table 17.
00044     void stepUpAll6Db(void);//13 - Increment all by 6 dB. Left-shift contents of all RDAC registers, stop at all 1s.
00045     void stepUp1(uint8_t w);//14 - Increment contents of RDAC (A0) by 1, stop at all 1s. See Table 15.
00046     void stepUp1All(void);//15 - Increment contents of all RDAC registers by 1, stop at all 1s.
00047     void repeatCMD(void);//16 - See page 21 in manual Another subtle feature of the AD5235 is that a subsequent CS strobe, withoutclock and data, repeats a previous command
00048     float getTolerance(void);
00049 private:  
00050 uint16_t _reply;
00051 PinName _CS_pin;
00052 uint16_t transferData(uint8_t cmd, uint16_t val);
00053 };
00054 #endif