I am trying to get the PMOD PMON1 to run on a teensy for a micro project I am working on and so far not so good.
Here is my code block, please take a look and let me know if you see anything I am missing? I far I am not Serial reading anything but the "Program Started".
Question
JGRMSL
I am trying to get the PMOD PMON1 to run on a teensy for a micro project I am working on and so far not so good.
Here is my code block, please take a look and let me know if you see anything I am missing? I far I am not Serial reading anything but the "Program Started".
/* ADM1191 U/I I2C converter
I2C SDA ==> 18
I2C SCL ==> 19
CONF_REG[7..0] NC STATUS_RD NC VRANGE I_ONCE I_CONT V_ONCE V_VCONT
V_VCONT =1, countinuosly cnv V
I_VCONT =1, countinuosly cnv I
VRANGE Vrange =0 -> Vr=26.52V,
write I2C [ADR][CONF_REG]
read I2C [ADR][Uh][Ih][Ul:Ih]
*/
#include <Wire.h>
#define ADM1191_ADR B01100000 // 7bit ADM1191 device address A1,A0=00 jumpers set to 1 0Xb00
#define ADM1191_CONF_REG B00000101 // ADM config
uint16_t result_Uh=0, result_Ih =0, result_UIl =0;
float P, Uh, Ih, Rs=0.05;
void setup() {
while(!Serial);
Serial.print("Program Started"); Serial.println();
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(ADM1191_ADR);
Wire.write(ADM1191_CONF_REG);
Wire.endTransmission();
}
void loop() {
Wire.beginTransmission(ADM1191_ADR);
Wire.requestFrom(ADM1191_ADR, 3); // request 3 bytes from ADM
while(Wire.available()) {
result_Uh = Wire.read(); // HIGH U
result_Ih = Wire.read(); // HIGH I
result_UIl = Wire.read(); // LOW U : LOW I
result_Uh = (result_Uh << 4) + (result_UIl >> 4);
result_Ih= (result_Ih << 4) + (result_UIl & 0x0F);
Uh= (26.52/4096)* result_Uh;
Serial.print(" U: ");
Serial.print(Uh, 2);
Serial.print(" [V]\t");
Ih= ((105.84/4096)*result_Ih)/Rs;
Serial.print(" I: ");
Serial.print(Ih, 0);
Serial.print(" [mA]\t");
P= Uh*Ih/1000;
Serial.print("P: ");
Serial.print(P, 2);
Serial.println(" [W]\t");
}
Wire.endTransmission();
delay(1000);
}
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.