STM8s - if condition inside while is not updating continuously

Thread Starter

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


//adc read
// do calculation
print(volate read);

}
}
}
 

djsfantasi

Joined Apr 11, 2010
9,156
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
9,156
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.
 

Thread Starter

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
9,156
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
bat_volts = (1.22/adc_recorded)*1023;

    coilSense_adc = ADC_Read(AIN3); // adc 2
    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?
 

Thread Starter

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
bat_volts = (1.22/adc_recorded)*1023;

    coilSense_adc = ADC_Read(AIN3); // adc 2
    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?
I have two different equations because one is calculating the battery voltage and the other is an output coming from an op-amp for which I use a different equation. So these equations are working fine. Also, regarding coilsense_ADC globally declared was a careless mistake from my side, since it was working fine I didn't bother to change it.
 
Top