to control an Empulse charger ( Eltek Valere ) you can use an Arduino + Canbus shield and this code
( this code is for High voltage Eltek valere , you need to change the voltage packet to something below 112 volts)
This code allow Arduino to control an Eltek charger , ir REQUIRE also a Sparkfun Canbus Shiled.
UP/DOWN joystik chance the voltage up or down by 10V
LEFT/RIGHT joystik change the current up or down by 1Ampere
CLICK enable or disable the charger.
Led D8 is on when charger is enable
Led D7 blinks when any input is registered form the joystik.
On serial monitor (@115200) there are available debug values calculated for the actual canbus packet.
-------------------------------------------BEGIN CODE-------------------------------------------------------------
#include <SPI.h>
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
/* Define Joystick connection */
#define UP A1
#define DOWN A3
#define LEFT A5
#define RIGHT A2
#define CLICK A4
// define pins for feedback leds
#define CONF 7
#define ENAB 8
// intitialize to reasonable value for safety
int volts =150;
int ampere =0;
boolean running = false ;
int VMSD = 0x00; //Voltage Most Significant Digit
int VLSD = 0x00; //Voltage Least Significant Digit
int CMSD = 0x00; //Current Most Significant Digit
int CLSD = 0x00; //Current Least Significant Digit
void setup()
{
//serial and canbus initialization
Serial.begin(115200);
if(Canbus.init(CANSPEED_250))
Serial.println("CAN Init ok");
else
Serial.println("Can't Init CAN");
delay(1000);
pinMode(UP,INPUT);
pinMode(DOWN,INPUT);
pinMode(LEFT,INPUT);
pinMode(RIGHT,INPUT);
pinMode(CLICK,INPUT);
pinMode(ENAB, OUTPUT);
pinMode(CONF, OUTPUT);
}
//here start the main loop , it will run over and over and over
void loop()
{
// using shield joystik to up/down voltage left/right ampere and click for enable running
if (analogRead(CLICK) <= 10) {
running = !running;
digitalWrite(CONF, HIGH);}
if ((analogRead(UP) <= 10)and (volts<= 240)){
volts = volts+10;
digitalWrite(CONF, HIGH);}
if ((analogRead(DOWN) <= 10)and (volts >= 160)){
volts = volts-10;
digitalWrite(CONF, HIGH);}
if ((analogRead(LEFT) <= 10)and (ampere <= 15)){
ampere = ampere+1;
digitalWrite(CONF, HIGH);}
if ((analogRead(RIGHT) <= 10)and (ampere >= 1)){
ampere = ampere-1;
digitalWrite(CONF, HIGH);}
digitalWrite(ENAB, running);
delay(90); // 90 millisecond to allow people to see the CONF led so people can see if the valued changed
digitalWrite(CONF, LOW);
// calculation to eltek protocol
VMSD = (volts*10)/256,HEX;
VLSD = (volts*10)%256,HEX;
CMSD = (ampere*10)/256,HEX;
CLSD = (ampere*10)%256,HEX;
// end calculation to eltek protocol
//can message setup
tCAN message;
message.id = 0x2ff; //formatted in HEX eltek broadcast address for all chargers on the bus
message.header.rtr = 0;
message.header.length = 7; //formatted in DEC
message.data[0] = running,HEX; // charger enable 01
message.data[1] = 0xE8; // power 03E8 = 100,0%
message.data[2] = 0x03;
message.data[3] = VLSD; // volt
message.data[4] = VMSD;
message.data[5] = CLSD; // ampere
message.data[6] = CMSD;
/*
// example packet for 200 volts 2 ampere D0 07 14 00
message.id = 0x2ff; //formatted in HEX
message.header.rtr = 0;
message.header.length = 7; //formatted in DEC
message.data[0] = 0x01; // charger enable 01
message.data[1] = 0xE8; // power 03E8 = 100,0%
message.data[2] = 0x03;
message.data[3] = 0xD0; // volt max 07D0 = 200,0 volts
message.data[4] = 0x07;
message.data[5] = 0x14; // ampere max 0014 = 2,0 Ampere
message.data[6] = 0x00;
*/
//actual canbus packet sending
mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
mcp2515_send_message(&message);
//debug code reading from actual canbus message to be sure what's going on
//---------running Debug-------------
Serial.print("enable ");
Serial.println(message.data[0]);
//---end running debug--------------
// ------voltage Debug ----------------------------
Serial.print("voltage ");
//Serial.println(message.data[3],HEX);
//Serial.println(message.data[4],HEX);
//Serial.println(message.data[4]*256+message.data[3],HEX);
//Serial.println(message.data[4]*256+message.data[3]);
Serial.println((message.data[4]*256+message.data[3])/10);
// ---end voltage debug ---------------------------
// -----------current Debug ----------------------------
Serial.print("current ");
//Serial.println(message.data[5],HEX);
//Serial.println(message.data[6],HEX);
//Serial.println(message.data[6]*256+message.data[5],HEX);
//Serial.println(message.data[6]*256+message.data[5]);
Serial.println((message.data[6]*256+message.data[5])/10);
// ---end voltage debug ---------------------------
delay(100); // wait 100 millisecond before starting the loop again
}
-------------------------------------------------END CODE-------------------------------------------------------------------------
Simone