Esempio n. 1
0
void configPins(){

	AD1PCFGL = 0b1111111111111111; //set all bits not to be analog

	//TRISx defines the input/output state of pins. 1 represents input, while 0 represents output.
	TRISAbits.TRISA0 = 0;	// warn1
	TRISAbits.TRISA1 = 0;	// warn2 
	TRISAbits.TRISA3 = 0;	// Critical
	TRISAbits.TRISA4 = 0;	// DI/RO
	
	TRISBbits.TRISB2 = 0;	//MOSI
	TRISBbits.TRISB3 = 0;	//SCK
	TRISBbits.TRISB4 = 0;	//Relay
	TRISBbits.TRISB5 = 1;	//MISO LTC1
	TRISBbits.TRISB6 = 1;	//MISO LTC2	
	TRISBbits.TRISB7 = 1;	//MISO LTC3
	TRISBbits.TRISB8 = 1;	//MISO ADC
	TRISBbits.TRISB9 = 1;	//RX    
	TRISBbits.TRISB10 = 0;	//TX
	TRISBbits.TRISB11 = 0;	//FAULT
	TRISBbits.TRISB12 = 0;	//CS LTC1
	TRISBbits.TRISB13 = 0;	//CS LTC2
	TRISBbits.TRISB14 = 0;	//CS LTC3
	TRISBbits.TRISB15 = 0;	//CS ADC


	LATBbits.LATB3 = 0; //SET CLOCK LOW
	setRelay(RELAY_OFF); //make sure the relay is off
	LATAbits.LATA0 = 0; //set warn1 off
	LATAbits.LATA1 = 0; //set warn2 off
	LATAbits.LATA3 = 0; //set critical led off
	LATBbits.LATB12 = 1;
	LATBbits.LATB13 = 1;
	LATBbits.LATB14 = 1;
}
Esempio n. 2
0
int checkCurrentSensor(int channel){
    double current = readCurrentSensor(channel);
    if (current < CURRENT_MIN || current > CURRENT_MAX){
      setRelay(RELAY_OFF);
      return RED_STATUS;
    }
    if(current <= CURR_YELLOW_MIN || current >= CURR_YELLOW_MAX){
        return OVERCURRENT_STATUS;
    }
    else{
        return GREEN_STATUS;
    }
}
Esempio n. 3
0
int checkTemperature(int channel){
    //TODO: comment code
    double temp = readTempSensor(channel);
    if(temp < TEMP_MIN || temp > TEMP_MAX){
        setRelay(RELAY_OFF);
        return RED_STATUS;
    }
    if(temp <= TEMP_YELLOW_MIN || temp >= TEMP_YELLOW_MAX){
        return OVERTEMP_STATUS;
    }
    else{
        return GREEN_STATUS;
    }
}
Esempio n. 4
0
int16_t main(void)
{
	//TODO discharge calculations
	int i = LTC3;
	int j;
	char voltages[19];
	int selfCheck = 0;

	configPins();
	configClock();
	

	//Comment out next 5 lines if debugging
	selfCheck += initLTC();
	selfCheck += initADC();//initADC();
	if(selfCheck == 2){
		setRelay(RELAY_ON);
	}

    while(1)
    {	
		//comment out next 4 lines if debugging
		for(i = LTC1; i < LTC_ALL; i++){
			LTC_readVoltages(i);
		}
		checkADC();


		//uncomment next 0 lines if debugging RS-485
		
		//unComment next 3 lines if debugging LTC
		//LTC_writeConfig(LTC_ALL, 0);
		//LTC_readVoltages(i);
		//LTC_analyzeVolts(i);

		//uncomment out next 3 lines if debugging ADC
//		j = ADCReadRaw(TEMP1_CHANNEL);
//		j++;
//		j--;
	}
}
Esempio n. 5
0
int Relay::deactivateRelay(String data)
{
    return setRelay(data.toInt(), false);
}
Esempio n. 6
0
int Relay::activateRelay(String data)
{
    return setRelay(data.toInt(), true);
}