Registered Users          New User?
Picture of John Miller
front sensor with dc motor
by John Miller - Sunday, December 27, 2009, 09:40 PM
 

I am trying to have a front sensor control a DC motor using the following code:

#include "mxapi.h"

void move (int count,int pulse_width[])
{
    int i;
        for (i=0; i<= count; i++)
        {
            RB3 = 1;
          delay_us (pulse_width [0]);
            RB3 = 0;
            RB0 = 1;
          delay_us (pulse_width [1]);
            RB0 = 0;
          delay_ms (20);
        }
}
void main (void)
{

        TRISC2 = 0;     // SET PORT C2 LEFT MOTOR
        TRISD0 = 0;     // SET PORT D0 LEFT MOTOR
        TRISC3 = 0;     // SET PORT C3 LEFT MOTOR

        TRISB3 = 0;
        TRISB0 = 0;
 
    adc_int(ALL_ANALOG); // INITIALIZE ANALOG INPUT

   while(1==1)
   {
      if(adc_read (0)>=250) // IF PORT A0 VALUE >=250
      {
        RC2 = 1;        // LEFT MOTOR STOP
        RD0 = 0;
        RC3 = 0;
      }
       else if(adc_read (0)<250) // IF PORT A0 VALUE <250
      {
        RC2 = 1;        // LEFT MOTOR FORWARD
        RD0 = 0;
        RC3 = 1;
      }
   }
}

I get an erro code of the following:

35: adc_int(0b00000000);
    ^ function declared implicit int (warning)
: : undefined symbol: (error)
: : _adc_int (motors2sensor.obj) (error)

any help would be great  thanks

John

Me
Re: front sensor with dc motor
by Ivan Rudnicki - Tuesday, December 29, 2009, 05:14 AM
  The function to initialize the analog to digital conversion is adc_init, not adc_int.

Note that this code will work only with the analog front sensors.