ahmad-al3omar
Joined: 25 May 2007 Posts: 16
|
very slow simulation |
Posted: Wed Apr 30, 2008 11:35 am |
|
|
dear all
i am using the following code in order to rotate a motor forward and backward related to the value of the potentiometer which connected to the ADC channel 0 and Channel 1
when i run the simulation on the proteus the simulation is very very very slow and i can't change the state of the pot. meter , it is not from my version all projects run perfectly but this not.
this is my code,, the second problem which i did not found any solution for it is that when i run the simulation there is a flashing high on pin c4-c7 i dont know why .plese help
please help me to find what i have to do
Code: | #include<16f877a.h>
#fuses noprotect,nowdt,xt
#use delay(clock=4000000)
#include<lcd.c>
float weight_a,weight_d,steer_a,steer_d,str_i,wgt_i, max_str, min_str,max_wgt,
min_wgt;
INT16 diff_wgt,diff_str;
void str()
{
set_adc_channel(0);
steer_d=read_adc();
delay_us(50);
set_adc_channel(1);
weight_a=read_adc();
delay_us(50);
}
main()
{
lcd_init();
setup_adc(adc_clock_internal);
setup_adc_ports(all_analog);
set_tris_c(0x00);
max_str=0;
min_str=0;
max_wgt=0;
min_wgt=0;
output_c(0B00000000);
while(1)
{
str();
if(steer_d>140 )
{
str_i=(steer_d-127);
if(str_i>max_str && str_i>10 )
{
diff_str=(str_i-max_str)*50;
output_high(pin_c0);
output_high(pin_c2);
delay_ms(diff_str);
output_low(pin_c0);
delay_ms(diff_str);
output_low(pin_c2);
}
else if(str_i<max_str && str_i>10 )
{
diff_str=(max_str-str_i)*50;
output_high(pin_c1);
output_high(pin_c3);
delay_ms(diff_str);
output_low(pin_c1);
delay_ms(diff_str);
output_low(pin_c3);
}
max_str=str_i;
}
str();
if(steer_d<110 )
{
str_i=(127-steer_d);
//str_f=str_i;
if(str_i>min_str && str_i>10 )
{
diff_str=(str_i-min_str)*50;
output_high(pin_c1);
output_high(pin_c3);
delay_ms(diff_str);
output_low(pin_c1);
delay_ms(diff_str);
output_low(pin_c3);
}
else
{
diff_str=(min_str-str_i)*50;
output_high(pin_c0);
output_high(pin_c2);
delay_ms(diff_str);
output_low(pin_c0);
delay_ms(diff_str);
output_low(pin_c2);
}
min_str=str_i;
}
str();
if(weight_a>76)
{
wgt_i=(weight_a-76);
if(wgt_i>max_wgt && wgt_i>10)
{
diff_wgt=(wgt_i-max_wgt)*50;
output_high(pin_c4);
output_high(pin_c6);
delay_ms(diff_wgt);
output_low(pin_c4);
output_low(pin_c6);
}
else
{
diff_wgt=(max_wgt-wgt_i)*50;
output_high(pin_c5);
output_high(pin_c7);
delay_ms(diff_wgt);
output_low(pin_c5);
output_low(pin_c7);
}
max_wgt=wgt_i;
}
}
} | [/code] _________________ A.T.N |
|