I want to control proportional valve using pwm generated by atmega 8. the pwm changed when changing analog input value. i did this code to make the pwm reached it's final value by ramping it, so i did the matrix K. the problem here is that the output pwm didn't stable at the final value (r) ], it goes up then down and so on
i want to ramp from rold to r
void main(void){float r;float rold =0;constunsignedint k[4]={4,6,8,10};/////slope of ramp upwhile(1){while(r!=rold)// check if the input changed or not equaled{////////////////////// ramp up pwmif(r>rold){for(i=0;i<4;i++){
r=read_adc(0);
x=r/10;// as i will multiply by K on the next step r from 0-5v
y=k[i]*x;
OCR1A=y*2000/1024;
delay_ms(50);}}
rold=r;}
r=read_adc(0);
x=r/10;// as i will multiply by K on the next step
y=k[3]*x;// stable at final value of x
OCR1A=y*2000/1024;}}