 # motor controll

hello everyone,

i am doing a project where I have to turn on the motor taking input from a analog angle detection sensor. When I have the sensor reading value 255 then the motor has to turn in a constant 7000rpm. Say I have sensor connecting in A3 and encoder of motor in interrupt pin2 and pin3 (Arduino Uno). The following code I am trying to write, I would really appreciate your assistance-

//val is reading from analog sensor
if (val > 200) { // I dont know hot to set the val as a term of 200 < val = 256
delay(10);
digitalWrite(DIRB,LOW);
analogWrite(DIRA,val);

for (intrpt=0; intrpt >= 7000; intrpt++){
intrpt >= 7000;// counting till 7000 interupts
intrpt = intrpt;}
}

`````` for (intrpt=0; intrpt >= 7000; intrpt++){
intrpt >= 7000;// counting till 7000 interupts
intrpt = intrpt;}
``````

What in the world are you imagining that to do? The first line in the for loop (the one with the comment) is a comparison that doesn’t get assigned to anything or used for anything so it is worthless. The second line just sets a variable equal to itself. How in the world is that useful?

Also, what does this statement mean?

``````// I dont  know hot to set the val as a term of 200 < val = 256
``````

as I mentioned I need a constant rpm of 7000 of the motor when my ADC value is in a range of 200 to 256. My idea was to count the interrupt from the hall effect encoder of the motor till 7000 (I guess that does mean the shaft of the motor has rotate 7000 times).

About the code I am not sure as I mentioned. Perhaps you can suggest something :) thanks

dasa-hs: Perhaps you can suggest something :) thanks

A basic tutorial on C++ so you can maybe understand just a little about syntax, variables, and what a for loop really does. Start with the basics before you get into something way over your head.

I doubt you will get any desirable motor control when making decision on change of motor speed once every minute (7000 revolutions). Your going to have to calculate the current speed and decisions on speed change much more frequently. Is the encoder your own creation? - Scotty