control for DAC AD5384 for the SOLID SM1 Slow Control
Diff: AD5384.cpp
- Revision:
- 3:7ca85ed310e0
- Parent:
- 2:fc250e37a028
- Child:
- 4:bc9ab300ab26
diff -r fc250e37a028 -r 7ca85ed310e0 AD5384.cpp --- a/AD5384.cpp Mon Oct 06 22:25:16 2014 +0000 +++ b/AD5384.cpp Wed Oct 08 10:43:18 2014 +0000 @@ -5,8 +5,12 @@ #define p2_14 16384 #define p2_13 8192 -#define C_ACTIVE 1 -#define C_DEACTIVE 0 +#define CS_ACTIVE 1 +#define CS_DEACTIVE 0 + +#define RST_ACTIVE 1 +#define RST_DEACTIVE 0 + // spi mode has to be set for each transmission as spi bus can be shared @@ -16,10 +20,11 @@ * v1.11 added init 1 and init 2 function an ctrlreg defs * v1.12 * v1.13 corrected channel mask from 0x1F to 0x3F + * v1.20 added hw_rst , added hwrst to init1 not in init2 * */ -#define AD5384_SRC_VERSION "1.13" +#define AD5384_SRC_VERSION "1.23" #define M_DATA_R 0x3 #define M_OFFS_R 0x2 @@ -61,10 +66,11 @@ -AD5384::AD5384(SWSPI *spiinterface ,DigitalOut* chipselect):getVersion( VERSION_AD5384_HDR,AD5384_SRC_VERSION, __TIME__, __DATE__) { +AD5384::AD5384(SWSPI *spiinterface ,DigitalOut* chipselect, DigitalOut* reset):getVersion( VERSION_AD5384_HDR,AD5384_SRC_VERSION, __TIME__, __DATE__) { vref=2.5; spi=spiinterface; cs=chipselect; + rst=reset; for ( int nc=0 ; nc < nrch; nc++){ gain[nc]=0x3FFE; offset[nc]=0x2000; @@ -114,14 +120,15 @@ u16 dacin=calculate_dac_setting(ch, vout ); set_spi_mode(); u32 data=format_word(M_DATA_R,ch,0,dacin); - cs->write(C_ACTIVE); + cs->write(CS_ACTIVE); spi->write(data); - cs->write(C_DEACTIVE); + cs->write(CS_DEACTIVE); return dacin; } void AD5384::init1(){ u16 ctrlreg=0; + hw_rst(); ctrlreg = (INT_REF_2500 | REF_SRC_INT ) & TOGGLE_DISABLE; set_reg(M_SPEC_R,CTRL_REG_ADDR,ctrlreg); @@ -175,22 +182,22 @@ set_spi_mode(); value=value & 0x3FFF; u32 data=format_word(mode,ch,0,value); - cs->write(C_ACTIVE); + cs->write(CS_ACTIVE); spi->write(data); - cs->write(C_DEACTIVE); + cs->write(CS_DEACTIVE); return data; } u16 AD5384::get_reg(u8 mode, u8 ch ){ set_spi_mode(); u32 data=format_word(mode,ch,1,0); - cs->write(C_ACTIVE); + cs->write(CS_ACTIVE); spi->write(data); - cs->write(C_DEACTIVE); + cs->write(CS_DEACTIVE); wait( .00001); - cs->write(C_ACTIVE); + cs->write(CS_ACTIVE); data=spi->write(NOP_INST); - cs->write(C_DEACTIVE); + cs->write(CS_DEACTIVE); return (u16) data; } @@ -222,13 +229,22 @@ u16 AD5384::get_ch_out_reg(u8 ch) { u32 data=format_word(M_DATA_R,ch,1,0); - cs->write(C_ACTIVE); + cs->write(CS_ACTIVE); spi->write(data); - cs->write(C_DEACTIVE); + cs->write(CS_DEACTIVE); wait( .00001); - cs->write(C_ACTIVE); + cs->write(CS_ACTIVE); data=spi->write(NOP_INST); - cs->write(C_DEACTIVE); + cs->write(CS_DEACTIVE); return (u16) data; } + + void AD5384::hw_rst(){ + rst->write( RST_ACTIVE); // edge sensitive + wait_us(30); + rst->write( RST_DEACTIVE); + wait_us(300); // 270 us according data sheet + +} + \ No newline at end of file