Wire.begin();// join i2c bus (address optional for master)
DacUpd(MCP4725_ADD0,thresh1);
DacUpd(MCP4725_ADD1,thresh2);
//setup spi
pinMode(SS,OUTPUT);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
//SPI.setClockDivider(SPI_CLOCK_DIV128 );
//begin serial
Serial.begin(9600);
2018-08-12 13:06:38 +00:00
Serial.setTimeout(65535);
2018-07-30 20:52:02 +00:00
}
voidloop(){
Serial.println("Input a command!");
2018-08-12 13:06:38 +00:00
Serial.println("[1= set thrshold1; 2= set threshold2, 3= set HV ch1, 4 = set HV ch2, 5 = set HV enables, 6= generic 2 part command, 7 = generic read]");
2018-07-30 20:52:02 +00:00
intcmd=readIntFromSerial();
switch(cmd){
case1:
{
Serial.println("Set a threshold value Ch1[1,4096]: ");
intvalue=readIntFromSerial();
//setThreshold(3, value);
DacUpd(MCP4725_ADD0,value);
break;
}
case2:
{
Serial.println("Set a threshold value Ch2[1,4096]: ");
intvalue=readIntFromSerial();
//setThreshold(3, value);
DacUpd(MCP4725_ADD1,value);
break;
}
case3:
{
2018-08-12 13:06:38 +00:00
//MSB
Serial.println("Input a voltage value Ch1 msb[1=highest,255=lowest,56=nominal]");
2018-07-30 20:52:02 +00:00
intsendValue=readIntFromSerial();
//if (sendValue < HV_MAX_VAL) {
// Serial.print("HV Value is too high! Setting HV ch2 to:");
// Serial.println(HV_MAX_VAL);
//send the command code
2018-08-12 13:06:38 +00:00
spi_exchange(1);
spi_exchange(sendValue);
//LSB
Serial.println("Input a voltage value Ch1 LSB[1=highest,255=lowest,56=nominal]");
sendValue=readIntFromSerial();
//if (sendValue < HV_MAX_VAL) {
// Serial.print("HV Value is too high! Setting HV ch2 to:");
// Serial.println(HV_MAX_VAL);
//send the command code
2018-07-30 20:52:02 +00:00
spi_exchange(2);
spi_exchange(sendValue);
break;
}
case4:
{
2018-08-12 13:06:38 +00:00
//MSB
Serial.println("Input a voltage value Ch1 msb[1=highest,255=lowest,56=nominal]");
2018-07-30 20:52:02 +00:00
intsendValue=readIntFromSerial();
//if (sendValue < HV_MAX_VAL) {
// Serial.print("HV Value is too high! Setting HV ch2 to:");
// Serial.println(HV_MAX_VAL);
//send the command code
2018-08-12 13:06:38 +00:00
spi_exchange(3);
spi_exchange(sendValue);
//LSB
Serial.println("Input a voltage value Ch1 LSB[1=highest,255=lowest,56=nominal]");
sendValue=readIntFromSerial();
//if (sendValue < HV_MAX_VAL) {
// Serial.print("HV Value is too high! Setting HV ch2 to:");
// Serial.println(HV_MAX_VAL);
//send the command code
2018-07-30 20:52:02 +00:00
spi_exchange(4);
spi_exchange(sendValue);
break;
}
case5:
{
2018-08-01 11:47:39 +00:00
Serial.println("disabling HV");
spi_exchange(11);
spi_exchange(0);
2018-07-30 20:52:02 +00:00
Serial.println("enabling HV");
spi_exchange(11);
spi_exchange(3);
break;
}
2018-08-12 13:06:38 +00:00
//generic command sender
case6:
{
Serial.println("Input a command to send");
Serial.println(" 01 WRITE MSB(16 high bits) HV1_DUTY_CYCLE");