Go Down

Topic: 90,000 rpm motor control (Read 2229 times) previous topic - next topic

mnsman

Feb 02, 2012, 11:10 pm Last Edit: Feb 06, 2012, 03:17 am by mnsman Reason: 1
Hi All,

I have built a pulsed dc motor that currently runs up to 90,000 rpm.  An Arduino Mega2560 controlling it.  Immediately, I must confess that I'm not a programmer but I can muttle my way through.  The software that I'm using and have slightly modified is open source [edit: actually software is GPLv3 Free Software as pointed out by justjed in a later post].  In fact the whole project is open source.  I think that the code could be improved for speed if a real programmer took this on.  Currently there is about a 200us delay between trigger input to processor output.

If possible I would like to add a lcd with keypad in order to see rpm and change parameters such as pulse delay and duration.  I'm looking at this one: http://www.ebay.com/itm/SainSmart-1602-LCD-Keypad-Shield-Arduino-Duemilanove-UNO-MEGA-1280-2560-R3-/270887248179?pt=LH_DefaultDomain_0&hash=item3f12236133 .  

My question is will the Arduino handle the additional overhead?  I'm not as worried about the keypad input as the display overhead.  I already have a ps2 keyboard attached and it works ok but of course if a display/keypad will work it would be a bonus to remove ps2 keyboard.  I don't need to update the display (rpm/menu) frequently (every 1 second?).  The rpm reading is not critical to operation but would be a nice built in feature.  The code is available for anyone interested.

Thanks for any help.
Jim

Constantin

#1
Feb 02, 2012, 11:22 pm Last Edit: Feb 02, 2012, 11:24 pm by Constantin Reason: 1
Consider a LCD that sits directly  on the serial port. Then, messages are only a a Serial.print command away. With Arduino 1.0, the serial port is no longer blocking the CPU the way it used to. See Mark Sprouls shield description for what I mean. A similar shield can be bought at Unified Microsystems for $35. But I would prefer Marks shield because it's open source... see if he can sell you a PCB and you then populate it with the components of your choice.

I can't tell what pins the SainShield uses... it's not in the shieldslist either. HTH

justjed

That e-bay thing looks rather like the Phi-2 Interactive Shield Kit. Forum member liudr designed that, and builds them. So if this sort of thing matters to you, you can buy from him, or through a vendor, and support some people who contribute to this community. Plus, you'll get the library, and support. There's a demo here.
... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

mnsman

#3
Feb 03, 2012, 02:29 pm Last Edit: Feb 03, 2012, 02:40 pm by mnsman Reason: 1
Thanks for the replies.  

Constantin - From your response, presumably the serial lcd is both easier and faster than a parallel lcd with Arduino 1.0.  Given that, the only problem I have with the serial lcd option is that for some reason my code won't compile with Arduino 1.0.  It compiles fine with 0023.  I haven't addressed that issue yet.  Ultimately I will have to revisit that problem so I might as well deal with it sooner rather than later.  Can't remember the errors I was getting off the top of my head.  If I can't figure it out I'll start another thread.  

justjed - As far as buying from a forum member... that's a good idea.  It makes sense to support the support.

I'm not going to make a decision quite yet- not in that big of a hurry.  I'll kick back and wait to see if there is any other input on the matter.  I'd like to make the right purchase the first time.  In the mean time I have plenty to do with the project.

Constantin

Agreed.

One good reason to get the code to compile under Arduino 1.0 is that the serial port is non-blocking. Thus, your control system can presumably work happily away while the buffer is holding any keyboard inputs or the serial port is displaying outputs. I'm thinking of buying a shield like this just for debugging purposes - a inexpensive way to monitor multiple Arduinos communicating with each other.

liudr

Thanks for mentioning my shield justjed!

The OP contacted me via PM. If you want to reduce your Arduino load, here is a way: use a phi-panel serial LCD keypad or backpack (plug in a matrix keypad) on one of the MEGA's hardware serial ports. Then use the phi-panel's on board functions to render menus etc. Your arduino just needs to send the menu/list to the serial LCD and the choice will come back via serial, all the keypad handling and LCD scrolling through the menu is handled by the serial LCD on board processor.

Someone used my panel and made an HVAC project:

http://www.youtube.com/watch?v=mBzwwARAa_U&feature=player_embedded

If your project is demanding, you can have a timer to only sense the keypad 20 times a second. Since the keypad talks to serial, its results are buffered against lost, so are info intended to display on the LCD buffered.

Timer code:

Code: [Select]
int keypad_last_read;
int update_time=50; // Update every 50 ms or 20 times a second
void setup()
{
  keypad_last_read=millis();
}

void loop()
{
  //do your stuff
  if (millis()-keypad_last_read>update_time)
  {
    keypad_last_read=millis();
    if (Serial2.available()) key=Serial2.read());
    //Do something about the key press
  }
}

You can do the same for displaying to serial LCD, which I think is non-blocking with arduino 1.0 so you're free to do your stuff once you call serial.print().

Here are links to three models, a backpack version (use a matrix keypad $2.25 on ebay), a compact integrated panel, a full size panel:

http://www.inmojo.com/store/liudr-arduino-and-physics-gadgets/item/serial-lcd-back-pack---phi-panel/

http://www.inmojo.com/store/liudr-arduino-and-physics-gadgets/item/serial-16x2-lcd-keypad-panel---phi-panel/

http://www.inmojo.com/store/liudr-arduino-and-physics-gadgets/item/serial-20x4-lcd-keypad-panel---phi-panel/

Let me know if you have other questions.

mnsman

liudr - thanks for the quick and informative response.  Funny that it came full circle back to you.  As you know justjed pointed me in your direction but it didn't register that you were the same person I had independently found while researching serial v. parallel here on the forum.  Looks like I'll be making a purchase from you but I still have to look over your suggestions and determine which choice makes sense to me.

Thanks to all for the help.  Tonight I will once again try to get it to compile with Arduino 1.0.  When that is complete I will take the plunge.    :D

dc42

Either use a serial LCD and Arduino 1.0 so you have non-blocking write to the LCD, or run the motor control code in an ISR so that it can interrupt the LCD code. Without seeing the code, I can't say whether this second approach is practical or not.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

mnsman

#8
Feb 03, 2012, 09:08 pm Last Edit: Feb 06, 2012, 03:18 am by mnsman Reason: 1
dc42 - It does use an ISR.  

For those interested I have attached the code that I am using.   It is open source [edit: actually software is GPLv3 Free Software as pointed out by justjed in a later post] and I am not the author.  It seems to work well.  I have modified the code a little and have tinkered with making the delay adjustment automated according to rpm/period.  The attached sketch relies on manual control of pulse duration and delay via keyboard, potentiometer or fixed with the code.  I found it here:  http://alt-nrg.org/Muller.html

If anyone does look at it... Can you tell me why it doesn't compile with Arduino 1.0?
My other question is can this code be improved?  For example it uses digitalWrite commands.  Will replacing them with digitalWriteFast improve the performance?  Or other improvements.

dc42

If it uses an ISR to do the critical timing then you may be able to use a standard parallel LCD and the LiquidCrystal library.

To compile it under Arduino 1.0, at the very least you need to replace the line #include "WProgram.h" by #include "Arduino.h".
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

mnsman

dc42 - already tried replacing the #include "WProgram.h" with #include "Arduino.h".  The code I attached is in it's original form.  My working copy is at home.  If my memory serves me right I remember "thinking" the problem lies with one of the .h files included with the original sketch.  I could be wrong about that.  The project is not here where I am now.  I will recheck the arduino.h, then I will try compiling the original again and then my working copy tonight.  I read somewhere that someone needed both wprogram.h and arduino.h for their project to function with Arduino 1.0.  Is this possible?  Another thing to try tonight.  Worse thing that could happen is my computer explodes....   :smiley-eek:

Do believe I'm going to try the serial approach.  liudr's lcd's look good.  On-board micro-controller will help combined with your (dc42) suggestions- "Either use a serial LCD and Arduino 1.0 so you have non-blocking write to the LCD, or run the motor control code in an ISR".  Doing both ISR and hopefully soon non-blocking write.  I must also thank everyone else who have pretty much said the same about using serial.  I'm heading in the correct direction now.  Just need to get Arduino 1.0 to compile.

liudr

mnsman,

You've got a very well-written program to start with. Awesome! It's already sing ISR so you don't have to. After glancing through it, I thought the program handles everything in ISR and provides function calls you can use to set or read rpm, I think. You don't have to have serial LCD but getting MY serial LCD is just like getting a well-written program. You can focus on using it, but not how to use it. The panel essentially takes over these interface needs so you can focus on your project, not on how to make a menu :)

dc42


Just need to get Arduino 1.0 to compile.


Why don't you post the first few error messages it provides, together with the lines of code that those messages refer to?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

mnsman

#13
Feb 04, 2012, 11:57 pm Last Edit: Feb 06, 2012, 03:18 am by mnsman Reason: 1
liudr - can't take credit for the code as you probably read in my earlier post.  Hats off to the person who wrote it and made it open source [edit: actually software is GPLv3 Free Software as pointed out by justjed in a later post].  It's reassuring that you think it looks like good code.  My question still stands.  Can it be improved for speed?  I'm not sure how the Arduino community handles open source code.  In other words where should the code reside and how are improvements tracked etc?  This is nice code for people like me who want to control pulsed dc motors rather than let them run freely.  As far as I know the code has only been placed on the web site I put a link too.  BTW  I will be buying one of your lcd's very soon.  Thanks.

To all - I got Arduino 1.0 to compile.  I didn't do anything different that I know of.  The problem occurred when I first added the Arduino.  It must have been something stupid that I did because I didn't have a clue what I was doing.  There has been a big learning curve as everyone has experienced at some point.  I don't think that you've heard the last from me because there are still many features beyond the tach/menu that I want to add and after all I am new at this.  For instance:  Code automatic delay adjustment for rpm, Code skip pulse function; Code multiple pulses (per revolution) function; Code load control function.  These would be nice features to add to an open source motor controller.  I also plan on adding an H-bridge and an additional drive coil to the motor which will require additional coding.  After it's all said and done I hope the Arduino will handle what I'm throwing at it.

I'm well on my way to coding the automatic delay but it's not perfected yet.  That is what I'm currently working on.  At least now I can use Arduino 1.0 and add a serial lcd.

Bottom line on the compile problem... just make sure the code attached above has the WProgram.h removed and Arduino.h added in it's place as dc42 already mentioned.

For anyone really interested in the project I have a youtube channel mnsman1 http://www.youtube.com/user/mnsman1.  My videos aren't the best productions but at the very least I give details how to reproduce the motor and I will eventually add videos about the addition of the Arduino and the code.  As I said previously the entire project is open source.

Thanks again everyone for the input.

justjed


Can it be improved for speed?  I'm not sure how the Arduino community handles open source code.  In other words where should the code reside and how are improvements tracked etc?


The typical method would be for the person who makes changes to deliver a patch to the maintainer. If you would supply a link to the location of the original, I can look at the license and perhaps advise further.
... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

Go Up