how to loop this code 60 times the cout


{//--- read ADC input and calculate next PWM value.
str = "ousb -r adc 0" ;
Vavg = cpp_do_ousb_command(&str) ;
Vgen = Vext - (Vavg - Vsat*pwm/100) / ( 1 - pwm/100) ;
pwm += gain*(Vgen_goal - Vgen) ;
if (!isnormal(pwm)) pwm = 0 ; // if maths error set motor to stop.
if (pwm>100) pwm = 100 ;
if (pwm<0) pwm = 0 ;


//--- form PWM command and send to board.
stst.str("") ;
stst << pwm ;
str = "ousb pwm 1 " + stst.str() ;
cpp_do_ousb_command(&str) ;
}

do a loop 60 times of the code above then
cout << " pwm%= " << (int)pwm << ", ADC0= " << Vavg <<endl;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
for (int i=0; i<60; i++)
{//--- read ADC input and calculate next PWM value.
str = "ousb -r adc 0" ;
Vavg = cpp_do_ousb_command(&str) ;
Vgen = Vext - (Vavg - Vsat*pwm/100) / ( 1 - pwm/100) ;
pwm += gain*(Vgen_goal - Vgen) ;
if (!isnormal(pwm)) pwm = 0 ; // if maths error set motor to stop.
if (pwm>100) pwm = 100 ;
if (pwm<0) pwm = 0 ;


//--- form PWM command and send to board.
stst.str("") ;
stst << pwm ;
str = "ousb pwm 1 " + stst.str() ;
cpp_do_ousb_command(&str) ;
}
cout << " pwm%= " << (int)pwm << ", ADC0= " << Vavg <<endl; 

I guess, but it's a bit too obvous, is that really all you need?
Topic archived. No new replies allowed.