AD5384 DAC.
Fork of AD5384 by
AD5384.h@3:0d930c475e72, 2014-10-07 (annotated)
- Committer:
- NickRyder
- Date:
- Tue Oct 07 21:17:50 2014 +0000
- Revision:
- 3:0d930c475e72
- Parent:
- 1:d2d6341d3e97
Tidying up.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wbeaumont | 0:33bb5081488a | 1 | #ifndef AD5384_H |
wbeaumont | 0:33bb5081488a | 2 | #define AD5384_H |
wbeaumont | 0:33bb5081488a | 3 | |
wbeaumont | 0:33bb5081488a | 4 | #include "solid_sctrl_def.h" |
wbeaumont | 0:33bb5081488a | 5 | #include "SWSPI.h" |
wbeaumont | 1:d2d6341d3e97 | 6 | #include "getVersion.h" |
wbeaumont | 0:33bb5081488a | 7 | |
wbeaumont | 1:d2d6341d3e97 | 8 | #define VERSION_AD5384_HDR "1.12" |
wbeaumont | 0:33bb5081488a | 9 | |
wbeaumont | 0:33bb5081488a | 10 | |
wbeaumont | 0:33bb5081488a | 11 | /* |
wbeaumont | 0:33bb5081488a | 12 | * class to set and readback the AD5384 |
wbeaumont | 0:33bb5081488a | 13 | * to minimize the access to the device there is a shadow of the DAC, GAIN and OFFSET values |
wbeaumont | 0:33bb5081488a | 14 | |
wbeaumont | 1:d2d6341d3e97 | 15 | * v0.10 initial development to see if reading / writing is possible |
wbeaumont | 1:d2d6341d3e97 | 16 | * v1.10 initial release versioni |
wbeaumont | 1:d2d6341d3e97 | 17 | * v1.11 added init1 init2 |
wbeaumont | 0:33bb5081488a | 18 | */ |
wbeaumont | 0:33bb5081488a | 19 | class SWSPI; |
wbeaumont | 0:33bb5081488a | 20 | #include "mbed.h" |
wbeaumont | 0:33bb5081488a | 21 | //class DigitalOut; |
wbeaumont | 0:33bb5081488a | 22 | |
wbeaumont | 1:d2d6341d3e97 | 23 | class AD5384 : public getVersion { |
NickRyder | 3:0d930c475e72 | 24 | SWSPI *spi; |
NickRyder | 3:0d930c475e72 | 25 | DigitalOut * cs; |
wbeaumont | 0:33bb5081488a | 26 | float vref; |
wbeaumont | 0:33bb5081488a | 27 | |
wbeaumont | 0:33bb5081488a | 28 | void set_spi_mode(); |
NickRyder | 3:0d930c475e72 | 29 | u16 calculate_dac_setting(u8 nr, float vout); |
NickRyder | 3:0d930c475e72 | 30 | u32 format_word(u8 mode, u8 ch, u8 rw, u16 data); |
NickRyder | 3:0d930c475e72 | 31 | u16 get_reg(u8 mode, u8 ch); |
NickRyder | 3:0d930c475e72 | 32 | u32 set_reg(u8 mode, u8 ch, u16 value); |
wbeaumont | 0:33bb5081488a | 33 | public: |
NickRyder | 3:0d930c475e72 | 34 | AD5384(SWSPI * spiinterface, DigitalOut * chipselect); |
wbeaumont | 0:33bb5081488a | 35 | |
wbeaumont | 0:33bb5081488a | 36 | u16 dac[40]; |
wbeaumont | 0:33bb5081488a | 37 | u16 gain[40]; |
wbeaumont | 0:33bb5081488a | 38 | u16 offset[40]; |
wbeaumont | 0:33bb5081488a | 39 | float volt[40]; |
NickRyder | 3:0d930c475e72 | 40 | u16 get_dac(u8 ch); |
NickRyder | 3:0d930c475e72 | 41 | u16 set_dac(u8 ch, u16 dac); |
NickRyder | 3:0d930c475e72 | 42 | u16 get_ch_out_reg(u8 ch) ; |
NickRyder | 3:0d930c475e72 | 43 | u16 set_volt(u8 nr, float vout); |
NickRyder | 3:0d930c475e72 | 44 | u16 set_gain(u8 ch, u16 gain); |
NickRyder | 3:0d930c475e72 | 45 | u16 get_gain(u8 ch); |
NickRyder | 3:0d930c475e72 | 46 | u16 set_offset(u8 ch, u16 gain); |
NickRyder | 3:0d930c475e72 | 47 | u16 get_offset(u8 ch); |
NickRyder | 3:0d930c475e72 | 48 | // ctnrls |
NickRyder | 3:0d930c475e72 | 49 | u32 get_ctrl(); |
NickRyder | 3:0d930c475e72 | 50 | u32 soft_clr(); |
NickRyder | 3:0d930c475e72 | 51 | u32 soft_rst(); |
NickRyder | 3:0d930c475e72 | 52 | u32 clear_code(); |
NickRyder | 3:0d930c475e72 | 53 | void init1(); |
NickRyder | 3:0d930c475e72 | 54 | void init2(); |
wbeaumont | 0:33bb5081488a | 55 | }; |
wbeaumont | 0:33bb5081488a | 56 | |
wbeaumont | 0:33bb5081488a | 57 | #endif |