Society of Robots - Robot Forum
Software => Software => Topic started by: aruna1 on October 14, 2008, 09:48:53 AM
-
i wrote a little code to measure varience of a LDR connected to A0 and run a motor.but its not working.can some one point me the error.
i used 16F877A with 4MHz crystal,CCS C .
do i have to give ref voltages also
#include "D:\PIC C codes\16F877A\sensor+pwm\sensor+pwm.h"
int x=0,y=0;
void main()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,99,1);
setup_ccp1(CCP_PWM);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
set_adc_channel(0);
while(1)
{
delay_ms(10);
x=read_adc();
y=(x*100)/255;
output_high(PIN_B0);
output_high(PIN_C1);
set_pwm1_duty(y);
if(x<=256)
{
output_high(PIN_B1);
}
else
{
output_high(PIN_B2);
}
}
}
-
How do you know its not working? Compiler error? Robot isn't working? Sensor works but motor doesn't? Did you measure the LDR with your multimeter? More info please! And tell us what you did to try and debug it, also.
-
How do you know its not working? Compiler error? Robot isn't working? Sensor works but motor doesn't? Did you measure the LDR with your multimeter? More info please! And tell us what you did to try and debug it, also.
according to the code motor speed should vary with LDR sensitivity.i.e more ligt less speed low light high speed.but motor is not running at all.sensors give correct values but it seems PIC does not take thoes inputs
-
sensors give correct values but it seems PIC does not take thoes inputs
What do you mean? How do you know this? Did you check your circuit with a multimeter or using UART?
-
sensors give correct values but it seems PIC does not take thoes inputs
What do you mean? How do you know this? Did you check your circuit with a multimeter or using UART?
ya i check it with multi meter,
update pic takes in put(i wrote a code to turn on and off three LEDs indicating binary nubers 0 to 7 minimum light = 7(111),maximum light =0(000).so binary value changes with intensity.code worked.but when i connect motor it does not work. :(
-
Follow these instructions to fix your motor circuit:
http://www.societyofrobots.com/robot_faq.shtml#circuit_debug
-
Follow these instructions to fix your motor circuit:
http://www.societyofrobots.com/robot_faq.shtml#circuit_debug
thanks