//real time operating system - scheduler void RTOS(){ //1s task if(Timer1s){ Timer1s=0; sendCellMinVoltage_send=1; sendCellMaxBalancing_send=1; sendCellMaxVoltage_send=1; if (ADC_OK) { CalcTemps(); ADC_ChanelCnt = 0; //Zaženi ADC sekvencao ADC_SampleCnt = 0; SelChanConvADC(ADC_Chanels[ADC_ChanelCnt]); ADC_OK = 0; } //if readout of all cells is ok than we toggle the LED1_TOGGLE LED2_TOGGLE //lifebeat if(test_bit(BmsStatus0, STATUS_B0_ALL_ROK)){ if(LED2_STATUS==1) LED1_OFF else LED1_ON }else{ LED1_OFF } }
/****************************************************************************** Function: void ADLsample(BYTE *data, const BYTE ADLoffset, const BYTE ch) Summary: Function to sample an analog pin and place the value in an array Conditions: * A/D Converter must be configured * Analog pins must be initilized Input: *data - pointer to data array ADLoffset - where in the data array to place the data to conform to ADL protcol ch - the analog channel (pin) to sample Return Values: none Side Effects: sampled value is added to the data array passed Description: ****************************************************************************/ void ADLsample(BYTE *data, const BYTE ADLoffset, const BYTE ch) { unsigned int temp; SelChanConvADC(ch); // configure which pin you want to read and start A/D converter while(BusyADC()); // wait for complete conversion // put result in data array in accordance with specified byte location temp = (unsigned int)ReadADC(); modifyRotary(&temp); data[ADLoffset] = ((BYTE *)&temp)[1]; data[ADLoffset + 1] = ((BYTE *)&temp)[0]; return; }
/* Eval voltage on a channel * result on volt */ short V_Eval(unsigned char channel,signed float *voltage) { signed float temp = 0; SelChanConvADC(channel); timeout = ADC_TIMEOUT; while(BusyADC() && timeout > 0); //Wait here until conversion is finished if (timeout == 0) { return KO; } temp = ReadADC(); *voltage = (temp / 1024.0) * 5.0; return OK; }
/** * uint16_t sample(const uint8_t ch) * * This function reads the analog voltage of a pin and then returns the value * * @param ch - which pin to sample */ uint16_t sample(const uint8_t ch) { SelChanConvADC(ch); // Configure which pin you want to read and start A/D converter while(BusyADC()); // Wait for complete conversion return ReadADC(); }