Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Controlling Stepper Motor Serially with VB

  • 15-03-2007 5:09pm
    #1
    Closed Accounts Posts: 2,922 ✭✭✭


    Hey, not really sure if this is the right forum, but here's a major problem I'm having with my thesis.

    I have a stepper motor, and driver chip which are both working perfectly. A VB program came with the chip, but doesn't allow me to do what I need to do. According to the chip manufacturer the easiest way to do this is through VB, but I'm hopeless at programming, and my course (Mechanical Engineering) is in no way related to all this electronic tomfoolery ;)


    The information I have to work with is here in this pdf
    .

    Any help would be great!


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    I suppose it would be the right forum. What exactly are you trying to get the chip to do?


  • Closed Accounts Posts: 2,922 ✭✭✭Dave


    What I'm basically trying to do is move the chip clockwise 8 degrees, dwell there for a set time and then go anti clockwise to -8 degrees, all this done repeatedly.


  • Registered Users, Registered Users 2 Posts: 2,300 ✭✭✭PixelTrawler


    I'm nearly sure i saw a tutorial on this on www.thecodeproject.com - google it.

    I'm pretty sure its .net though, not VB but it might give you some ideas.


  • Closed Accounts Posts: 2,922 ✭✭✭Dave


    Hmmm what's the difference between .net and vb. I'm a complete novice.


  • Registered Users, Registered Users 2 Posts: 1,393 ✭✭✭Inspector Gadget


    Hmm... this brings me back :)

    Basically, the example junk they gave you is in old-school (pre .NET) VB, which would mean VB5 or VB6, I guess. VB4 should probably work as well, but anything older than that is stretching things somewhat.

    You're going to have to do a little programming any way you slice it, but this actually requires very little code to get going. I suggest that if you can get a copy of "classic" VB (as mentioned in the examples), then it's probably one the easiest way to talk to the serial port of a PC - there's a control (MSComm - sound familiar? - icon looks like a yellow telephone, if I remember correctly) that does all the donkey work. Google for "MSComm example" and you'll find some useful stuff.

    Seeing as it's a stepper motor, the exact angle you'll get it to turn through isn't dictated in degrees, it's dictated in whole steps - for example, if you've got a 200-step motor, then each step is 1.8 degrees, four steps is 7.2 degrees, whereas five steps is 9 degrees, and that's as close as you get directly. Another option is to find an integer multiple of both your desired angle and the number of degrees per step, and to turn the motor that further but use a suitable reduction gear to get the right angle - for the 200 step/1.8 degrees per step example, 72 degrees is exactly 9 times your desired angle, and exactly 40 steps, so if you build a reduction gear to bring that rotation down 9:1 and get the motor to turn through 40 steps, you'll get eight degrees at the far end of your gear train (excuse the poor grasp of the terminology, my background is electronics)

    The basic sequence of events in your program is this:
    1) Open connection between PC and controller (see your MSComm examples)
    2) Issue command to controller to turn clockwise.
    3) Wait a bit (there's a "Timer" control in VB that you could perhaps use here)
    4) Issue command to controller to turn anticlockwise
    5) Wait again (if required)
    6) Go to step 2 and repeat

    Hope this helps,
    Gadget


  • Advertisement
  • Closed Accounts Posts: 2,922 ✭✭✭Dave


    Wow, I'd have never figured that out by myself! Seriously, thanks! I'm still not really sure how to send that info to the chip though! As I said I'm a complete novice!


  • Closed Accounts Posts: 2,922 ✭✭✭Dave


    Ok, here's a complete update so.

    Did everything you said. Got the MSCOMM thing in VB to open. Checked the chip with hyperterminal, which worked perfectly, (nearly came in my pants when I saw the thing move with hyperterminal :D ) Now I just don't know how to get the thing to work with VB and MSCOMM, as in do I just type in the code and compile it or what?!. It's VB 5.0 Pro. This is my final problem I think.


  • Closed Accounts Posts: 2,922 ✭✭✭Dave


    I did it! Thanks alot guys, If I knew who ye were I'd buy ye a drink! Couldn't have done it without ye, seriously.


  • Registered Users, Registered Users 2 Posts: 1,393 ✭✭✭Inspector Gadget


    Happy to help :)

    Gadget


  • Closed Accounts Posts: 2,922 ✭✭✭Dave


    [edit] fixed last problem, now here's a new one!!

    and idea how to reset the timer after each statement?
    
    Private Sub RSTimer1_Timer()
    
    Dim i As Integer
    i = 2
    Dim a As Integer
    a = 2
    Do While i = i
    
        If i = a Then
        
            RSTimer1.Enabled = True
            MSComm1.Output = "{IE-1000}"
            RSTimer1.Enabled = False
            i = i + 1
    
        Else
    
            RSTimer1.Enabled = True
            MSComm1.Output = "{IE1000}"
            a = a + 1
            RSTimer1.Enabled = False
        
        End If
        
    
    Loop
    
    
    End Sub
    

    Sorry about the code :)


  • Advertisement
  • Closed Accounts Posts: 2,922 ✭✭✭Dave


    -


  • Registered Users, Registered Users 2 Posts: 1,393 ✭✭✭Inspector Gadget


    Hi Dave:

    I'd suggest that maybe you do some old-fashioned debugging at this point.
    Check to see that your looping is actually working, by sticking a line like:
    Debug.Print "Timer 1 code running"
    

    ...at the beginning of the RSTimer{n}_Timer() subroutines, to see if it works. (Obviously, change the number in the message depending on which timer you're looking at). The text in question should appear in the debug window of VB - if you don't see it, type Ctrl+G and it'll appear. Run your code in the VB environment, and if it's working, you should see the following in the Debug Window:
    Timer 1 code running
    Timer 2 code running
    Timer 1 code running
    Timer 2 code running
    

    ...and so on. By the way, you do intend for it to wait thirty seconds (30000ms) between changes, right? I'd suggest you use a smaller interval while testing - maybe two or three seconds instead? - as otherwise it'll get boring quick :D

    One last thing; You should drop in a call to DoEvents() after each time you output something to the serial port - this hands control back to Windows and allows it to do the back-end stuff (like actually sending the data out the serial port). It may not be strictly necessary on a fast computer, but probably no harm.

    Hope this helps,
    Gadget


  • Closed Accounts Posts: 2,922 ✭✭✭Dave


    The loop works fine, but it just keeps on moving anticlockwise then clockwise without any delay. I think I may have edited my post since you read it last.


Advertisement