Skip to content

Instantly share code, notes, and snippets.

@gustavosinbandera1
Created January 5, 2021 22:38
Show Gist options
  • Save gustavosinbandera1/3c3e8a6d7177dab155c80c3711c1d9c4 to your computer and use it in GitHub Desktop.
Save gustavosinbandera1/3c3e8a6d7177dab155c80c3711c1d9c4 to your computer and use it in GitHub Desktop.
code
while (1) {
if (read) {
read = false;
for (channel = 0; channel < NUM_CHANNELS; channel++) {
adc_average[channel] += this->m_value[channel];
}
count++;
if (count >= num_cycles) {
count = 0;
for (int index = 0; index < NUM_CHANNELS; index++) {
reading = (uint16_t)((adc_previus_average[index]+ adc_average[index] / num_cycles)/ 2);
if (index == 6 || index ==7) {
if (reading >= 1739) {
this->m_value[index] = straping_vin[1739];
} else {
this->m_value[index] = straping_vin[reading];
}
} else if (index == 8 || index == 9 || index == 10) {
if(reading>3420) reading = 3420;
for(uint16_t k=0; k<4096; k++){
if(strapping_flex_input[k] == reading){
this->m_value[index] = strapping_flex_output[k];
break;
}
if(strapping_flex_input[k] > reading) {
this->m_value[index] = strapping_flex_output[k-1];
break;
}
}
}else {
//put code to thread others inputs like solar1, solar2, Min4,Vbatt
}
adc_previus_average[index] = adc_average[index]/ num_cycles;
}
dtoObj->updateADCBuffer(this->m_value);
dtoObj->serialize(this->buffer); //serializing DTO Object
if (!adc_queue.Enqueue(this->buffer)) { //sending to the I2C listener object
//error_handler();
}
for (int index = 0; index < NUM_CHANNELS; index++) {
adc_average[index] = 0;
}
}
HAL_Delay(3);
HAL_ADC_Start_IT(this->m_adc); //enabling DMA again
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment