Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: attachInterrupt() NOT WORKING ? on: March 27, 2011, 08:35:08 pm
I posted part of my code.

Where does cm change?    changes in the loops

What is the nature of the input? A light sensor? A switch? How is it wired?

the input is i digital encoder with infrared light transmitted all the time.
every time the infrared light is CUT, it send a pulse.


I want to read the number of pulses all the time and CAPTURE the time between pulses. that is why I put the attachInterrupt() in the LOOP.

i'm feeding the pulse to digital input 2 (interrupt Pin in the duemilanove)

(cm) does change in my code, but for the sake of this forum i set it to 160 to capture time. I'm not capturing anything. HELP?


i am a biggner i don't even know what ISR stand for
2  Using Arduino / Programming Questions / attachInterrupt() NOT WORKING ? on: March 27, 2011, 06:38:06 pm
can someone help with my interrupt?
I AM  sending pulses, but the interrupt is not doing anything ? i'm using duemilanove

THE CODE:



int encPin = 2;      //pulses sent to this pin

volatile int pulses=0;
long cm;
float speedMS, maxSpeed = 0;
float newTime, distance = 0.018786;
volatile float endTime,startTime;

void setup()
{
Serial.begin(9600);      // initialize serial communication:
pinMode(encPin, INPUT);   // sets the digital pin 2 as output

}

void loop()               //START OF VOID LOOP
{
cm = 160;

if (cm > 150 || cm ==0)          
{
attachInterrupt(0, blink, RISING);   //grap the time to pulse at each low-to-high
}

  if (pulses>1)            //calculate speed each 2 pulses
  {
    newTime = (endTime-startTime)/1000000;   //calculate time for 2 pulses (in seconds)
    speedMS = distance /newTime;      //calculate the speed (m/s) of the car
    pulses=0;                  //reset the pulse counter
  }

}    //END OF LOOP

void blink()                      //keep track of pulse count AND the Time form pulse 1 to pulse 2
{
pulses++;
if (pulses==1)
{
startTime = micros();      //Time when pulse 1 is detected
}
if (pulses==2)
{
endTime = micros();      //Time when pulse 2 is detected
}
3  Using Arduino / Programming Questions / Re: embarrassing IF question? on: March 25, 2011, 06:18:17 pm
can I do the Following? using millis()?

enCoder = digitalRead(encPin);
if (enCoder == LOW)
{
   x++;
   if (x==14)
   {
      rev++;
      endTime = millis();
      Time= endTime - startTime;
      startTime=endTime;
      Time = Time*1000;
      x=0;
      distance = 0.201062;
      speedsMS = distance/Time;
   }
}

with all variables inside the if statement are FLOAT?
4  Using Arduino / Programming Questions / Re: what is SetMode(...)? for PID on: March 25, 2011, 01:31:59 am
thank you
5  Using Arduino / Programming Questions / what is SetMode(...)? for PID on: March 25, 2011, 12:17:23 am
hello,

from
http://www.arduino.cc/playground/Code/PIDLibrary

i don't understand the function of SetMode(AUTO/MANUAL).
i'm guessing that when set to AUTO, it set values for P_param, I_param, D_param. automatically,
MANUAL: the user enters these values.

am I right?


thnx
6  Using Arduino / Programming Questions / Re: embarrassing IF question? on: March 23, 2011, 04:08:29 pm
You realize that you lost decimals if you don't play with casting? I don't know if I use the right term here...

I think it would be a good think to use suitable variables, instead of long or unsigned long. Do you need negative values?

Cheers,
Kari

i don't need negative values. and i'd like to keep my decimals. what do you recommend ?
I want to use millis(); but in the example posted they 're using unsigned long.

example:
http://arduino.cc/en/Reference/Millis
7  Using Arduino / Programming Questions / Re: embarrassing IF question? on: March 23, 2011, 01:21:52 pm
sry HERE's the code:

Code:
{
    revoloutions ++;  //add one to revoloutions - the wheel has turned round one more time
    endRotation = millis();  //keep track of the time that the rotation completed
    rotationTime = endRotation - startRotation;  //work out the time of the full rotation
    startRotation = endRotation;  //the next rotation starts when the previous one finished, so make them have both the same values
    RPM = (60000 / rotationTime);  //find out how many times you can get the rotation time inot one minute - hence working out the RPM
    distanceTravelled = revoloutions * wheelCircumference;  //the distance travelled will be the ammount of rotations * the distance travelled per rotation
    distanceTravelledPerSecond = RPM * wheelCircumference;  //speed = distance / time. The time for this is 1 second, the distance is worked out here
    distanceTravelledPerSecond = distanceTravelledPerSecond / 100;  //This gives the distance travelled per second in meters, not centimeters
    speeds = distanceTravelledPerSecond;  //The speed will be in m/s, and this is the ammount of meters travelled per second, or m/s, so it is the speed!
    if(speeds > maximumSpeed)
      maximumSpeed = speeds;  //if the new speed is faster than the maximum speed, make the current speed the new maximum speed
    timeInSeconds = millis();  //This will give the ammount of milliseconds that the program has been running for
    timeInSeconds = timeInMilliseconds / 1000;  //This will turn the time in milliseconds into the time in seconds
    averageSpeed = (distanceTravelled / timeInSeconds);  //This will give the average speed
}

oh and I still need help on my problem if you guys can help smiley


sorry to bother you again but can I use unsigned long for all variables?

8  Using Arduino / Programming Questions / Re: embarrassing IF question? on: March 22, 2011, 10:23:26 pm
Set up another boolean variable. Let's call it "armed".
Start by setting armed = TRUE.
Then as soon as you see the pin go high AND armed = TRUE, increment the counter, and set armed = FALSE
Then as soon as you see the pin go low AND armed = FALSE, set armed = TRUE

this is my part of my code now:

val = digitalRead(inPin);
if (val == 1 && armed == true)
{
    enc_counter +=1;
    armed = false;
}

val = digitalRead(inPin);
if (val == 0 && armed == false)
{
     armed = true;
}


assuming my code is correct, and I got the revolutions now.
how can I get the RPM or RPS (per second). in another word, how can digitalRead(inPin) within certain TIME, say 5 seconds?

here's some code to help you out, this is from my program and it calculates RPM, speed, distance, max speed and average speed.

See how you can adapt your code to include mine



I can't see the code?
9  Using Arduino / Programming Questions / Re: embarrassing IF question? on: March 22, 2011, 09:53:09 pm
Set up another boolean variable. Let's call it "armed".
Start by setting armed = TRUE.
Then as soon as you see the pin go high AND armed = TRUE, increment the counter, and set armed = FALSE
Then as soon as you see the pin go low AND armed = FALSE, set armed = TRUE

this is my part of my code now:

val = digitalRead(inPin);
if (val == 1 && armed == true)
{
    enc_counter +=1;
    armed = false;
}

val = digitalRead(inPin);
if (val == 0 && armed == false)
{
     armed = true;
}


assuming my code is correct, and I got the revolutions now.
how can I get the RPM or RPS (per second). in another word, how can digitalRead(inPin) within certain TIME, say 5 seconds?
10  Using Arduino / Programming Questions / Re: embarrassing IF question? on: March 22, 2011, 09:05:46 pm
thnx for replying, I guess I can use your line:

enc_counter += digitalRead(inPin);

to count the number of time my input goes to HIGH.

BUT, how can I Read (inPin) for say 5 seconds then execute the next line?
OR, how can I read  for 5 seconds without delaying the program?

11  Using Arduino / Programming Questions / embarrassing IF question? on: March 22, 2011, 08:25:40 pm
this is embarrassing, can i do the following:

const int inPin = 8;
int val =0;
int enc_counter =0;

val = digitalRead(inPin);
if (val == HIGH)                   //can i use HIGH or 0 ???
{
    enc_counter +=1;
}


count every time a high is sent to PIN 8:


thank you

bassam
12  Using Arduino / Motors, Mechanics, and Power / How to Increase the PID Response time? on: February 14, 2011, 06:20:33 pm
Hello,

I have example 1 from the link below setup to control the speed of a dc motor.
http://www.arduino.cc/playground/Code/PIDLibrary

Error = Setpoint - input
output = PWM;     // to control the speed.

when the error is positive = increase speed = PWM duty cycle go to 100%
when the error is negative = decrease speed = PWM duty cycle go to 0%

THE PROBLEM:
I've tried alot of values for P_Param and I_Param. keeping D_Param = 0.
the response time (for the duty cycle to go from 100% to 0%) is really slow. How can i increase the response time? specially when the error is negative.

Thank you,
Bassam



13  Using Arduino / Motors, Mechanics, and Power / Reading encoder Pulses ? on: February 08, 2011, 09:19:54 pm
Hello,

I have an encoder setup that outputs 8 pulses per revolution (PPR), how can read those pulses using arduino? what kind of input should I use OR where should I connect the encoder pulse output on the arduino?

thank you
14  Using Arduino / Motors, Mechanics, and Power / Re: PID Example 1 on: February 08, 2011, 08:12:38 pm
see what I"m trying to do is to control the PWM via distance. i'm using the following
http://www.arduino.cc/en/Tutorial/Ping

to read distance and i'm thinking of feeding the distance that the sensor is reading as a PID Input.
i'm unable to figure this out, can i do the following:

input = cm;

?
15  Using Arduino / Motors, Mechanics, and Power / Re: PID Example 1 on: February 08, 2011, 05:44:18 pm
thnx for replying and thenx for posting the source, question, what kind of input can I use at ANALOG IN 0 ? just to get this example working?

also, is the output in analogWrite(3,Output), (0<output<255) to control the duty cycle of the PWM?
Pages: [1] 2