Show Posts
Pages: [1] 2 3 ... 11
1  Using Arduino / Programming Questions / Re: Explain what's happening with this RPM sketch on: August 23, 2014, 06:18:34 am
@vffgaston
It turned out to be caused by overflow. Did you read the posts above?
2  Using Arduino / Programming Questions / Re: Explain what's happening with this RPM sketch on: August 23, 2014, 12:05:16 am
So.. what if I want fast, non-integer-value calculations?
Is there any way around using floats?
3  Using Arduino / General Electronics / Re: A3144 hall effect sensor problems on: August 20, 2014, 11:58:54 am
Thanks. I will try these suggestions and post back. I was busy for the past couple of days, so I couldnt' check this thread.
4  Using Arduino / Programming Questions / Re: Explain what's happening with this RPM sketch on: August 20, 2014, 11:57:16 am
OK.
It wasn't obvoius to me because I assumed that setting the variable data type to long would tell the compiler that the whole calculation should done using longs. Now I know that that isn't the case..
Thanks for the help.

By the way, I read on the reference that using floats is much slower than using ints.
What about longs? Are longs slower than ints too? If so, are they faster than floats?
5  Using Arduino / Motors, Mechanics, and Power / Re: DC PID motor controller on: August 19, 2014, 11:22:54 pm
You were right about the RPM being relatively constant. I think the flicker I described was due to a problem in the Sketch I wrote.
However, I do plan to add a PID algorithm as some point.

What did you mean by "Error in rotation period"  as opposed to "estimating speed" ? By speed, were you referring to linear speed of the edge of the disk?
According to my current plant,  the input to the PID loop would be the RPM value of the spinning disc .. This is calculated by recording the time to complete a given number of  revolutions. Would that work?
6  Using Arduino / Programming Questions / Re: Explain what's happening with this RPM sketch on: August 19, 2014, 05:04:10 am
Thanks for the explanation.
I tried changing the dataype of rpm to float (without making any of the changes above) but that didn't work. If the data type of rpm is unsinged long, do we still have to include the U and L formatters?
7  Using Arduino / Motors, Mechanics, and Power / Re: DC PID motor controller on: August 18, 2014, 01:41:10 pm
I tried that approach but the hands on the clock flicker a bit.. I'm assuming that that's because of variations in the RPM.
One pulse per revolution is going to mean having a very slow responding loop, which
would take a while to settle down.

The disk is spinning at about 3000 RPM.. would that be too slow? (I'm not entirely sure what you mean by that part of your reply)
8  Using Arduino / Motors, Mechanics, and Power / DC PID motor controller on: August 18, 2014, 11:13:02 am
I started working on a POV clock project but instead of using a Hard disk driver, I'm trying to use a CD drive motor. This means that I need to use my own motor speed controlling mechanisms. I've just read about PID and this seems to be the way to go.

My CD drive RPM is sensed by a beam break sensor. The time taken for a given number of revs is counted and the RPM is calculated. Would this calculated RPM value be a suitable input to the PID algorithm?
9  Using Arduino / Programming Questions / Re: Explain what's happening with this RPM sketch on: August 14, 2014, 08:59:18 pm
max number (16 bits) is 65535.  I suspect an overflow
Try define the variable as long instead of int

I tried that.. but it didn't fix the problem.
Quote
60000 which overflows an int register.

I can see why the Op was confused because rpm was defined as an unsigned int and should be good to 65,535.

It is easy to overlook  that arithmetic with integer constants default to int.  http://arduino.cc/en/Reference/Arithmetic

Quote
U & L formatters

By default, an integer constant is treated as an int with the attendant limitations in values. To specify an integer constant with another data type, follow it with:
a 'u' or 'U' to force the constant into an unsigned data format. Example: 33u
a 'l' or 'L' to force the constant into a long data format. Example: 100000L
a 'ul' or 'UL' to force the constant into an unsigned long constant. Example: 32767ul


Could you please clarify your answer a little more?
10  Using Arduino / Programming Questions / Explain what's happening with this RPM sketch on: August 14, 2014, 01:01:40 pm
I'm using the RPM sketch from the arduino PlayGround. Here's the code:
Code:
volatile byte half_revolutions;

 unsigned int rpm;

 unsigned long timeold;

 void setup()
 {
   Serial.begin(9600);
   attachInterrupt(0, rpm_fun, RISING);

   half_revolutions = 0;
   rpm = 0;
   timeold = 0;
 }

 void loop()
 {
   if (half_revolutions >= 20) {
     //Update RPM every 20 counts, increase this for better RPM resolution,
     //decrease for faster update
     rpm = 30*1000/(millis() - timeold)*half_revolutions;
     timeold = millis();
     half_revolutions = 0;
     Serial.println(rpm,DEC);
   }
 }

 void rpm_fun()
 {
   half_revolutions++;
   //Each rotation, this interrupt function is run twice
 }

The sketch gives correct readings as it is..
However, my RPM meter counter entire revolutions, not half revolutions. To correct for this, I changed to "30 * 1000" to "60 * 1000 "  (60 = 30 x 2) . Since the sketch was designed to count half revolutions, I assumed that simply multiplying the value by 2 would be enought to make it work with a "1 interrupt per revolution" design.

As soon as I make the change, the output values become very strang.. I get seemingly random values in the range of 30,000 to about 50,000 but sometimes much lower or higher. I can't understand why this simple edit would cause those values..
Could it be some kind of overflow issue?
11  Using Arduino / General Electronics / Re: A3144 hall effect sensor problems on: August 14, 2014, 06:20:36 am
ok.. let me know if (and how) you get yours to wok
12  Using Arduino / General Electronics / Re: A3144 hall effect sensor problems on: August 13, 2014, 08:52:16 pm
This is my code: I'm using the arduino digitalRead example :
Code:
/*
  DigitalReadSerial
 Reads a digital input on pin 2, prints the result to the serial monitor
 
 This example code is in the public domain.
 */

// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState = digitalRead(pushButton);
  // print out the state of the button:
  Serial.println(buttonState);
  delay(1);        // delay in between reads for stability
}



How should I connect the decoupling capacitor?.. and what does it do?
My circuit looks like this , without the capacitors.
http://www.allegromicro.com/~/media/Images/Design/Unipolar-Hall-Effect-Sensor-IC-Basics/fig4.ashx?w=358&h=235&as=1
Basically, I "Supply" is connected to the 5V out from the arduino, Ground is connected to ground and "output" is connected to digital pin 2.
There's a 10k resistor between Vin and output. That's the pullup. Those are the only components in the circuit.
(I must admit, I'm not sure which pin is Vin and which is the ouput, because the datasheet doesn't allow me to identify which side of the device I'm looking at but I tried both polarities... it still didnt' work)
13  Using Arduino / General Electronics / A3144 hall effect sensor problems on: August 13, 2014, 12:06:26 pm
I'm having trouble hooking up a hall effect sensor to the arduino.

The datasheet is here : http://www.google.lk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCcQFjAA&url=http%3A%2F%2Fwww.allegromicro.com%2F~%2Fmedia%2FFiles%2FDatasheets%2FA3141-2-3-4-Datasheet.ashx&ei=nZrrU779PM668gWj5ILQBw&usg=AFQjCNEOdzCEoz2KfzfuhXorAUsx0yxKKg&sig2=jmfWgy-NqDJNQrKKHIq5lA

I wired it up with a 10K pull up resistor connected between Vin and the output from the sensor..
However, placing a magnet near the sensor has no effect what soever.
I bought two of these sensors and they both behave the same way.. is it possible that they are both broken? or am I doing something wrong?
14  Using Arduino / Sensors / Re: Arduino RPM sensor on: May 03, 2014, 10:31:30 am
The light I'm using an an infrared LED.

I'll try your suggestions abut darkening the CD. I wonder how the guys who made those tutorials did it.

Would using a hall effect sensor instead of an IR sensor solve this problem?
15  Using Arduino / Sensors / Re: Arduino RPM sensor on: May 03, 2014, 07:32:08 am
Thanks for your reply. smiley
In reply to your question, the POV effect is similar but not the same (I think) as the stroboscopic effect. It works because the human eye sees very high frequency pulses of light as a single continuous light. (This mechanism is used by old CRT monitors and TVs where the screen draws one line at a time)
The CD generates the POV effect.. it's primary purpose is not to generate a clock signal. However, the LEDs lighting the disk have to be turned on an off at specific times, which depend on the RPM. That's why it's important to accurately trigger interrupts.

The notch is about 1 - 2 mm (the width of a normal hack saw blade since that's what I used to cut it. smiley-wink )
Unfortunately, I don't know the exact RPM of the motor. It's a normal DVD drive motor and I'm powering it off of a 3.3V supply. 

I tried using a voltage comparator (just like the one in your images.. it's an LM339) and that certainly does reduce the magnitude of the problem. (less interrupts generated) but it does still generate multiple interrupts for each passage of the notch through the detector.

How does an RC circuit work? Would that be useful here?
Pages: [1] 2 3 ... 11