interrupt counting and PWM control

I want to control a motor, say i am counting the value of motor’s encoder, till it reaches to a number of 10 i want the pwm increasing from 0 to some respective value with the following code.

#define ENABLE 2
#define DIRB 6
#define DIRA 5
#define analogPin A0 // adc pin for getting sensor value

int ENCA = 2;
int ENCB = 3;
int value_up=0;//encoder
int value; //encoder
int a_read = 0; // analog value read

void setup() {
pinMode(DIRA, OUTPUT); //1A
pinMode(DIRB, OUTPUT); //2A
pinMode(ENABLE, OUTPUT); // Motor enable
digitalWrite(ENABLE,HIGH); //Eable Motor
Serial.begin(9600);
pinMode(analogPin, INPUT);

a_read=digitalRead(analogPin);
delay(1000);
Serial.begin(9600);
pinMode (ENCA, INPUT_PULLUP);
pinMode (ENCB, INPUT_PULLUP);
attachInterrupt(0, Encoder, RISING);
}

void loop() {
a_read = analogRead(analogPin);//read ADC
Serial.println(a_read);

/* iwant here to increase the alue of analogWrite through RISING till value_up==8 and then value of RISING will constant*/
if (a_read>=100 && a_read<135){
analogWrite(DIRA, RISING);
delay(10);
value_up==8;//reading from encoder
}

else if (a_read>=136 && a_read<195){
analogWrite(DIRA, RISING);
delay(10);}
value_up==10;//reading from encoder
//here now the DIRA should get some constant value now to be stable at the respective value_up
}

void Encoder(){
if(digitalRead(ENCB)== HIGH)
value++;

else
value–;

if(value==8960){value_up=1;}
}

I dont know how to write the above "if " statement correctly in respect to syntax of the Arduino.Would really appreciate your help.

analogWrite(DIRA, RISING);

What is it that you imagine this does?

value_up==8;//reading from encoder

This statement is useless. If you want to assign a value, use 1 equal sign. If you want to compare a value then use 2, but you should do something with that comparison.

Also, one more thing. If value and value_up are going to change inside the ISR, then they should be declared as volatile.

Delta_G: value_up==8;//reading from encoder

This statement is useless. If you want to assign a value, use 1 equal sign. If you want to compare a value then use 2, but you should do something with that comparison.

I want the program to check if the value_up reaches to 8. As soon as I get the value as 8 I want my program to set the PWM to a constant value so that I will get the constant speed.

Delta_G: analogWrite(DIRA, RISING);

What is it that you imagine this does?

My idea is tat through this RISING the value will get increased till value_up=8, I mean as soon as the valu_up=8 the DIRA will be assigned to a constant number.

dasa-hs: What is it that you imagine this does?

My idea is tat through this RISING the value will get increased till value_up=8, I mean as soon as the valu_up=8 the DIRA will be assigned to a constant number.

When an experienced person asks "what you imagine this does?" it means that you are doing something silly and you need to look up the Reference section of this website. RTFM.

...R

dasa-hs: My idea is tat through this RISING the value will get increased till value_up=8, I mean as soon as the valu_up=8 the DIRA will be assigned to a constant number.

Nope. RISING is #define'd in Arduino.h

#define RISING 3

So you might as well have written:

analogWrite(DIRA, 3);

dasa-hs: I want the program to check if the value_up reaches to 8. As soon as I get the value as 8 I want my program to set the PWM to a constant value so that I will get the constant speed.

If you want the program to check the value of something and run code on a condition, you need to use an if statement. You have a few of those in your program so I assume you know how they work. Just writing

value_up == 8;

on a line by itself does nothing.

if(value_up == 8) 
{
     // now here you can have some code to run conditionally
}