The AD8556 is a zero-drift, sensor signal amplifier with digitally programmable gain and output offset.
Revision 0:05eaa16f3327, committed 2013-09-11
- Comitter:
- fblanc
- Date:
- Wed Sep 11 13:30:19 2013 +0000
- Commit message:
- OK
Changed in this revision
AD8556.cpp | Show annotated file Show diff for this revision Revisions of this file |
AD8556.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 05eaa16f3327 AD8556.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AD8556.cpp Wed Sep 11 13:30:19 2013 +0000 @@ -0,0 +1,204 @@ +/** + * @brief AD8556: Digitally Programmable Sensor Signal Amplifier with EMI Filters + * http://www.analog.com/en/specialty-amplifiers/instrumentation-amplifiers/ad8556/products/product.html + * @date 05/09/2013 + * @author F.BLANC LAAS-CNRS + * http://homepages.laas.fr/fblanc/ + */ + +#include "AD8556.h" + +/** + * @brief Constructor. + * + * @param dig + + */ +AD8556::AD8556(PinName dig) : _dig(dig) +{ +} + +/** + * @brief Destructor. + */ +AD8556::~AD8556() +{ +} + + + + + +/** + * @brief init + * @param mode + * @param First_Stage_Gain_Code + * @param Second_Stage_Gain_Code + * @param Vdac_Code + */ +int AD8556::init(unsigned char mode,unsigned char First_Stage_Gain_Code, unsigned char Second_Stage_Gain_Code,unsigned char Vdac_Code) +{ + trame(ADC_Second_Stage_Gain_Code,mode,Second_Stage_Gain_Code); + trame(ADC_First_Stage_Gain_Code,mode,First_Stage_Gain_Code); + trame(ADC_Output_Offset_Code,mode,Vdac_Code); + return 0; +} + +/** + * @brief trame + * @param parameter + * @param mode + * @param data + */ +void AD8556::trame(unsigned char parameter,unsigned char mode,unsigned char data) +{ + //12-Bit Start of Packet 1000 0000 0001 + write_bit(1); + for(unsigned char i=0; i<10; ++i) + write_bit(0); + write_bit(1); + //2-Bit Function + switch (mode) { + case ADC_MODE_SENSE_CURENT : + write_bit(0); + write_bit(0); + break; + case ADC_MODE_SIMULATION : + write_bit(0); + write_bit(1); + break; + case ADC_MODE_FUSE : + write_bit(1); + write_bit(0); + break; + case ADC_MODE_READ : + write_bit(1); + write_bit(1); + break; + } + //2-Bit Parameter + switch (parameter) { + case ADC_Second_Stage_Gain_Code : + write_bit(0); + write_bit(0); + break; + case ADC_First_Stage_Gain_Code : + write_bit(0); + write_bit(1); + break; + case ADC_Output_Offset_Code : + write_bit(1); + write_bit(0); + break; + case ADC_Other_Functions : + write_bit(1); + write_bit(1); + break; + } + + + //2-Bit Dummy 10 + write_bit(1); + write_bit(0); + //8-Bit Value + for(char i=0; i<8; ++i) { + write_bit( data & (0x80>>i) ); + } + //12-Bit End of Packet 1000 0000 0001 + write_bit(0); + for(unsigned char i=0; i<10; ++i) + write_bit(1); + write_bit(0); +} + +/** + * @brief write_bit + * + * @param bit 1 or 0 + */ +void AD8556::write_bit(unsigned char bit) +{ + _dig = 0; + _dig.output(); + wait_us(10); + _dig = 1; + if ( bit ) + wait_us(50); //1 + wait_us(5); + _dig = 0; + wait_us(10); +} + +/** + * @brief vdac + * @param vdac consigne (volt) + * @param vdd positive voltage supply (volt) + * @param vss nagative voltage supply (volt) + * @param mode + */ +void AD8556::prog_vdac(float vdac,float vdd,float vss, unsigned char mode) +{ + unsigned char Vdac_Code; + Vdac_Code=256*(vdac-vss)/(vdd-vss)-0.5; + trame(ADC_Output_Offset_Code,mode,Vdac_Code); + +} +/** + * @brief prog_gain + * @param gain 70 to 1280 + * @param mode + */ +void AD8556::prog_gain(float gain, unsigned char mode) +{ +float Second_Stage_Gain; +int First_Stage_Gain_Code; + if (gain<70) { + trame(ADC_Second_Stage_Gain_Code,mode,0); + trame(ADC_First_Stage_Gain_Code,mode,0); + } else if (gain<100) { + trame(ADC_Second_Stage_Gain_Code,mode,0); + Second_Stage_Gain=17.5; + First_Stage_Gain_Code=(int)(((gain/Second_Stage_Gain)-4.0)*66.7); + trame(ADC_First_Stage_Gain_Code, mode, First_Stage_Gain_Code); + } else if (gain<140) { + trame(ADC_Second_Stage_Gain_Code,mode,1); + int First_Stage_Gain_Code=(int)gain/25; + Second_Stage_Gain=25; + First_Stage_Gain_Code=(int)(((gain/Second_Stage_Gain)-4.0)*66.7); + trame(ADC_First_Stage_Gain_Code, mode, First_Stage_Gain_Code); + } else if (gain<200) { + trame(ADC_Second_Stage_Gain_Code,mode,2); + Second_Stage_Gain=35; + First_Stage_Gain_Code=(int)(((gain/Second_Stage_Gain)-4.0)*66.7); + trame(ADC_First_Stage_Gain_Code, mode, First_Stage_Gain_Code); + } else if (gain<280) { + trame(ADC_Second_Stage_Gain_Code,mode,3); + Second_Stage_Gain=50; + First_Stage_Gain_Code=(int)(((gain/Second_Stage_Gain)-4.0)*66.7); + trame(ADC_First_Stage_Gain_Code, mode, First_Stage_Gain_Code); + } else if (gain<400) { + trame(ADC_Second_Stage_Gain_Code,mode,4); + Second_Stage_Gain=70; + First_Stage_Gain_Code=(int)(((gain/Second_Stage_Gain)-4.0)*66.7); + trame(ADC_First_Stage_Gain_Code, mode, First_Stage_Gain_Code); + } else if (gain<560) { + trame(ADC_Second_Stage_Gain_Code,mode,5); + Second_Stage_Gain=100; + First_Stage_Gain_Code=(int)(((gain/Second_Stage_Gain)-4.0)*66.7); + trame(ADC_First_Stage_Gain_Code, mode, First_Stage_Gain_Code); + } else if (gain<800) { + trame(ADC_Second_Stage_Gain_Code,mode,6); + Second_Stage_Gain=140; + First_Stage_Gain_Code=(int)(((gain/Second_Stage_Gain)-4.0)*66.7); + trame(ADC_First_Stage_Gain_Code, mode, First_Stage_Gain_Code); + } else if (gain<1280) { + trame(ADC_Second_Stage_Gain_Code,mode,7); + Second_Stage_Gain=200; + First_Stage_Gain_Code=(int)(((gain/Second_Stage_Gain)-4.0)*66.7); + trame(ADC_First_Stage_Gain_Code, mode, First_Stage_Gain_Code); + } else if (gain>=1280) { + trame(ADC_Second_Stage_Gain_Code,mode,7); + trame(ADC_First_Stage_Gain_Code, mode, 127); + } + +} \ No newline at end of file
diff -r 000000000000 -r 05eaa16f3327 AD8556.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AD8556.h Wed Sep 11 13:30:19 2013 +0000 @@ -0,0 +1,94 @@ +/** + * @brief AD8556: Digitally Programmable Sensor Signal Amplifier with EMI Filters + * http://www.analog.com/en/specialty-amplifiers/instrumentation-amplifiers/ad8556/products/product.html + * @date 05/09/2013 + * @author F.BLANC LAAS-CNRS + * http://homepages.laas.fr/fblanc/ + */ +#ifndef AD8556_H + +#define AD8556_H + +#include "mbed.h" +enum ADC_MODE { + ADC_MODE_SENSE_CURENT = 0x00, + ADC_MODE_SIMULATION = 0x01, + ADC_MODE_FUSE = 0x02, + ADC_MODE_READ = 0x03 +}; +enum ADC_FUNCTION { + ADC_Change_Sense_Current = 0x00, + ADC_Simulate_Parameter_Value = 0x01, + ADC_Program_Parameter_Value = 0x02, + ADC_Read_Parameter_Value = 0x03 +}; +enum ADC_PARAMETER { + ADC_Second_Stage_Gain_Code = 0x00, + ADC_First_Stage_Gain_Code = 0x01, + ADC_Output_Offset_Code = 0x02, + ADC_Other_Functions = 0x03 +}; +/** AD8556 class. + * Used for controlling a AD8556 Instrumentation Amplifiers connected via Single-wire serial interface. + * + */ +class AD8556 +{ +protected: +private: + /** + * @brief write_bit + * + * @param bit 1 or 0 + */ + void write_bit(unsigned char bit); + /** + * @brief read_bit + * + * @return bit 1 or 0 + */ + unsigned char read_bit(); + /** + * @brief trame + * @param parameter + * @param mode + * @param data + */ + void trame(unsigned char parameter,unsigned char mode,unsigned char data); +public: + /** + * @brief Constructor. + * @param dig + */ + AD8556(PinName dig); + DigitalInOut _dig; + + /** + * @brief Destructor. + */ + ~AD8556(); + /** + * @brief init + * @param First_Stage_Gain_Code + * @param Second_Stage_Gain_Code + * @param Vdac_Code + */ + int init(unsigned char mode=ADC_MODE_SIMULATION, unsigned char First_Stage_Gain_Code=0, unsigned char Second_Stage_Gain_Code=0,unsigned char Vdac_Code=0x7F); + /** + * @brief prog_vdac + * @param vdac consigne (volt) + * @param vdd positive voltage supply (volt) + * @param vss nagative voltage supply (volt) + * @param mode + */ + void prog_vdac(float vdac, float vdd=5.0 ,float vss=0.0, unsigned char mode=ADC_MODE_SIMULATION); + /** + * @brief prog_gain + * @param gain 70 to 1280 + + * @param mode + */ + void prog_gain(float gain=70.0, unsigned char mode=ADC_MODE_SIMULATION); + +}; +#endif \ No newline at end of file