I am trying to interface an Arduino Duemilanove with a max6651 chip.
I am unsure if I am communicating with it properly and I am attempting to change the Ktach value to control the speed of the fan; however, the chip does not change the fan's RPM. When I ask the 6651 over I2C for the tach value it does send back a number; however, this number does not change with the speed of the fan but rather with the Ktach. I would really appreciate it if someone could take a look at the data-sheet and my code and see what the problem is. I'm trying to use the closed-loop mode of operation with a 12volt fan.
#include <Wire.h>
byte KtachCommand=00000000;
byte ConfigCommand=00000010;
byte ConfigData= 00101000;
byte GPIODEFCommand=00000100;
byte DACCommand=00000110;
byte AlarmEnableCommand=00001000;
byte AlarmCommand=00001010;
byte Tach0Command=00001100;
byte Tach1Command=00001110;
byte Tach2Command=00010000;
byte Tach3Command=00010010;
byte GPIOSTATCommand=00010100;
byte COUNTCommand=00010110;
byte COUNTData=00000011;
int RPM;
byte Ktach=100;
int FanControllerAddress=72;
int Tach0RPM;
int Tach1RPM;
int Tach2RPM;
int Tach3RPM;
byte TachInput;
int counter;
void setup(){
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
Wire.beginTransmission(FanControllerAddress); // transmit to device
Wire.send(ConfigCommand); // transmits command
Wire.send(ConfigData); // transmits data
Wire.endTransmission(); // stop transmitting
delay(10);
Wire.beginTransmission(FanControllerAddress); // transmit to device
Wire.send(COUNTCommand);
Wire.send(COUNTData);
Wire.endTransmission();
delay(10);
}
void loop(){
if (counter==0){
UpdateFans();
ScreenUpdate();}
KtachUpdate();
delay(50);
counter++;
if (counter==20){
counter=0;}
}
void KtachUpdate(){
if(Serial.available()>0){
byte input=Serial.read();
if (input=='u')
Ktach=Ktach-1;
else if (input=='d')
Ktach=Ktach+1;
if (Ktach<64)
Ktach=64;
if (Ktach>250)
Ktach=250;
RPM=59531.25/(Ktach+1);
Wire.beginTransmission(FanControllerAddress);
Wire.send(KtachCommand);
Wire.send(Ktach);
Wire.endTransmission();
delay(10);}
}
void UpdateFans(){
Wire.beginTransmission(FanControllerAddress);
Wire.send(Tach0Command);
Wire.requestFrom(FanControllerAddress,1);
if (Wire.available()>0){
TachInput=Wire.receive();}
if (TachInput>0){
Tach0RPM=TachInput*15;}
delay(10);
}
void ScreenUpdate(){
Serial.print("RPM= ");
Serial.println(RPM);
Serial.print("Ktach= " );
Serial.println(Ktach,DEC);
/Serial.print("Tach0 RPM = ");
Serial.println(Tach0RPM);
Serial.println(" ");
}