Go Down

Topic: Motor position control using single input encoder (Read 512 times) previous topic - next topic

ajbk

Mar 06, 2014, 06:54 pm Last Edit: Mar 06, 2014, 07:00 pm by ajbk Reason: 1
I am trying to control a 24V DC motor position using a single input encoder. The encoder wheel has got 30 spikes on it. It is connected to the interrupt 0 pin. I am trying to move the motor first to a forward position (theta1 = 120deg) from a home position. Then back to the home position from where it has to be moved to a backward position (theta1D = 90deg). I have written a code for the same but while compiling it gives an error on line 6 as
error : expected unqualified-id before '{' token
The code is as shown below:
Code: [Select]
int encoder1Pin = 2;
int motor1PinA = 3;
int motor1PinB = 4;
volatile int encoder1Pos = 0;

{
void setup ()
{
  pinMode(encoder1Pin,INPUT);
  pinMode (motor1PinA,OUTPUT);
  pinMode (motor1PinB,OUTPUT);
  attachInterrupt(0, ISR, CHANGE);
  int theta1 = 120;
  int theta1D = 90;
}
   int motor1Forward();
  {
    digitalWrite(motor1PinA,HIGH);
    {
    if(encoder1Pos*6 == theta1);
    }
    digitalWrite(motor1PinA,LOW);
    encoder1Pos = 0;
  }
  int motor1Home();
  {
    digitalWrite(motor1PinB,HIGH);
    {
      if(encoder1Pos*6 == theta1);
    }
    digitalWrite(motor1PinB,LOW);
    encoder1Pos = 0;
  }
  int motor1Backward();
  {
     digitalWrite(motor1PinB,HIGH);
    {
      if(encoder1Pos*6 == theta1D);
    }
    digitalWrite(motor1PinB,LOW);
    encoder1Pos = 0;
  }
}
{
  void ISR()
  {
    encoder1Pos++
  }
}


UKHeliBob

The line that it errors on has an opening brace on it.  Why ?

The outer braces in this code section need to go as well
Code: [Select]
{
  void ISR()
  {
    encoder1Pos++
  }
}

As do the semi-colons at the end of the function names such as this one (and others)
Code: [Select]
int motor1Home();
There may be other problems but I stopped looking.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

ajbk

Thanks UKHeliBob..
I modified the code as shown below. But still errors.
Code: [Select]
int encoder1Pin = 2;
int motor1PinA = 3;
int motor1PinB = 4;
volatile int encoder1Pos = 0;
int theta1 = 120;
int theta1D = 90;

void setup() {
 pinMode(encoder1Pin,INPUT);
 pinMode (motor1PinA,OUTPUT);
 pinMode (motor1PinB,OUTPUT);
 attachInterrupt(0, encoder1svc, CHANGE);
}

void loop()
{
int motor1Forward()
{
 digitalWrite(motor1PinA,HIGH);
 {
   if(encoder1Pos*6 == theta1);
 }
 digitalWrite(motor1PinA,LOW);
 encoder1Pos = 0;
}
int motor1Home()
{
 digitalWrite(motor1PinB,HIGH);
 {
   if(encoder1Pos*6 == theta1);
 }
 digitalWrite(motor1PinB,LOW);
 encoder1Pos = 0;
}
int motor1Backward()
{
 digitalWrite(motor1PinB,HIGH);
 {
   if(encoder1Pos*6 == theta1D);
 }
 digitalWrite(motor1PinB,LOW);
 encoder1Pos = 0;
}
void encoder1svc()
{
 encoder1Pos++;
}
}








UKHeliBob

#3
Mar 06, 2014, 10:57 pm Last Edit: Mar 06, 2014, 10:59 pm by UKHeliBob Reason: 1
You have got several function definitions within the loop() function.  In fact there is nothing in the loop() function apart from function definitions.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up