DC motor Steering control through POT

AWOL:

If you mean Pulse Position Modulation, I think you're using the wrong term. Standard RC servos use Pulse Width Modulation

Lefty is absolutely right.
Digital R/C systems (used to be called "digiprop" for "digital proportional") have used PPM for at least the last 35 years.
The difference is subtle, and you could use PWM to generate a PPM-compatible waveform (though you're advised not to) using the Arduino's eight bit PWM, which is at too high a frequency by default (a servo or ESC may not work at all with too high a frame-rate, or may draw excessive current), and has too low resolution.
If you take a typical range of an R/C PPM pulse of 1 to 2ms, an eight bit resolution PWM generating the whole 20ms frame will give only about twelve graduations or positions.

I do understand the different between the PWM provided by the analog pins and the PWM used by ordinary RC servos, but I still don't understand why you refer to the servo signal as PPM. It is not Pulse Position Modulation as I understand the term. PPM is a synchronous signalling technique requiring a timing reference, and obviously (?) it's inherently impossible for the single wire servo signal to be synchronous. Perhaps PPM means something different to you - if so, could you explain what meaning you're giving the term?

I appreciate that you want to make a distinction between a servo control signal and an Arduino's ordinary analogue output signal, but using a term which is flat-out wrong is imo not a good way to achieve that.

Peter i am not concern about servo i am only concerned about DC Motor that i need to work with and it can be controlled Using PWM.

and i am using POT to know the particular number of degree of the steering Moved

      if (a){
        Serial.println("i am in the center");
      }
      else  
      {
        analogWrite(m1,255);
      }
      else
      {
        analogWrite(m2,255);
      } 
...
      if (fval>=975)
      {
        Serial.println("Direction = Right");
      }
      else
      {
        analogWrite(m1,255);
      }
      else
      {
        analogWrite(m2,255);
      }

Novel - the ever-useful third option.

What are you trying to say you mean to say that i cant use else second time

I have commented the else for the second time but i am still Getting the error

const int apin =A0;
const int m1 = 9;
const int m2 = 11;
int aval = 0;
int fval = 0;
int cval;
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
}
void loop()
{
  // read the analog in value:
  aval = analogRead(apin);  
  // map it to the range of the analog out:
  fval = map(aval,0,0,0,1023);  
  // change the analog out value:
}
void check_input() {

  if ( Serial.available()) {

    char ch = Serial.read();
switch(ch) {       

      case 'l':
        Serial.println("wana go left");
        if(fval <= 49){
        Serial.println("i'm in left");}
        else if(fval > 49)
        {
         analogWrite(m1,255);
         analogWrite(m2,0);
         delay(1000);
        }
         digitalWrite(13, HIGH);
         break;
      case 'c':
        Serial.println("Center the Steering");
        int a=constrain(fval,470,510); 
        if (a){
          Serial.println("i am in the center");
                }
          else  
              {
                analogWrite(m1,255);
              }
  //     else
     {
       analogWrite(m2,255);
       } 
//        //motor_run = false;
        //motor_started = false;
        //analogWrite(motor_cur_pin, 0);
        //digitalWrite(13, LOW);
        break;
      case 'r':
        //motor_cur_pin = MOTOR_LT_PIN;
        if (fval>=975)
        {
        Serial.println("Direction = Right");
        }
        else
        {
        analogWrite(m1,255);
        }
        //else
        {
        analogWrite(m2,255);
        }
        break;
      //case 'r':
        //motor_cur_pin = MOTOR_RT_PIN;
        //Serial.println("Direction = RIGHT");
        //break;
    }
  }
}

ERROR

Discus_forum.cpp: In function 'void check_input()':
Discus_forum:56: error: jump to case label
Discus_forum:39: error: crosses initialization of 'int a'

How can you have a second else?
It's meaningless.
It is a binary proposition "if (something is true)" else "it isn't true"

You need to enclose your case 'c' block in braces:

      case 'c':
       {
        Serial.println("Center the Steering");
        int a=constrain(fval,470,510); 
        if (a){
          Serial.println("i am in the center");
                }
          else  
              {
                analogWrite(m1,255);
              }
  //     else
     {
       analogWrite(m2,255);
       } 
//        //motor_run = false;
        //motor_started = false;
        //analogWrite(motor_cur_pin, 0);
        //digitalWrite(13, LOW);
       }
        break;

You can't declare a variable directly in a case block.

Or declare a outside the switch/case.

the error is removed it worked thanx

if i can't use else twice so how to use it
what can i use instead Of second else

what can i use instead Of second else

To do what?

i am trying to Make the steering of my Robot to move in three states Left 0-50,Right 975-1023 and center 470-510 for which i have developed the following code and i will welcome any more suggestions in the code

const int apin =A0;
const int m1 = 9;
const int m2 = 11;
int aval = 0;
int fval = 0;
int cval;
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
}
void loop()
{
  // read the analog in value:
  aval = analogRead(apin);  
  // map it to the range of the analog out:
  fval = map(aval,0,0,0,1023);  
  // change the analog out value:
}

void check_input() 
{

  if ( Serial.available()) {

    char ch = Serial.read();
switch(ch) {       

      case 'l':
        Serial.println("wana go left");
        if(fval <= 49){
        Serial.println("i'm in left");}
        else if(fval > 49)
        {
         analogWrite(m1,255);
         analogWrite(m2,0);
         delay(1000);
        }
         digitalWrite(13, HIGH);
         break;
      case 'c':
        {
        Serial.println("Center the Steering");
        int a=constrain(fval,470,510); //if the POT is in between 470-510
        if (a==a){
          Serial.println("i am in the center");// then the Steering is in the center
                }
          else if(fval>470)//Steering is inthe Left
              {
                analogWrite(m1,255);  
              }
              else       //steering is on the right
              {
                analogWrite(m2,255);
              } 

        //digitalWrite(13, LOW);
        }
        break;
      case 'r':
        //motor_cur_pin = MOTOR_LT_PIN;
        if (fval>=975)
        {
        Serial.println("Direction = Right");
        }
        else
        {
        analogWrite(m1,0);
        analogWrite(m2,255);
        delay(1000);
      }
        break;
    }
  }
}

You still need to fix this...

  aval = analogRead(apin);  
  // map it to the range of the analog out:
  fval = map(aval,0,0,0,1023);

Reference: map(value, fromLow, fromHigh, toLow, toHigh)

You want to map values of aval between 0 and 0 to a range of 0 to 1023?

0-1023 is my POTs BIT that i have Designated i dont understand what are you trying to say

The map function converts an input range of values (fromLow to fromHigh) from a variable to an output range (toLow to toHigh). Your input range starts at zero and ends at zero.

http://arduino.cc/en/Reference/Map

You're still not calling "check_input", so all of this discussion is pretty pointless.

Is this Ok

const int apin =A0;
const int m1 = 9;
const int m2 = 11;
int aval = 0;
int fval = 0;
int cval;
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
}
void loop()
{
  // read the analog in value:
  aval = analogRead(apin);  
  // map it to the range of the analog out:
  fval = map(aval,0,1023,0,255);  
  // change the analog out value:
}

void check_input() 
{

  if ( Serial.available()) {

    char ch = Serial.read();
switch(ch) {       

      case 'l':
        Serial.println("wana go left");
        if(fval <= 49){
        Serial.println("i'm in left");}
        else if(fval > 49)
        {
         analogWrite(m1,255);
         analogWrite(m2,0);
         delay(1000);
        }
         digitalWrite(13, HIGH);
         break;
      case 'c':
        {
        Serial.println("Center the Steering");
        int a=constrain(fval,470,510); //if the POT is in between 470-510
        if (a==a){
          Serial.println("i am in the center");// then the Steering is in the center
                }
          else if(fval>470)//Steering is inthe Left
              {
                analogWrite(m1,255);  
              }
              else       //steering is on the right
              {
                analogWrite(m2,255);
              } 

        //digitalWrite(13, LOW);
        }
        break;
      case 'r':
        //motor_cur_pin = MOTOR_LT_PIN;
        if (fval>=975)
        {
        Serial.println("Direction = Right");
        }
        else
        {
        analogWrite(m1,0);
        analogWrite(m2,255);
        delay(1000);
      }
        break;
    }
  }
}

No.
See reply #34

int a=constrain(fval,470,510); //if the POT is in between 470-510
        if (a==a){

Are you smoking something you shouldn't?

As AWOL is saying, you now need to actually call check_input().

is there any Mistake using Constrain i have call checl_input............

void loop()
{
  // read the analog in value:
  aval = analogRead(apin);  
  // map it to the range of the analog out:
  fval = map(aval,0,1023,0,255);  
  // change the analog out value:
  check_input();
}

fval varies from 0-255 depending on pot position, so constraining it to the range 470-510 means a will always be 470.

I'm a bit confused how this is meant to work. You have a pot that is supposed to be for steering, but then you also have some serial input as well. How are the two supposed to work together?