Exemplo n.º 1
0
/*******************

Stel de stroom in van de PCB
De stroom moet eerst omgezetten in een spanning dmv convertCurrent

*******************/
void setCurrentCharger(int i){
        int voltage_dac;
        currentCharger=i;
        if (currentCharger == 0) {
                i2c_shutdown_DAC();
        } else{
	        voltage_dac = convertCurrent();
                i2c_write_DAC(voltage_dac);
        }
}
Exemplo n.º 2
0
void main(void) {

    /* Configure the oscillator for the device */
    ConfigureOscillator();



    /* Initialize I/O and Peripherals for application */
    InitApp();

    resetCS();

    startCSConversion();

    line1();
    writeLCD("START CALIBRATION");

    calibration();

    writeRegister(MODE, 0x00006000);
    writeRegister(VOLTAGE_GAIN, 0x2F9000);
    writeRegister(CURRENT_GAIN, 0x3Fe0000);

    startCSConversion();
    while (1) {
        uint24_t status = readRegister(STATUS_REG);
        line2();
        if (!(status & 0x1)) {
            convertExe(status);
            writeLCD(buffer);
            resetCS();
            startCSConversion();
            continue;
        }
        double readVal;
        const char * measure;
        switch (showStatus) {
            case ssConf:
                data.lData = readRegister(showStatus);
                sprintf(buffer, "%02X%02X%02X    ", data.bytes[2], data.bytes[1], data.bytes[0]);
                measure = "CONF    ";
                break;
            case ssCycleCount:
                data.lData = readRegister(showStatus);
                sprintf(buffer, "%d    ", data.lData);
                measure = "CYCLE    ";
                break;
            case ssStatus:
                data.lData = readRegister(showStatus);
                sprintf(buffer, "%02X%02X%02X    ", data.bytes[2], data.bytes[1], data.bytes[0]);
                measure = "STATUS    ";
                break;
            case ssMode:
                data.lData = readRegister(showStatus);
                sprintf(buffer, "%02X%02X%02X    ", data.bytes[2], data.bytes[1], data.bytes[0]);
                measure = "MODE    ";
                break;
            case ssTemperature:
                data.lData = readRegister(showStatus);
                sprintf(buffer, "%02X%02X%02X    ", data.bytes[2], data.bytes[1], data.bytes[0]);
                measure = "TEMP    ";
                break;
            case ssCurrentGain:
                data.lData = readRegister(showStatus);
                readVal = convertCurrentGain(data.lData);
                measure = "I GAIN  ";
                sprintf(buffer, "%f    ", readVal);
                break;
            case ssVoltageOffset:
                data.lData = readRegister(showStatus);
                readVal = convertOffset(data.lData);
                measure = "VDC offset";
                sprintf(buffer, "%f    ", readVal);
                break;
            case ssVoltageGain:
                data.lData = readRegister(showStatus);
                readVal = convertCurrentGain(data.lData);
                measure = "V GAIN  ";
                sprintf(buffer, "%f    ", readVal);
                break;
            case ssVoltageAcOffset:
                data.lData = readRegister(showStatus);
                readVal = convertOffset(data.lData);
                measure = "VAC offset";
                sprintf(buffer, "%f    ", readVal);
                break;

            case ssCurrent:
                data.lData = readRegister(showStatus);
                readVal = convertCurrent(data.lData);
                measure = "CURRENT ";
                sprintf(buffer, "%f    ", readVal);
                break;
            case ssVolt:
                data.lData = readRegister(INST_VOLT);
                readVal = convertInstVolt(data.lData);
                measure = "VOLT    ";
                sprintf(buffer, "%f    ", readVal);
                break;
            case ssRMSVoltage:
                data.lData = readRegister(ssRMSVoltage);
                readVal = convertRMSVolt(data.lData);
                sprintf(buffer, "%f    ", readVal);
                measure = "RMS VOLT";
                break;
            case ssRMSCurrent:
                data.lData = readRegister(ssRMSCurrent);
                readVal = convertRMSCurrent(data.lData);
                sprintf(buffer, "%f    ", readVal);
                measure = "RMS I";
                break;
            case ssPower:
                data.lData = readRegister(INST_POWER);
                readVal = convertPower(data.lData);
                measure = "I POWER  ";
                sprintf(buffer, "%f    ", readVal);
                break;
            case ssActivePower:
                data.lData = readRegister(ssActivePower);
                readVal = convertPower(data.lData);
                measure = "I POWER  ";
                sprintf(buffer, "%f    ", readVal);
                break;
            default:
                data.lData = readRegister(showStatus);
                sprintf(buffer, "%02X%02X%02X    ", data.bytes[2], data.bytes[1], data.bytes[0]);
                measure = "        ";
                break;
        }

        line1();
        writeLCD(buffer);
        line2();
        writeLCD(measure);
        if (PORTBbits.RB2 == 0) {
            if (PORTBbits.RB2 == 0) {
                showStatus++;
                if (showStatus == ssLast) {
                    showStatus = ssConf;
                }
                while (1) {
                    if (PORTBbits.RB2 == 1) {
                        if (PORTBbits.RB2 == 1) {
                            break;
                        }
                    }
                }
            }
        }
    }

}
Exemplo n.º 3
0
void Parsing_parse(char * Buffer, Measurement * measurement){
  // All parameters are received as hexidecimal strings. These are converted
  // to doubles using the strtol function and multiplying by factors obtained through
  // measurements.
  
  // Holder for the hexidecimal string
  char temp[9];
  
  // Get voltage
  for (int j=0; j<9; j++){
	temp[j] = Buffer[j+VOLTAGE_PARSE_OFFSET];
  }
  temp[8] = '\0';
  
  // Convert from hex to double
  int voltage = strtol(temp, NULL, 16);
  measurement->voltage = convertVoltage(voltage);
  
  // Compute normalizing factor
  double scale = pow(measurement->voltage / 235.0, 2);
  
  // Get current
  for (int j=0; j<9; j++){
	temp[j] = Buffer[j+CURRENT_PARSE_OFFSET];
  }
  temp[8] = '\0';
  
  // Convert from hex to double
  int current = strtol(temp, NULL, 16);
  measurement->current = convertCurrent(current);
  
  // Get P Power
  for (int j=0; j<9; j++){
	temp[j] = Buffer[j+P_POWER_PARSE_OFFSET];
  }
  temp[8] = '\0';
  
  // Convert from hex to double and normalize
  int power = strtol(temp, NULL, 16);
  double pACT = convertP_power(power);
  measurement->P_power = scale * pACT;
  
  // Get Reactive Power
  for (int j=0; j<9; j++){
	temp[j] = Buffer[j+Q_POWER_PARSE_OFFSET];
  }
  temp[8] = '\0';
  
  // Convert from hex to double and normalize
  power = strtol(temp, NULL, 16);
  double pREAC = convertQ_power(power);
  measurement->Q_power = scale * pREAC;
  
  // Get Harmonic Power
  for (int j=0; j<9; j++){
	temp[j] = Buffer[j+H_POWER_PARSE_OFFSET];
  }
  temp[8] = '\0';
  
  // Convert from hex to double and normalize
  power = strtol(temp, NULL, 16);
  double pHAR = convertH_power(power);
  measurement->H_power = scale * pHAR;
}