RS232 motor control using ADC

Thread Starter

varunme

Joined Sep 29, 2011
60
i wrote a code for adc with rs232 in mikroC , to control a stepper with feedback, here i just made dummy values just to toggle the port bits , but its not working as the condition is satisfied , what will be the problem ?


Rich (BB code):
unsigned char ch;                    //
unsigned int adc_rd;                 // Declare variables
char *text;                          //
long tlong,ulong;
char output[7];
int i,rot; 
float ufloat,tfloat;
int uint;


void main() {
CMCON |= 7;

ADCON1 = 0X04;
ADCON1 = 0;
TRISA = 0x04;
ADCON1 = 0x80;
TRISB =0;                       //
PORTB=0x00;


while (1) {


        adc_rd = ADC_Read(2);        // A/D conversion. Pin RA2 is an input.
        Lcd_Out(2,1,text);           // Write result in the second line
        tlong = (long)adc_rd * 5000; // Convert the result in millivolts
        tlong = tlong / 1023;        // 0..1023 -> 0-5000mV
        ch = tlong / 1000;           // Extract volts (thousands of millivolts)
                                     // from result


          UART1_Init(9600);               // Initialize UART1 module at 9600 bps
          Delay_ms(100);                  // Wait for UART 1module to stabilize
          UART1_Write_Text("Start");
          UART1_Write(13);
          UART1_Write(10);


                 
                 
         while (!UART1_Data_Ready());        // wait for UART character in buffer

        // Initialize string with all '\0'
        for(i=0; i<7; i++){
            output = '\0';
        }

        UART1_Read_Text(output, "m", 255);   // read input from uart
      
        ulong = atol(output);
        
        
                    while(1)      {
                    

           if ( ulong =! tlong )
             {

                          if (ulong > tlong )
                          { PORTB.f1=1;
                          UART1_Write_Text("1");
                          break;
                          }
                          else //(ulong < tlong )
                         {PORTB.f1=0;
                         PORTB.f2=1;
                         UART1_Write_Text("2");
                         break;
                         }



           }
            if ( ulong == tlong )
            {
            PORTB.f3=1;
            UART1_Write_Text("3");
            PORTB.f1=0;
            PORTB.f2=1;
            break;
            }

          }
          }
 }        



 
Top