HPS3KW

This page is just some info on my expeiments with the HPS3KW module

link to the I2C datasheet HPS3KW.i2c.PDF

NOTE – there are two I2C commands in play – The blue is for HPS3KW – and the black are for the AA21970
So – if you have a original AA21970 – ordered directly from Meanwell/Astec – you must use those commands.
I used a I2C scanner program to find the addresses.

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

void setup()
{
  Wire.begin();

  Serial.begin(9600);
  Serial.println("\nI2C Scanner");
}

void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {

	Serial.print("I2C device found at address HEX:");
      Serial.print(address,HEX);
      Serial.print("  Decimal:");

	  Serial.print(address);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknow error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

Here is the power supply out of it’s long sleek box:
2014-03-26 20.23.31
The code below is probably not working – but will give some reference

This is the current test code – not working FYI!!

#include <Wire.h>
#include <SerialCommand.h>

#define PSU_ADDRESS 0x1F

#define CMD_SETCTRL  0x02
#define CMD_READCTRL 0x03
#define CMD_READAD   0x01
#define CMD_READFW   0x06

int PSUSTATUS=0;
#define PSU_ON	(1 << 0)
#define PSU_PIN 10
#define CURRENT_PIN A0

SerialCommand sCmd;

 int T1=0;
 int T2=0;   // temperature 

// og 57
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;
long interval = 1000;
int i ;
int zero = 0;
uint8_t values[18];
byte o,error;

void setup() {
  // Debugging output
  Serial.begin(9600);

  pinMode(PSU_PIN, OUTPUT);
  digitalWrite(PSU_PIN, HIGH);

   Wire.begin();

  sCmd.addCommand("TEST",   TEST );
  sCmd.addCommand("FW",   FIRMWARE );
  sCmd.addCommand("STATUS",   R_STATUS ); 

   Serial.println("Ready");
 }

  void FIRMWARE()
  {
   Wire.beginTransmission(PSU_ADDRESS);
   Wire.write(CMD_READFW);
   Wire.endTransmission();

   Wire.requestFrom(PSU_ADDRESS, 2);

   Serial.print("Firmware version  ");
   Serial.print(Wire.read());
   Serial.print(" / ");
   Serial.println(Wire.read());

  }

  void R_STATUS()
  {
   int v;
   Wire.beginTransmission(PSU_ADDRESS);
   Wire.write(CMD_READCTRL);
   Wire.endTransmission();

   Wire.requestFrom(PSU_ADDRESS, 1);
   v = Wire.read();
   Serial.print("Status Register ");
   Serial.print(v);
   Serial.print("  ");
   Serial.println(v,BIN);

  }

  void R_ANALOGUE()
  {

   Wire.beginTransmission(PSU_ADDRESS);
   Wire.write(CMD_READAD);
   Wire.endTransmission();

   Wire.requestFrom(PSU_ADDRESS, 18);
    uint8_t value;
    int i=0;
	while (Wire.available())
	{
	i++;
	value = Wire.read();
	values[i] = value;

	}

long a_current= 0;
int a_linevoltage = 0;

 a_linevoltage = values[11];
 a_linevoltage = a_linevoltage << 8;
 a_linevoltage |= values[10];

a_current = values[3];
a_current = a_current << 8;
a_current |= values[2];
a_current = a_current << 8;
a_current |= values[1]; 

T1 = values[12];
T2 = values[15];

// Serial.print("Line Voltage: ");
// Serial.print(a_linevoltage,DEC);
// Serial.print("  Output current: ");
// Serial.println(a_current,DEC);

}

 void TEST()
 {

   Wire.beginTransmission(PSU_ADDRESS);
   Wire.write(CMD_READAD);
   Wire.endTransmission();

   Wire.requestFrom(PSU_ADDRESS, 18);
    uint8_t value;
    int i=0;
	while (Wire.available())
	{
	i++;
	value = Wire.read();
	values[i] = value;
 	Serial.print("value ");
    Serial.print(i);
    Serial.print(" is ");
	Serial.print(value,DEC);
	Serial.print("  and in hex: ");
	Serial.println(value,HEX);
	}

long a_current= 0;
int a_linevoltage = 0;

 a_linevoltage = values[11];
 a_linevoltage = a_linevoltage << 8;
 a_linevoltage |= values[10];

a_current = values[3];
a_current = a_current << 8;
a_current |= values[2];
a_current = a_current << 8;
a_current |= values[1]; 

Serial.print("Line Voltage: ");
Serial.print(a_linevoltage,DEC);
Serial.print("  Output current: ");
Serial.println(a_current,DEC);

}

 void task1s()
 {
  R_ANALOGUE();
  //UPDATE_LCD1();

 }

 void loop()
 {
  sCmd.readSerial();
 unsigned long currentMillis = millis();

     if ( currentMillis - previousMillis > interval)
   {
     previousMillis = currentMillis;
        Serial.print("!");
    task1s();
   }

 }

Leave a Reply

Your email address will not be published. Required fields are marked *