control for DAC AD5384 for the SOLID SM1 Slow Control

Dependents:   SPItest sscm

AD5384.h

Committer:
wbeaumont
Date:
2015-01-29
Revision:
5:477603ce54a0
Parent:
4:bc9ab300ab26

File content as of revision 5:477603ce54a0:

#ifndef AD5384_H
#define AD5384_H

#include "solid_sctrl_def.h"
#include "SWSPI.h"
#include "getVersion.h"

#define VERSION_AD5384_HDR "1.30"


/*
 * class to set and readback the AD5384
 * to minimize the access to the device there is a shadow of the DAC, GAIN and OFFSET values 
    
 * v0.10  initial development to see if reading / writing is possible    
 * v1.10  initial  release versioni
 * v1.11  added init1 init2
 * v1.20  added rst pin
 * v1.24  added update shadow registers 
 * v1.30  added get volt
*/ 
class SWSPI;
#include "mbed.h"
//class DigitalOut;

class AD5384 : public getVersion {
    SWSPI *spi ;
    DigitalOut* cs; 
    DigitalOut* rst;
    float vref;
    
    void set_spi_mode();
    u16 calculate_dac_setting(u8 nr, float vout );
    u32 format_word(u8 mode,u8 ch,u8 rw,u16 data) ;
    u16 get_reg(u8 mode, u8 ch   );
    u32  set_reg(u8 mode,u8 ch, u16 value  );
    
    void update_gain_shadow(u8 ch ) ;
    void update_offset_shadow(u8 ch ) ;
    void update_dac_shadow(u8 ch );
    
    public: 
        AD5384(SWSPI *spiinterface ,DigitalOut* chipselect,DigitalOut* reset );
        // channel shadow registers
        u16 dacr[40];
        u16 gain[40];
        u16 offset[40];
        float volt[40];
       u16 get_dac(u8 ch);
       u16 set_dac( u8 ch, u16 dac);
       u16 get_ch_out_reg(u8 ch) ;
       u16 set_volt(u8 nr, float vout );
       // if read all reg the gain and offset register is  read
       // otherwise the shadow register offset and gain are used
       float get_volt(u8 nr, bool readallreg=false );
       u16 set_gain(u8 ch, u16 gain  );
       u16 get_gain(u8 ch );
       u16 set_offset(u8 ch, u16 gain);
       u16 get_offset(u8 ch  );
       void hw_rst();
       // ctnrls
       u32 get_ctrl();
       u32 soft_clr();
       u32 soft_rst();
       u32 clear_code();
       void init1();
       void init2();
       
        
 
};

#endif