|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Arduino and kop encoder
do i have to divide the rpm by 360 since my encoder has 360 positions in 1 rotation?
|
|
#2
|
|||
|
|||
|
Re: Arduino and kop encoder
i noticed that your code resets back to zero after 60,000 rpm. it is reading much faster that actually spinning. what do i do to make it the actual rpm
My encoder is the kop encoder and it has 360 positions in 1 rotation |
|
#3
|
||||
|
||||
|
Re: Arduino and kop encoder
Quote:
Code:
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
#include <Servo.h>
Servo motor1; // create servo object to control a motor
Servo motor2; // ditto
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
float dt;
volatile byte rpmcount;
float rpm;
unsigned long timeold;
void setup()
{
motor1.attach(9); // attaches motor 1 on pin 9 to the servo object
motor2.attach(10); // ditto
attachInterrupt(0, rpm_fun, RISING);
rpmcount = 0;
rpm = 0;
timeold = 0;
digitalWrite(2, HIGH);
Serial.begin(9600);
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the motor (value between 0 and 180)
if (rpmcount >= 20) {
dt = (float)(millis() - timeold)/1000;
Serial.print(dt);
rpm = rpmcount/dt*60;
timeold = millis();
rpmcount = 0;
Serial.print(" RPM: ");
Serial.print(rpm);
Serial.print(" Pot: ");
Serial.print(val);
Serial.print("\n");
}
motor1.write(val); // sets the motor speed according to the scaled value
motor2.write(val);
}
void rpm_fun()
{
rpmcount++;
}
|
|
#4
|
|||
|
|||
|
Re: Arduino and kop encoder
Quote:
with your new code, the faster it spins, the lower the rpm. Last edited by SeanPerez : 04-25-2012 at 08:06 PM. |
|
#5
|
||||
|
||||
|
Re: Arduino and kop encoder
Quote:
If you are, disregard that. That's the "dt" value. Sorry, I didn't make it very legible. Look at the second set of numbers. 0.43 RPM: 2803.74 Pot: 82 means that 0.43 is the time between calculations, 2803.74 is the revolutions per minute, and 82 is the potentiometer value. |
|
#6
|
|||
|
|||
|
Re: Arduino and kop encoder
ok now im reading the right number. but it seems the rpm is way to high then the actual rpm.
im spinning it by hand and its reading around 21,000 rpm. this is way to high. im spinning it at around 60 rpm +or- 10 rpm |
|
#7
|
||||
|
||||
|
Re: Arduino and kop encoder
You didn't multiply it by 360 did you? If not, The arduino board MIGHT somehow me picking up every encoder tick. If that's the case, divide by 360. (Notice that 21000/360 = 58.3)
|
|
#8
|
||||
|
||||
|
Re: Arduino and kop encoder
It would make sense, by the way, if it is. My code is for a hall effect sensor being used as an encoder that reads a screw once per revolution.
|
|
#9
|
|||
|
|||
|
Re: Arduino and kop encoder
sorry if i was unclear but i was looking for code for a encoder that reads 360 positions per revolution compared to your 1 . no worries, all i did was divide your rpm by 360.
|
|
#10
|
||||
|
||||
|
Re: Arduino and kop encoder
So you got it working then? Dividing by 360 would be the solution I think.
|
|
#11
|
||||
|
||||
|
Re: Arduino and kop encoder
Oh, and I thought I'd caution you. There's a maximum read rate on the arduinos. It takes about 100 microseconds to take a reading, so it can read about 10,000 times/second. Since you're reading all 360 values every rotation, you've got a maximum of 27.78 rev/sec, or 1666.67 RPM. Not really sure what you're using it for, but keep that in mind.
|
|
#12
|
||||
|
||||
|
Re: Arduino and kop encoder
Thank you folks. I found this thread very informative and useful.
We are also working to "off-load" more robot functions to an Arduino Mega. Doc |
|
#13
|
|||
|
|||
|
Re: Arduino and kop encoder
Quote:
are you sure its 1666? i went up to as high as 2000 multiple times in a row |
|
#14
|
|||
|
|||
|
Re: Arduino and kop encoder
i think the fastest i could spin it was 2100rpm
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|