Ingo Electronics


  MAX9611 library functions 


//Data registers
#define current_sensor    0x00
#define rs_voltage        0x02
#define out_voltage       0x04
#define set_voltage       0x06
#define temperature       0x08

#define control_reg_1     0x0A


//Control Register1 bits -Normal operation
#define  MAX9611_sensor_1x    0b00000000 // Read current-sense amplifier output from ADC, gain = 1x
#define  MAX9611_sensor_4x    0b00000001 // Read current-sense amplifier output from ADC, gain = 4x
#define  MAX9611_sensor_8x    0b00000010 // Read current-sense amplifier output from ADC, gain = 8x
#define  MAX9611_RS           0b00000011 // Read average voltage of RS+ (input common-mode voltage) from ADC
#define  MAX9611_OUT          0b00000100 // Read voltage of OUT from ADC
#define  MAX9611_SET          0b00000101 // Read voltage of SET from ADC
#define  MAX9611_temperature  0b00000110 // Read internal temperature from ADC
#define  all                  0b00000111 // Read all channels in fast-read mode, sequentially every 2ms. Uses last gain setting.





//******************************************************************************
int MAX9611_read(unsigned char reg_addr){
unsigned int tempAD;
unsigned int tempAD_second_byte;

I2C1_Start();
I2C1_Wr(0xE0);                       //Siunciamas adresas ir komanda "WRITE"
I2C1_Wr(reg_addr);                   //registras nuo kurio pradedame skaityti
delay_us(10);
I2C1_Repeated_Start();
I2C1_Wr(0xE1);                       //Siunciamas adresas ir komanda "READ"
tempAD=I2C1_Rd(1);                   //pirmas baitas Hight -ACK
tempAD_second_byte=I2C1_Rd(0);       //antras baitas Low   -NO ACK
I2C1_Stop();
Delay_ms(5);

tempAD=(tempAD<<8 );                 //pirma baita perstumiam i kaire
tempAD +=(int)tempAD_second_byte;    //prie pirmo baito pridedam antra baita

return  tempAD;
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
int MAX9611_temperature_converter(unsigned int value){

value=(value >> 7 );
//value = value&255;  //ignoruojam neigiamos temperaturos flaga (9-as bitas)
value = value*48;     // vienas bitas 0.48 laipsnio

return value;
}

//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//12bitu - max 4095, rezoliucija 1bitas 0.014V ,max  57.33V
int MAX9611_RS_converter(unsigned int value){

value=(value >> 4 );
value = value*14;
value = value/10;
return value;
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//12bitu - max 4095,  rezoliucija 1bitas 0.0001075V   max  0.440V
//Rsunto = 0.1075om
int MAX9611_sense_converter(unsigned int value){

value=(value >> 4 );

return value;
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
void MAX9611_setup(unsigned char reg_addr,unsigned char reg_data){
I2C1_Start();
I2C1_Wr(0xE0);       //Siunciamas adresas ir komanda "WRITE"
I2C1_Wr(reg_addr);   //registras i kuri bus rasomi duomenys
I2C1_Wr(reg_data);   // i registra irasome nustatymo duomenis

I2C1_Stop();
Delay_ms(5);
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''