Shop OBEX P1 Docs P2 Docs Learn Events
Timing solenoids to 0.1ms increments--How?? — Parallax Forums

Timing solenoids to 0.1ms increments--How??

LloydsLloyds Posts: 75
edited 2008-07-08 18:43 in BASIC Stamp
Hi,
I am a total newbie to BASIC stamp but would love to learn, especially if it will work for my project.
I need to control two solenoids with sub-millisecond repeatability. Repeatability is important; actual times are not.
I believe I can use a ULN2003 to drive the two solenoids. They are 12VDC, 5watt.
The timing sequence will be approximately as follows, but will fine tuned by trial and error to compensate for solenoid lag.

1) Start with solenoid 1 and 2 de-energized.
2) Energize solenoid 1 for 4.7ms (Possibly use the PULSOUT command??)
3) After solenoid 1 has been energized for 3.3ms, energize solenoid 2 for 8.5ms.

How to achieve the 3.3ms delay between energizing solenoid 1 and solenoid 2 has me stumped. It seems like the PAUSE command should work , but its resolution only goes down to 1ms, and I need a tenth of a millisecond resolution.
Can any of the stamp models achieve this?
Any help will be greatly appreciated!
Thanks,
Lloyd

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-07-07 02:32
    Hi Lloyd, I don't know if you can achieve the accuracy or repeatability you require but each PBasic line of code takes a certain amount of time, some instructions take less time than others. For values of time less than 1mS experiment using different (dummy) instructions or multiples of instructions and see if it falls within your limits.

    Jeff T
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-07 02:40
    The PULSOUT statement can provide the control for the energizing of the two solenoids to a resolution of 2us. The problem is timing the pause between the two. There are no delay statements that have the necessary resolution. There's a discussion of statement execution time here (www.emesystems.com) in the section "app-notes". Set up some kind of loop, then repeat that 10000 times with a DEBUG statement at the beginning and end. If you can add statements or operations to the inner loop to get a time of 33 seconds between the DEBUG statement, then you have an inner loop time of 3.3ms. Add a PULSOUT before and after this inner loop and there you have it. Keep in mind that the PULSOUT takes a little time to finish after the pulse is over and a little time to set up before the next pulse starts and adjust your delay loop a little to compensate.
  • LloydsLloyds Posts: 75
    edited 2008-07-07 02:41
    Jeff,
    Ahhhh, so to get a 3.3ms pause I could try PAUSE 3, and then run a little dummy loop for a certain number of times to delay things for the additional 0.3ms. Sounds like it should work.
    Thanks!
    Lloyd
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-07 02:45
    You could do it that way, but, if you're going to add the code for a 0.3ms delay, you might as well repeat it 10 times more to get a 3.3ms delay. You'd also average out any irregularities or miscalibration.
  • LloydsLloyds Posts: 75
    edited 2008-07-07 02:59
    Mike,
    Yes, i see what you mean. And I really like your way of looping it by a factor of 10,000 to get an easily measurable time indicator. Now that you mention it, I remember having to do a similar thing several years ago using BASIC to write to a purchased blackbox stepper motor controller. The PC and blackbox communicated fine on our old Windows 98 machines, but was too fast on the new Windows 2000 machines. Adding loops in a few strategic places made it work.

    So it sounds like the Basic Stamp will do what i need. Time for me to get down to business!
    Thanks again,
    Lloyd
  • BobLowryBobLowry Posts: 12
    edited 2008-07-08 04:53
    > Lloyds wrote:
    > 1) Start with solenoid 1 and 2 de-energized.
    > 2) Energize solenoid 1 for 4.7ms (Possibly use the PULSOUT command??)
    > 3) After solenoid 1 has been energized for 3.3ms, energize solenoid 2 for 8.5ms.

    Lloyds, I don't think PULSOUT will work for this application. As far as I know(but I could be wrong), when a PULSOUT command is run, no further commands will operate until that PULSOUT has finished running. So if your first PULSOUT is 4.7ms, the second PULSOUT command will not begin until at least 4.7ms after the first.

    One way that may work is to use the HIGH and LOW commands instead, which don't suffer from this problem. HIGH activates a solenoid, LOW deactivates it(at least generally.)

    It might look something like this (in pseudocode):

    HIGH solenoid1
    PAUSE 3.3ms
    HIGH solenoid2
    PAUSE 1.4ms
    LOW solenoid1
    PAUSE 7.1ms
    LOW solenoid2


    Since PAUSE may not have the required resolution you can substitute in something that does, like the technique Mike suggested. Another method to pause with better resolution could be to send a PULSOUT to an unused pin.

    One more thing to consider, the 5watt solenoid may draw considerably more power for a very brief period when it is first energized, as an "inrush current." Something to watch out for; I'm not sure whether the ULN2003 would like this, but it could be fine.

    Post Edited (BobLowry) : 7/8/2008 5:04:30 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-08 04:57
    BobLowry,
    Thanks for noticing. I completely missed the overlap of the solenoids. Your solution is perfect.
    The only thing to watch out for is the execution time of the loops used for the pauses. The
    HIGH and LOW statements take some time to execute and that has to be worked into the times.
  • LloydsLloyds Posts: 75
    edited 2008-07-08 12:33
    Bob Lowry and and Mike Green,·
    Bob, Yes, I follow what you are saying regarding the non-overlap in the execution of the PULSOUT command.· That will give me another approach to try when my parts arrive.··I can also see that with·the short·durations involved, it would have been difficult to diagnose where the problem really was and therefore, which of the various durations to adjust.· But using Mike's method of putting a 10,000 times mutiplier in appropriate places, I should be able to physically time the sequence of events until I get the functionality of the project where I want it.· At least I now·have some caution areas to watch out for.

    Regarding the suitability of the ULN2003, a friend·has suggested this L295 solenoid driver.
    http://www.datasheetcatalog.org/datasheet/SGSThomsonMicroelectronics/mXrzqut.pdf
    ·It looks more robust and·can still control·both solenoids.· I'm thinking it would interface similar to the way the ULN2003 would?·
    Or is it possible to parallel the pins in the ULN2003?· As a beginner, I'd like to take the most trouble free approach.

    Thanks for all the help!
    Lloyd
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-08 13:44
    Read the datasheet for the ULN2003. It talks about parallelling outputs.
  • LloydsLloyds Posts: 75
    edited 2008-07-08 14:31
    Mike,
    Will Do!
    Lloyd
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-07-08 14:36
    Geez, guy, what is the activation time for a solenoid anyway? I suspect any 'contacts' it might have would 'bounce' for a few milliseconds. And even then, the coil has to build up its magnetic field, it has to "pull-in" the solenoid core -- sub milli-second timing seems kind of unrealistic when the physics of motion might be the limiting factor.

    That's just a thought.
  • LloydsLloyds Posts: 75
    edited 2008-07-08 16:45
    Allan,
    No, I'm with you on that and have been experimenting with mechanically operated micro switches to control the electrically operated air solenoids see if the mechanical part of the system is even capable of a quick cycle like I'm after.· I think it is.

    Basically, I've got a light weight (6/6 nylon piston and rod), short stroke, double acting air cyclinder that directly drives a "plunger".· The ultimate goal is to have precise control of the "plunger" "open time".

    The two solenoids I am trying to drive/control are Mac brand air solenoids that will·power the air cylinder, one to open it, the other to shut it.· The solenoids·are rated at 4ms to open, and 8ms to close, which by themselves, are too slow·for my application.· But by·having the 2 solenoids work independently of each other, and against each other, and control·both directions of the air cylinder, I believe I will be able to contol the open time of the "plunger" to the milli second level.· ·It will be like variable valve timing on an engine where the second·solenoid starts to shut the valve before the first solenoid even has the valve fully open.· Like an air operated Desmodromic valve arrangement.· Kind of, anyway.

    The odd timing numbers that I have in my initial post are based on calculations, partially backed up by empirical data.· When all is said and done, I won't really to be able to tell if the plunger is open for 3.3ms or for 4.3ms, but through the functioning of the system, I should be able to tell how precisely I am varying the plunger open time.· I've got the mecahnical stuff pretty well under control, but the electronics is new to me.

    I definitely appreciate all the help and comments, including pointing out potential problems.
    Lloyd
  • Larry~Larry~ Posts: 242
    edited 2008-07-08 17:16
    Im having a little trouble with this also, you have one cylinder and two valves one on each end?

    and your thinking that by opening the second it will make the first shut down faster. where does the air go from the first solenoid once shut down ( is it a three way valve )

    you might want to look into 4 way valves one valve·does the job
  • BobLowryBobLowry Posts: 12
    edited 2008-07-08 18:28
    I've successfully operated small normally-closed solenoid air valves with ~1ms on pulses. Not sure how clean or full the valve opening/closing action was though.
    12VDC Solenoid Valve

    Lloyds, if you do have trouble operating the solenoids with these short pulses you might try increasing the voltage. Of course, if you go over the rated voltage there are no guarantees that they would continue to work correctly or reliably, so be very careful. But if you kept the solenoid on-time short enough(both average and peak), you may not have any problems. You could also try experimenting with PWMing the solenoids.

    Post Edited (BobLowry) : 7/8/2008 6:38:41 PM GMT
  • LloydsLloyds Posts: 75
    edited 2008-07-08 18:43
    L-G,
    The 4 way air solenoid could be a nice clean approach, but I haven't been able to find·one that will·shuttle fast enough in the air volume and pressure·I am working with.
    The two solenoids I am using are 3 ways, but the trick··is that I have "quick exhaust valves" hooked up between the solenoids and·the·ports on the cylinder.· (OK, its not really a trick, someone told me about QEVs and I am eternally thankful!· They work great!)· I'll see if I can come up with a decent sketch.

    This provides a little better explanation about QEVs than I can.· Click on the pdf of QEVs for a flow schematic:
    http://www.mead-usa.com/products/detail.aspx?id=46&type=1

    The QEV allows the exhaust to dump directly to atmosphere once the pressure in the cylinder becomes higher than the residual pressure in the supply line.· It works a little like a check valve and is configured so that the exhaust doesn't have to be routed back through the solenoid valve. With a QEV, you can actually use a simple 2 way air solenoid valve·at each end of the cylinder and still get really fast reversing speeds.· Yes, there is that transition period where the two sides of the piston are fighting each other, but once the cracking pressure in the QEV is reached,·the reversal·is instantaneous.

    Still, whether·I will be succesfull in implementing the electronic controls has yet to be seen.· But what is life with a good challenge every now and then!
    Regards,
    Lloyd


    ·
Sign In or Register to comment.