Glasgow, scotland
Offline
Newbie
Karma: 4
Posts: 42
Arduino rocks
|
 |
« on: January 26, 2011, 05:59:18 pm » |
Hi guys I've been making an optical tachometer, trouble is it can't seem to read fast RPM's like those of an average motor you get in a starter kit, it can read up to like 3000 RPM, but beyond that it's all over the place my test motor has a 2 slot circle with an LED shining through onto the LDR, and the motor is powered by battery to rule out interference ( I thought at least  ). I tried different slot sizes to no avail. Is my code alright? if so, is there fast and slow LDR's or something? unsigned long time=0; unsigned long time2=0; unsigned long rpm; unsigned long period; int counts=0; int potpin=1; int motorpin=10; int motor; unsigned int runs=0;
void setup(){ Serial.begin(9600); attachInterrupt(0,ping,RISING); }
void loop(){ motor=analogRead(potpin); motor=map(motor,0,1023,0,255); analogWrite(motorpin,motor); if(runs>2840){ // this no. of runs means it takes exactly 500 millis noInterrupts(); time2=micros(); period=time2-time; rpm=counts*60000000; rpm=rpm/period; Serial.print(period); Serial.print(" "); Serial.print(counts); Serial.print(" "); Serial.println(rpm); counts=0; runs=0; time=micros(); interrupts(); } runs++; } void ping(){ counts++; }
thanks!!
|
|
|
|
|
Logged
|
|
|
|
|
Washington
Offline
God Member
Karma: 20
Posts: 717
Firefox & Arduino rocks
|
 |
« Reply #1 on: January 26, 2011, 06:10:11 pm » |
CDS cells are very slow having a maximum speed of around 30 times per second (at best).
|
|
|
|
|
Logged
|
Avoid throwing electronics out as you or someone else might need them for parts or use. Solid state rectifiers are the only REAL rectifiers. Resistors for LEDS!
|
|
|
|
Cumming, Ga
Offline
Edison Member
Karma: 12
Posts: 1389
Ultimate DIY: Arduino
|
 |
« Reply #2 on: January 26, 2011, 06:17:20 pm » |
LDR's are inherently slow. In fact, the slow recovery of an LDR is often exploited as an advantage. (like 250rise to 300fall micro seconds) which is Damn Slow in my book and not good for anything faster than about 2000 RPM. So in your case, it's just the wrong part. You should re-design your solution and consider using a Photo-Diode or a Photo-Transistor. A photo-transistor traditionally would have higher sensitivity with a trade-off in response time compared to a photo-diode. Honestly though, a Photo-Transistor should be just fine for what you want. Example of how one gets used: http://kitsnspares.com/admin/pdffiles/uC%20based%20Tachometer.pdf
|
|
|
|
|
Logged
|
|
|
|
|
Glasgow, scotland
Offline
Newbie
Karma: 4
Posts: 42
Arduino rocks
|
 |
« Reply #3 on: January 26, 2011, 06:29:58 pm » |
guess i'll have to go digging in a radio or something, i'll pst results with a phototransistor cheers! a nice karma 4 u  wish it was called internets, " i award you +1 internets fine sir "
|
|
|
|
|
Logged
|
|
|
|
|
Glasgow, scotland
Offline
Newbie
Karma: 4
Posts: 42
Arduino rocks
|
 |
« Reply #4 on: January 26, 2011, 07:11:28 pm » |
By the way, where is a good place to dig for a phototransistor? 
|
|
|
|
|
Logged
|
|
|
|
|
Jakarta
Offline
Newbie
Karma: 0
Posts: 10
Arduino rocks
|
 |
« Reply #5 on: January 26, 2011, 09:03:44 pm » |
If "the light" is not mandatory measurements object, why not try hall-effect? I think it is a better option....
|
|
|
|
|
Logged
|
|
|
|
|
Brisbane, Australia
Offline
Newbie
Karma: 3
Posts: 35
B.E.E. / B.Inf.Tech.
|
 |
« Reply #6 on: January 26, 2011, 09:09:24 pm » |
Alternatively to a phototransistor/photodiode you might want to consider a photo-interrupter, preferably with logic output. This makes the design much simpler and you can avoid the analog signals. A very nice photo-interrupter I used to measure motor RPM of a quad rotor vehicle is Sharp GP1A53HRJ00F ( http://au.element14.com/sharp/gp1a53hrj00f/photointerrupter/dp/9708006) and I highly recommend it. HTH -Igor
|
|
|
|
|
Logged
|
|
|
|
|
Cumming, Ga
Offline
Edison Member
Karma: 12
Posts: 1389
Ultimate DIY: Arduino
|
 |
« Reply #7 on: January 26, 2011, 09:46:09 pm » |
Examples of places to LOOK:
Old Ball Mice, VCR's, CDROM drives, Tape Drives, floppy drives (especially if you can find a real old 5 1/4 "real" floppy drive.
|
|
|
|
|
Logged
|
|
|
|
|
Washington
Offline
God Member
Karma: 20
Posts: 717
Firefox & Arduino rocks
|
 |
« Reply #8 on: January 27, 2011, 12:38:13 am » |
By the way, where is a good place to dig for a phototransistor?  Digikey, Mouser, Allied electronics, possibly radio shack, maybe an old VCR.
|
|
|
|
|
Logged
|
Avoid throwing electronics out as you or someone else might need them for parts or use. Solid state rectifiers are the only REAL rectifiers. Resistors for LEDS!
|
|
|
|
Brisbane, Australia
Offline
Newbie
Karma: 3
Posts: 35
B.E.E. / B.Inf.Tech.
|
 |
« Reply #9 on: January 27, 2011, 01:07:24 am » |
As pwillard noted, the old school computer mice with a ball have nice encoder wheels and IR diodes and photo transistors.
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 278
Posts: 25577
Solder is electric glue
|
 |
« Reply #10 on: January 27, 2011, 11:10:42 am » |
Note if you go down the mouse route some of the photo sensors will only work if the light goes through the wheel because they are twin sensors and only give outputs on true quadrature light signals. I thought they were just simple sensors too but there is a vintage that are not.
|
|
|
|
|
Logged
|
|
|
|
|
Glasgow, scotland
Offline
Newbie
Karma: 4
Posts: 42
Arduino rocks
|
 |
« Reply #11 on: January 27, 2011, 12:00:19 pm » |
WELL i couldn't find a ball mouse, so i took apart an optical one for the mousewheel. But it had a mechanical encoder, too noisy for this application. So I went and bought (  ) a phototransistor from maplin and i can confirm it works great  **edit** my code though seems to be a problem, it can go up to 8500 rpm or so then starts counting from zero again. it still counts the revolutions and the period correctly, but when it divides them for some reason something is going wrong .. . . . help!
|
|
|
|
« Last Edit: January 27, 2011, 02:59:10 pm by prawnstar »
|
Logged
|
|
|
|
|
Washington
Offline
God Member
Karma: 20
Posts: 717
Firefox & Arduino rocks
|
 |
« Reply #12 on: January 27, 2011, 04:05:29 pm » |
The frequency is simply too much for the poor little Arduino to handle. You may have to put it through an external divider to "pre-scale" it. That could be as simple as one or two flip-flops for 2x or 4x division.
100hz is too fast for the Arduino? *shrug* 
|
|
|
|
|
Logged
|
Avoid throwing electronics out as you or someone else might need them for parts or use. Solid state rectifiers are the only REAL rectifiers. Resistors for LEDS!
|
|
|
|
Glasgow, scotland
Offline
Newbie
Karma: 4
Posts: 42
Arduino rocks
|
 |
« Reply #13 on: January 27, 2011, 04:43:05 pm » |
okay i have it working, basicly just didvide counts first then scale to RPM, instead of all in 1 step . .. whats better, to count the number of rotations in a set amount of time, or to find the time difference between a certain number of rotations? i b puzzl'd 
|
|
|
|
|
Logged
|
|
|
|
|
The Udaho Border
Offline
Newbie
Karma: 1
Posts: 18
Arduino rocks
|
 |
« Reply #14 on: January 27, 2011, 06:04:10 pm » |
100hz is too fast for the Arduino? *shrug*  No it isn't but I've found I have to be clever when polling anything at the same time as I'm reading and writing to lcd's. I suspect the same might be true for serial devices. To keep loop execution speed below 5ms on this latest project, I had to limit the reading and writing to one command per loop. switch (lcd_command % 11) // display updated one command at a time { // to decrease loop execution time case 0: lcd.setCursor(0, 0); // column 0 line 0 break; case 1: if (run_state == RUN_RUNNING) lcd.print("Running "); else lcd.print("Stopping "); break; case 2: lcd.setCursor(10, 0); // column 9 line 0 break; case 3: lcd.print(cycle_count); break; case 4: lcd.print("c "); break; case 5: lcd.setCursor(0, 1); // column 0 line 1 break; case 6: lcd.print(lcd_tenths / 10); break; case 7: lcd.print("s "); break; case 8: lcd.setCursor(10, 1); // column 9 line 1 break; case 9: lcd.print(sense_count); break; case 10: lcd.print("p "); break; } lcd_command++; // increment for next iteration
|
|
|
|
|
Logged
|
|
|
|
|
|