Ejemplo n.º 1
0
void CheckHeaterFaults(void) 
{
  if (ETMAnalogCheckOverAbsolute(&Heater_output_voltage)) //Over voltage condition
  {
    global_data_A36613.status |= HEATER_OVERVOLTAGE_FLT;
    heater_reset_counter++;
    ResetHeater();
  }
  

  if (ETMAnalogCheckOverAbsolute(&Heater1_current) || ETMAnalogCheckOverAbsolute(&Heater2_current)) //Over current condition
  {
    global_data_A36613.status |= HEATER_OVERCURRENT_FLT;
    heater_reset_counter++;
    ResetHeater();
  }

  if (global_data_A36613.control_state == STATE_READY)// heater undervoltage and undercurrent should only be checked after warmup.
  {
    if (ETMAnalogCheckUnderAbsolute(&Heater1_current) || ETMAnalogCheckUnderAbsolute(&Heater2_current)) //Under current condition
    {
      global_data_A36613.status |= HEATER_UNDERCURRENT_FLT;
 //   heater_reset_counter++;
 //   ResetHeater();
    }

    if (ETMAnalogCheckUnderAbsolute(&Heater_output_voltage)) //Under voltage condition
    {
      global_data_A36613.status |= HEATER_UNDERVOLTAGE_FLT;
      heater_reset_counter++;
      ResetHeater();
    }
  }
}
Ejemplo n.º 2
0
void DoA36225_500(void) {

  // Check the status of these pins every time through the loop
  if (PIN_D_IN_3_HEATER_OVER_VOLT_STATUS == ILL_HEATER_OV) {
    ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_HW_HEATER_OVER_VOLTAGE);
  }

  if (_T5IF) {
    // 10ms Timer has expired so this code will executre once every 10ms
    _T5IF = 0;
    
    // Flash the operate LED
    led_divider++;
    if (led_divider >= 50) {
      led_divider = 0;
      if (PIN_LED_POWER) {
	PIN_LED_POWER = 0;
      } else {
	PIN_LED_POWER = 1;
      }
    }

    // Update the error counters that get returned
    etm_can_system_debug_data.i2c_bus_error_count = 0;  // There are no I2C devices on this board
    etm_can_system_debug_data.spi_bus_error_count = etm_spi1_error_count + etm_spi2_error_count;
    etm_can_system_debug_data.scale_error_count = etm_scale_saturation_etmscalefactor2_count + etm_scale_saturation_etmscalefactor16_count;
    etm_can_system_debug_data.self_test_result_register = 0; // DPARKER NEED TO WORK ON THE SELF TEST
    
    /*
      The following are updated by the ETM_CAN module
      can_bus_error_count
      reset_count
    */


    // Set the fault LED
    if (etm_can_status_register.status_word_0 & 0x0003) {
      // The board is faulted or inhibiting the system
      PIN_LED_I2_C = 0;
    } else {
      PIN_LED_I2_C = 1;
    }

    // Update the digital input status pins
    if (PIN_D_IN_0_ELECTROMAGENT_STATUS == ILL_POWER_SUPPLY_DISABLED) {
      ETMCanSetBit(&etm_can_status_register.status_word_0, STATUS_BIT_READBACK_ELECTROMAGNET_STATUS);
    } else {
      ETMCanClearBit(&etm_can_status_register.status_word_0, STATUS_BIT_READBACK_ELECTROMAGNET_STATUS);
    }
  
    if (PIN_D_IN_4_TEMPERATURE_STATUS == ILL_TEMP_SWITCH_FAULT) {
      ETMCanSetBit(&etm_can_status_register.status_word_0, STATUS_BIT_HW_TEMPERATURE_SWITCH);
    } else {
      ETMCanClearBit(&etm_can_status_register.status_word_0, STATUS_BIT_HW_TEMPERATURE_SWITCH);
    }

  
    if (PIN_D_IN_1_HEATER_STATUS == ILL_POWER_SUPPLY_DISABLED) {
      ETMCanSetBit(&etm_can_status_register.status_word_0, STATUS_BIT_READBACK_HEATER_STATUS);
    } else {
      ETMCanClearBit(&etm_can_status_register.status_word_0, STATUS_BIT_READBACK_HEATER_STATUS);
    }
    
    if (PIN_D_IN_5_RELAY_STATUS == ILL_RELAY_OPEN) {
      ETMCanSetBit(&etm_can_status_register.status_word_0, STATUS_BIT_READBACK_RELAY_STATUS);
    } else {
      ETMCanClearBit(&etm_can_status_register.status_word_0, STATUS_BIT_READBACK_RELAY_STATUS);
    }
    
    // Flash the Refresh
    if (PIN_D_OUT_REFRESH) {
      PIN_D_OUT_REFRESH = 0;
    } else {
      PIN_D_OUT_REFRESH = 1;
    }
    
    // Do Math on ADC inputs
    // Scale the ADC readings to engineering units
    ETMAnalogScaleCalibrateADCReading(&global_data_A36224_500.analog_input_electromagnet_current);
    ETMAnalogScaleCalibrateADCReading(&global_data_A36224_500.analog_input_electromagnet_voltage);
    ETMAnalogScaleCalibrateADCReading(&global_data_A36224_500.analog_input_heater_current);
    ETMAnalogScaleCalibrateADCReading(&global_data_A36224_500.analog_input_heater_voltage);
    

// -------------------- CHECK FOR FAULTS ------------------- //

    if (global_reset_faults) {
      etm_can_system_debug_data.debug_0++;
      etm_can_status_register.status_word_1 = 0x0000;
      global_reset_faults = 0;
    }



    if (control_state == STATE_OPERATE) {
      global_data_A36224_500.analog_input_electromagnet_current.target_value = global_data_A36224_500.analog_output_electromagnet_current.set_point;
      global_data_A36224_500.analog_input_electromagnet_voltage.target_value = ETMScaleFactor16(global_data_A36224_500.analog_output_electromagnet_current.set_point,MACRO_DEC_TO_SCALE_FACTOR_16(NOMINAL_ELECTROMAGNET_RESISTANCE),0);
      global_data_A36224_500.analog_input_heater_current.target_value = global_data_A36224_500.analog_output_heater_current.set_point;
      global_data_A36224_500.analog_input_heater_voltage.target_value = ETMScaleFactor16(global_data_A36224_500.analog_output_heater_current.set_point,MACRO_DEC_TO_SCALE_FACTOR_16(NOMINAL_HEATER_RESISTANCE),0);
    } else {
      global_data_A36224_500.analog_input_electromagnet_current.target_value = 0;
      global_data_A36224_500.analog_input_electromagnet_voltage.target_value = 0;
      global_data_A36224_500.analog_input_heater_current.target_value = 0;
      global_data_A36224_500.analog_input_heater_voltage.target_value = 0;
    }


    if (ETMAnalogCheckOverAbsolute(&global_data_A36224_500.analog_input_heater_current)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_HEATER_OVER_CUR_ABSOLUTE);
    }
    if (ETMAnalogCheckUnderAbsolute(&global_data_A36224_500.analog_input_heater_current)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_HEATER_UNDER_CUR_ABSOLUTE);
    }
    if (ETMAnalogCheckOverRelative(&global_data_A36224_500.analog_input_heater_current)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_HEATER_OVER_CUR_RELATIVE);
    }
    if (ETMAnalogCheckUnderRelative(&global_data_A36224_500.analog_input_heater_current)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_HEATER_UNDER_CUR_RELATIVE);
    }
    if (ETMAnalogCheckOverAbsolute(&global_data_A36224_500.analog_input_heater_voltage)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_HEATER_OVER_VOL_ABSOLUTE);
    }
    if (ETMAnalogCheckUnderRelative(&global_data_A36224_500.analog_input_heater_voltage)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_HEATER_UNDER_VOL_RELATIVE);
    }
    
    
    if (ETMAnalogCheckOverAbsolute(&global_data_A36224_500.analog_input_electromagnet_current)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_MAGNET_OVER_CUR_ABSOLUTE);
    }
    if (ETMAnalogCheckUnderAbsolute(&global_data_A36224_500.analog_input_electromagnet_current)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_MAGNET_UNDER_CUR_ABSOLUTE);
    }
    if (ETMAnalogCheckOverRelative(&global_data_A36224_500.analog_input_electromagnet_current)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_MAGNET_OVER_CUR_RELATIVE); 
    }
    if (ETMAnalogCheckUnderRelative(&global_data_A36224_500.analog_input_electromagnet_current)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_MAGNET_UNDER_CUR_RELATIVE); 
    }
    if (ETMAnalogCheckOverAbsolute(&global_data_A36224_500.analog_input_electromagnet_voltage)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_MAGNET_OVER_VOL_ABSOLUTE); 
    }
    if (ETMAnalogCheckUnderRelative(&global_data_A36224_500.analog_input_electromagnet_voltage)) {
      ETMCanSetBit(&etm_can_status_register.status_word_1, FAULT_BIT_MAGNET_UNDER_VOL_RELATIVE);
    }
    


    // Set DAC outputs
    if (control_state == STATE_OPERATE) {
      ETMAnalogScaleCalibrateDACSetting(&global_data_A36224_500.analog_output_heater_current);
      WriteMCP4822(&U42_MCP4822, MCP4822_OUTPUT_A_4096, global_data_A36224_500.analog_output_electromagnet_current.dac_setting_scaled_and_calibrated>>4);
      
      ETMAnalogScaleCalibrateDACSetting(&global_data_A36224_500.analog_output_electromagnet_current);
      WriteMCP4822(&U42_MCP4822, MCP4822_OUTPUT_B_4096, global_data_A36224_500.analog_output_heater_current.dac_setting_scaled_and_calibrated>>4);
    } else {
Ejemplo n.º 3
0
void InitializeA36582(void) {
  unsigned int pulse_data_A[7];
  unsigned int pulse_data_B[7];
  unsigned char analog_port_internal_adc;
  unsigned char analog_port_external_adc;

  // Initialize the status register and load the inhibit and fault masks
  _CONTROL_REGISTER = 0;
  _FAULT_REGISTER = 0;
  _WARNING_REGISTER = 0;
  _NOT_LOGGED_REGISTER = 0;
  
  // Configure Trigger Interrupt
  _INT1IP = 7; // This must be the highest priority interrupt
  _INT1IE = 1;
  
  // Configure the "False Trigger" Interrupt
  _INT3IP = 6; // This must be the highest priority interrupt
  _INT3EP = 0; // Positive Transition
  _INT3IE = 1;

  // By Default, the can module will set it's interrupt Priority to 4
  
  // Initialize all I/O Registers
  TRISA = A36582_TRISA_VALUE;
  TRISB = A36582_TRISB_VALUE;
  TRISC = A36582_TRISC_VALUE;
  TRISD = A36582_TRISD_VALUE;
  TRISF = A36582_TRISF_VALUE;
  TRISG = A36582_TRISG_VALUE;


  // Initialize TMR2
  TMR2  = 0;
  _T2IF = 0;
  T2CON = T2CON_VALUE;

  
  // Initialize TMR3
  PR3   = PR3_VALUE_10_MILLISECONDS;
  TMR3  = 0;
  _T3IF = 0;
  T3CON = T3CON_VALUE;


  
  // Initialize the External EEprom
  ETMEEPromUseExternal();
  ETMEEPromConfigureExternalDevice(EEPROM_SIZE_8K_BYTES, FCY_CLK, 400000, EEPROM_I2C_ADDRESS_0, 1);
  
  if (ETMEEPromCheckOK() == 0) {
    global_data_A36582.external_eeprom_error = 1;
    analog_port_internal_adc = ANALOG_INPUT_NO_CALIBRATION;
    analog_port_external_adc = ANALOG_INPUT_NO_CALIBRATION;
  } else {
    global_data_A36582.external_eeprom_error = 0;
    analog_port_internal_adc = ANALOG_INPUT_0;
    analog_port_external_adc = ANALOG_INPUT_1;
  }

  // Initialize the Can module
  ETMCanSlaveInitialize(CAN_PORT_1, FCY_CLK, ETM_CAN_ADDR_MAGNETRON_CURRENT_BOARD, _PIN_RG13, 4, _PIN_RA7, _PIN_RG12);
  ETMCanSlaveLoadConfiguration(36582, 251, FIRMWARE_AGILE_REV, FIRMWARE_BRANCH, FIRMWARE_BRANCH_REV);
  
  // Initialize the Analog input data structures
  ETMAnalogInitializeInput(&global_data_A36582.imag_internal_adc,
			   MACRO_DEC_TO_SCALE_FACTOR_16(.25075),
			   OFFSET_ZERO,
			   analog_port_internal_adc,
			   NO_OVER_TRIP,
			   NO_UNDER_TRIP,
			   NO_TRIP_SCALE,
			   NO_FLOOR,
			   NO_COUNTER,
			   NO_COUNTER);
  
  ETMAnalogInitializeInput(&global_data_A36582.imag_external_adc,
			   MACRO_DEC_TO_SCALE_FACTOR_16(.25075),
			   OFFSET_ZERO,
			   analog_port_external_adc, 
			   NO_OVER_TRIP,
			   NO_UNDER_TRIP,
			   NO_TRIP_SCALE,
			   NO_FLOOR,
			   NO_COUNTER,
			   NO_COUNTER);

  ETMAnalogInitializeInput(&global_data_A36582.analog_input_5v_mon,
			   MACRO_DEC_TO_SCALE_FACTOR_16(.12500),
			   OFFSET_ZERO,
			   ANALOG_INPUT_NO_CALIBRATION,
			   PWR_5V_OVER_FLT,
			   PWR_5V_UNDER_FLT,
			   NO_TRIP_SCALE,
			   NO_FLOOR,
			   NO_COUNTER,
			   NO_COUNTER);


  // Configure SPI port, used by External ADC
  ConfigureSPI(ETM_SPI_PORT_2, ETM_DEFAULT_SPI_CON_VALUE, ETM_DEFAULT_SPI_CON2_VALUE, ETM_DEFAULT_SPI_STAT_VALUE, SPI_CLK_2_MBIT, FCY_CLK);
 
 
  //Initialize the internal ADC for Startup Power Checks
  // ---- Configure the dsPIC ADC Module ------------ //
  ADPCFG = ADPCFG_SETTING;             // Set which pins are analog and which are digital I/O

  ADCON1 = ADCON1_SETTING_STARTUP;     // Configure the high speed ADC module based on H file parameters
  ADCON2 = ADCON2_SETTING_STARTUP;     // Configure the high speed ADC module based on H file parameters
  ADCON3 = ADCON3_SETTING_STARTUP;     // Configure the high speed ADC module based on H file parameters
  ADCHS  = ADCHS_SETTING_STARTUP;      // Configure the high speed ADC module based on H file parameters
  //ADCSSL = ADCSSL_SETTING_STARTUP;
  
  _ADIF = 0;
  _ADON = 1;

  while (_ADIF == 0); // Wait for 16 ADC conversions to complete;
  _ADON = 0;
  global_data_A36582.analog_input_5v_mon.filtered_adc_reading  = ADCBUF0 + ADCBUF1 + ADCBUF2 +ADCBUF3 + ADCBUF4 + ADCBUF5 + ADCBUF6 + ADCBUF7;
  global_data_A36582.analog_input_5v_mon.filtered_adc_reading += ADCBUF8 + ADCBUF9 + ADCBUFA +ADCBUFB + ADCBUFC + ADCBUFD + ADCBUFE + ADCBUFF;

  ETMAnalogScaleCalibrateADCReading(&global_data_A36582.analog_input_5v_mon);

  if (ETMAnalogCheckOverAbsolute(&global_data_A36582.analog_input_5v_mon)) {
    _CONTROL_SELF_CHECK_ERROR = 1;
    // DPARKER use the self test bits
  }
  
  if (ETMAnalogCheckUnderAbsolute(&global_data_A36582.analog_input_5v_mon)) {
    _CONTROL_SELF_CHECK_ERROR = 1;
    // DPARKER use the self test bits
  }
  
  ADCON1 = ADCON1_SETTING_OPERATE;     // Configure the high speed ADC module based on H file parameters
  ADCON2 = ADCON2_SETTING_OPERATE;     // Configure the high speed ADC module based on H file parameters
  ADCON3 = ADCON3_SETTING_OPERATE;     // Configure the high speed ADC module based on H file parameters
  ADCHS  = ADCHS_SETTING_OPERATE;      // Configure the high speed ADC module based on H file parameters
  //ADCSSL = ADCSSL_SETTING_STARTUP;
  
  _ADIF = 0;
  _ADON = 1;
  _SAMP = 1;


  // Read Data from EEPROM
  if (global_data_A36582.external_eeprom_error == 0) {
    // Only read from the EEPROM if we can connect to it succesfully
    ETMEEPromReadPage(PULSE_COUNT_REGISTER_A, 7, &pulse_data_A[0]);
    ETMEEPromReadPage(PULSE_COUNT_REGISTER_B, 7, &pulse_data_B[0]);
    
    // If the data checks out, update with data
    if (pulse_data_A[6] == ETMCRCModbus(pulse_data_A, 12)) {
      global_data_A36582.arc_total = *(unsigned long*)&pulse_data_A[0];
      global_data_A36582.pulse_total = *(unsigned long long*)&pulse_data_A[2];
    } else if (pulse_data_B[6] == ETMCRCModbus(pulse_data_B, 12)) {
      global_data_A36582.arc_total = *(unsigned long*)&pulse_data_B[0];
      global_data_A36582.pulse_total = *(unsigned long long*)&pulse_data_B[2];
    } else {
      // Both EEPROM Registers were corrupted
      global_data_A36582.arc_total = 0;
      //global_data_A36582.arc_total |= 0x00000000; // Set the highest bit high to indicate an EEPROM reading error
      global_data_A36582.pulse_total = 0;
      //global_data_A36582.pulse_total |= 0x0000000000000000; // Set the highest bit high to indicate an EEPROM reading error
    }
  } else {
    // There is an EEPROM Error, use values that we can use to interpret
    global_data_A36582.arc_total = 0;
    //global_data_A36582.arc_total |= 0x00000000; // Set the highest bit high to indicate an EEPROM reading error
    global_data_A36582.pulse_total = 0;
    //global_data_A36582.pulse_total = 0x0000000000000000; // Set the highest bit high to indicate an EEPROM reading error
  }
  // Run a dummy conversion
  _SAMP = 0;

}