mossab hammad
Newbie level 4
i wont to change this project to close loop
i use resistance and feedback shaft encoder sensor
i wont change in code in mikroc
code
unsigned long kp,speed=0,speed1=0,old=0;
char speed2,kp,x=1;
char key[]={'x','x',3,2,1,'x',6,5,4,'x',9,8,7,'x',10,0,11},txt[10];
void main()
{
trisc=0;
Pwm_Init(5000);
delay_ms(20);
Keypad_Init(&PORTB);
delay_ms(20);
Lcd_Init(&PORTD);
delay_ms(20);
Lcd_Cmd(LCD_CURSOR_OFF);
Lcd_Cmd(LCD_CLEAR);
lcd_out(1,1,"SUST university" ) ;
lcd_out(2,1,"Electrical department" ) ;
delay_ms(3000);
Lcd_Cmd(LCD_CLEAR);
lcd_out(1,1,"Designed for:" ) ;
lcd_out(2,5,"Musaab hamad" ) ;
delay_ms(5000);
Lcd_Cmd(LCD_CLEAR);
Pwm_Start();
Pwm_Change_Duty(0);
delay_ms(20);
while(1)
{
while( !(kp = Keypad_Read())) {}
kp=key[kp];
speed=0;
x=1;
while(1)
{
if(kp==10)
{
old=speed1;
speed1=speed;
break;
}
if(kp==11)
{
speed1=old;
break;
}
speed=speed*10+kp ;
lcd_chr(1,x,kp+48);
delay_ms(40);
while( !(kp = Keypad_Read())) {}
kp=key[kp];
x++;
delay_ms(40);
}
if(speed1<=1000)
{
Lcd_Cmd(LCD_CLEAR);
lcd_out(2,1,"speed=" ) ;
inttostr(speed1,txt) ;
lcd_out_cp(txt) ;
speed2=(speed1*255)/1000;
Pwm_Change_Duty(speed2);
delay_ms(40);}
}
}
i use resistance and feedback shaft encoder sensor
i wont change in code in mikroc
code
unsigned long kp,speed=0,speed1=0,old=0;
char speed2,kp,x=1;
char key[]={'x','x',3,2,1,'x',6,5,4,'x',9,8,7,'x',10,0,11},txt[10];
void main()
{
trisc=0;
Pwm_Init(5000);
delay_ms(20);
Keypad_Init(&PORTB);
delay_ms(20);
Lcd_Init(&PORTD);
delay_ms(20);
Lcd_Cmd(LCD_CURSOR_OFF);
Lcd_Cmd(LCD_CLEAR);
lcd_out(1,1,"SUST university" ) ;
lcd_out(2,1,"Electrical department" ) ;
delay_ms(3000);
Lcd_Cmd(LCD_CLEAR);
lcd_out(1,1,"Designed for:" ) ;
lcd_out(2,5,"Musaab hamad" ) ;
delay_ms(5000);
Lcd_Cmd(LCD_CLEAR);
Pwm_Start();
Pwm_Change_Duty(0);
delay_ms(20);
while(1)
{
while( !(kp = Keypad_Read())) {}
kp=key[kp];
speed=0;
x=1;
while(1)
{
if(kp==10)
{
old=speed1;
speed1=speed;
break;
}
if(kp==11)
{
speed1=old;
break;
}
speed=speed*10+kp ;
lcd_chr(1,x,kp+48);
delay_ms(40);
while( !(kp = Keypad_Read())) {}
kp=key[kp];
x++;
delay_ms(40);
}
if(speed1<=1000)
{
Lcd_Cmd(LCD_CLEAR);
lcd_out(2,1,"speed=" ) ;
inttostr(speed1,txt) ;
lcd_out_cp(txt) ;
speed2=(speed1*255)/1000;
Pwm_Change_Duty(speed2);
delay_ms(40);}
}
}