go away spammer

Author Topic: 16F877A ADC help  (Read 6515 times)

0 Members and 1 Guest are viewing this topic.

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
16F877A ADC help
« 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
Code: [Select]
#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);
   }
   }

}

I'm Me

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: 16F877A ADC help
« Reply #1 on: October 16, 2008, 12:29:19 AM »
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.

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: 16F877A ADC help
« Reply #2 on: October 16, 2008, 02:13:35 AM »
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
I'm Me

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: 16F877A ADC help
« Reply #3 on: October 19, 2008, 05:02:55 AM »
Quote
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?

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: 16F877A ADC help
« Reply #4 on: October 19, 2008, 05:39:49 AM »
Quote
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. :(
I'm Me

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: 16F877A ADC help
« Reply #5 on: October 19, 2008, 06:07:39 AM »
Follow these instructions to fix your motor circuit:
http://www.societyofrobots.com/robot_faq.shtml#circuit_debug

Offline aruna1Topic starter

  • Supreme Robot
  • *****
  • Posts: 381
  • Helpful? 4
  • I'm an Ordinary guy
Re: 16F877A ADC help
« Reply #6 on: October 19, 2008, 06:28:44 AM »
I'm Me

 


Get Your Ad Here