# STM8s - if condition inside while is not updating continuously

#### Prajeet Anand

Joined Aug 26, 2014
21
I'm doing an adc read as long as the GPIO is high. But once it enters the if loop it doesn't get automatically updated, I need to reset the GPIO in order to keep it running inside the loop. I have a timer to check and exit after a few seconds. I want to print the voltage continuously but it only prints it once and stops unless I rest the GPIO. What am I doing wrong. Is there any other way of doing it.

void main(){

while(1){

while(interrupt_1){

// interrupt function

}

if(interrupt2){ // check for GPIO high

// do calculation

}
}
}

#### djsfantasi

Joined Apr 11, 2010
7,870
With just an outline of the code, it could be anything...

Post your entire code inside code tags (use the ... drop down menu to insert them).

Then we might be able to help.

#### djsfantasi

Joined Apr 11, 2010
7,870
Thanks for posting the snippet. But what part of “post your entire” code didn’t you understand.

There are no definitions for many variables in this snippet. Other variables can’t be changed in your snippet. Apparently, there must be no typing errors because the variables aren’t typed. And since this is the case, this code must not even compile.

#### Prajeet Anand

Joined Aug 26, 2014
21
Thanks for posting the snippet. But what part of “post your entire” code didn’t you understand.

There are no definitions for many variables in this snippet. Other variables can’t be changed in your snippet. Apparently, there must be no typing errors because the variables aren’t typed. And since this is the case, this code must not even compile.
@djsfantasi I have posted the entire code. Please give it a look.

#### djsfantasi

Joined Apr 11, 2010
7,870
You use two different equations to calculate the battery voltage (? bat_volt) and the coil voltage (? coil_voltage). I suspect one is incorrect. Which one is it and what error would the miscalculation cause

Code:
uint16_t adc_recorded =  ADC_Read(AIN7); // adc 1

float coil_voltage = (bat_volts/1023)* coilSense_adc;
Also, you have mixed types in your equations. Float and uint_16. What are the difficulties in mixing types in an equation? Plus, I didn’t go back, but you don’t locally declare coilsense_ADC in the second equation. Is this intentional or an error? What error may occur in your equation with mixed types?

#### Prajeet Anand

Joined Aug 26, 2014
21
You use two different equations to calculate the battery voltage (? bat_volt) and the coil voltage (? coil_voltage). I suspect one is incorrect. Which one is it and what error would the miscalculation cause

Code:
uint16_t adc_recorded =  ADC_Read(AIN7); // adc 1
float coil_voltage = (bat_volts/1023)* coilSense_adc;