Shop OBEX P1 Docs P2 Docs Learn Events
Drive X and Y stepper motor with propeller Demo Board — Parallax Forums

Drive X and Y stepper motor with propeller Demo Board

NikosGNikosG Posts: 705
edited 2011-02-26 13:12 in Propeller 1
Hello all,


This is my first attempt to drive two stepper motors using the propeller microcontroller. This activity is a part of a bigger project which is in the pipeline and I would like to make clear in advance that this is an experimental approach and it is very possible to need various improvements.
Although I have some experience driving stepper motors with custom and home-made electronics I’m a new propeller user and it is very possible to discover that I have done some mistakes. So I’m waiting for your advice and your suggestion if you notice something wrong or something that I need to improve.
Here is the hardware I have used:
1) The motors I have used are two unipolar stepper motor very similar to 4-Phase /12-Volt Unipolar Stepper Motor (#27964) from parallax store. I also found two gear boxes for these motors which will help me a lot to finish my future project.
2) I also use a ULN2803A Darlington Array.
The reason I used the ULN2803A chip instead of the ULN2003 chip is because the ULN2803A chip is able to drive simultaneously two stepper motors. This choice is also suggested by the stepper motor’s manual.
3) The propeller board I have used is the Propeller Demo Board.
This board is ideal for my application as it is very friendly for a new propeller user like me because it provides a lot of facilities such as the breadboard, TV & VGA out and the two PS/2 connectors for mouse and keyboard I/O essential for the data input.
4) I also used a battery 9,6V to power the two stepper motors and a 7, 5 Volt 0, 7 Amp Power Supply to power my Propeller Demo Board.
Here is a photo of the hardware which is described above:
attachment.php?attachmentid=78627&d=1298488361
The schematic I have used is the following:
attachment.php?attachmentid=78626&d=1298488358
The code I have used is a very simple code that is based on the following idea:
To rotate a 4-Phase Unipolar Stepper Motor whose its phases 1,2,3,4 are connected to the P0,P1,P2,P3 Pins of the propeller microcontroller is exactly the same as you try to blink four LED’s light with sequence which are connected to the P0,P1,P2,P3 Pins.
So here is the code to rotate a unipolar stepper motor:
CON
                  
  _CLKMODE      = XTAL1 + PLL16X                         
  _XINFREQ      = 5_000_000

waitPeriod = 2_000_000 ' 1/2 sec switch cycle
 ph1Pin_x = 0    ' phase 1 control pin  for X motor
 ph2Pin_x = 1    ' phase 2 control pin  for X motor 
 ph3Pin_x = 2    ' phase 3 control pin  for X motor 
 ph4Pin_x = 3    ' phase 4 control pin  for X motor

   
 smv = 5   ' stepper motor velocity  1= min, 10 =max
 
OBJ
   pst: "Parallax Serial Terminal"

PUB Main
  if(ina[31])
   pst.Start(57600)
dira[0..3]~~
outa[0..3]~
  
  repeat
    ROTATE_X_MOTOR
   
PRI ROTATE_X_MOTOR
 if(ina[31])
  pst.str( string("X---1",13)) 
 !outa[ph1Pin_x]                                                    
  waitCnt(waitPeriod/smv +cnt)
  !outa[ph1Pin_x]

  if(ina[31])
   pst.str( string("X---2",13))
 !outa[ph2Pin_x]
 waitCnt(waitPeriod/smv+cnt)
 !outa[ph2Pin_x]

 if(ina[31])
   pst.str( string("X---3",13))
 !outa[ph3Pin_x]
 waitCnt(waitPeriod/smv+cnt)
 !outa[ph3Pin_x]

 if(ina[31])
   pst.str( string("X---4",13))
 !outa[ph4Pin_x]
 waitCnt(waitPeriod/smv+cnt)
 !outa[ph4Pin_x] 

Trying to drive simultaneously and a second stepper motor (the Y-motor) I have used the multitasking ability that offers the propeller microcontroller.
The code for this task is the following:
CON
_clkmode = xtal1 + pll2x
 _xinfreq = 5_000_000 'Note Clock Speed for your setup!!

 waitPeriod = 2_000_000 ' 1/2 sec switch cycle
 ph1Pin_x = 0    ' phase 1 control pin  for X motor
 ph2Pin_x = 1    ' phase 2 control pin  for X motor 
 ph3Pin_x = 2    ' phase 3 control pin  for X motor 
 ph4Pin_x = 3    ' phase 4 control pin  for X motor

 ph1Pin_y = 4    ' phase 1 control pin  for y motor
 ph2Pin_y = 5    ' phase 2 control pin  for y motor 
 ph3Pin_y = 6    ' phase 3 control pin  for y motor 
 ph4Pin_y = 7    ' phase 4 control pin  for  y motor
smvX = 8' 10 'steper motor velocity 1= min
 smvY = 8' 10 'steper motor velocity 1= min 
VAR
     LONG STACK[30] 
OBJ
   pst: "Parallax Serial Terminal"

PUB Main
  pst.Start(115200)
  dira[0..7]~~
  outa[0..7]~
  COGNEW (ROTATE_Y_MOTOR,@STACK) 
  repeat
    ROTATE_X_MOTOR
    ROTATE_Y_MOTOR
  
  
PUB ROTATE_X_MOTOR

!outa[ph1Pin_x]                                                    
  waitCnt(waitPeriod/smvX +cnt)
  !outa[ph1Pin_x]
  
 
 !outa[ph2Pin_x]
 waitCnt(waitPeriod/smvX+cnt)
 !outa[ph2Pin_x]
 
 !outa[ph3Pin_x]
 waitCnt(waitPeriod/smvX+cnt)
 !outa[ph3Pin_x]
 
!outa[ph4Pin_x]
 waitCnt(waitPeriod/smvX+cnt)
 !outa[ph4Pin_x]

PUB ROTATE_Y_MOTOR
!outa[ph1Pin_y]                                                    
 
 waitCnt(waitPeriod/smvY +cnt)
  !outa[ph1Pin_y]
  
!outa[ph2Pin_y]
 waitCnt(waitPeriod/smvY+cnt)
 !outa[ph2Pin_y]
 
!outa[ph3Pin_y]
 waitCnt(waitPeriod/smvY+cnt)
 !outa[ph3Pin_y]
 
  !outa[ph4Pin_y]
 waitCnt(waitPeriod/smvY+cnt)
 !outa[ph4Pin_y]
The following video displays the stepper motors running the codes described above.

And here is something that I can't explain and I need your help.
As you can see in the previous video when the Propeller demo board is connected with the PC the stepper motor rotates continuously. When I disconnect the Propeller demo board from the PC the stepper motor rotates for some seconds then stops for a little while and then rotates again and repeat the same procedure.
I can’t explain yet why this it happens.

If anyone can help is welcome!
Thank you,
Nikos Giannakopoulos
753 x 1208 - 148K
670 x 584 - 72K

Comments

  • RaymanRayman Posts: 14,886
    edited 2011-02-23 11:46
    Good job. Nice documentation.

    FWIW: Here's my old code for full, half, quarter, and micro stepping the Parallax unipoloar steppers in a similar setup:
    http://www.rayslogic.com/propeller/Programming/Stepper/Stepper1.zip

    But, I realize now that microstepping should actually apply a sinusoidally varying current in steps and not a linearly varying current like I did...
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-02-23 11:59
    You seem to have a conflict: You're launching ROTATE_Y_MOTOR into its own cog and then calling that method in your Main loop. Since the outputs of the Y motor are going to be the same for the independent cog and the call from the Main loop your outputs to that motor may not be what you want since the individual pins from the two cogs will be OR'd out to the IO pins.
  • KyeKye Posts: 2,200
    edited 2011-02-23 12:12
    Disable any serial driver I/O code you have using pins 31 and 30. It sounds like you are suffering from the FTDI reset bug issue. (Basically, the propeller chip gets reset by the USB to serial converter in an infinite loop over and over again when the FTDI chip is not power by a computer).
  • NikosGNikosG Posts: 705
    edited 2011-02-23 12:20
    Thank you for your respond!
    @ Rayman I downloaded your code and I'll try it later. Thank you!
    @ Jon Thank you for your correction!
    Do you see something wrong in the first code which manipulate only one stepper?
    When I use this code (for the one stepper) and disconnect the Propeller demo board from the PC the stepper motor rotates for some seconds then stops for a little while and then rotates again and repeat the same procedure. Why? could you explain this please?
  • NikosGNikosG Posts: 705
    edited 2011-02-23 12:29
    Kye Thank you!!,
    But you have scared me! what exactly is this FTDI reset??? Do I have something like virus in my propeller?
    Kye wrote: »
    Disable any serial driver I/O code you have using pins 31 and 30. It sounds like you are suffering from the FTDI reset bug issue. (Basically, the propeller chip gets reset by the USB to serial converter in an infinite loop over and over again when the FTDI chip is not power by a computer).
  • RaymanRayman Posts: 14,886
    edited 2011-02-23 12:42
    Kye may be right... You are using Fullduplexserial to talk through the FTDI chip. But, this puts power on P30.
    If the USB cable is removed, this powers up the FTDI chip which then immediatly resets the Prop...
  • NikosGNikosG Posts: 705
    edited 2011-02-23 13:05
    And how can I fix it?
    I think that I'will have a lot of question at the "Propeller Meetup Group" on Fri, Feb 25, 2011 !!!!!!
    Anyway! Thank you all of you!!!
    You are fantasic people!!!
    Rayman wrote: »
    Kye may be right... You are using Fullduplexserial to talk through the FTDI chip. But, this puts power on P31.
    If the USB cable is removed, this powers up the FTDI chip which then immediatly resets the Prop...
  • RaymanRayman Posts: 14,886
    edited 2011-02-23 13:27
    There are lots of fixes out there... Just do a forum search...
    I think the simplest software fix is to test P31 for logic 1 before starting the FullDuplexSerial driver.
    If the USB cable is connected, it should be asserting power on P31 otherwise it seems to float low...
  • KyeKye Posts: 2,200
    edited 2011-02-23 13:33
    Comment out the start call... or do an if statment on the start call...
    if(ina[31])
      startDriver
    

    ... etc.
  • NikosGNikosG Posts: 705
    edited 2011-02-24 17:59
    Hi Kye,

    I should create a new programe?
    How can I start a driver? The "startDriver" you mentioned above is a command?
    Could you give me more details please?
  • NikosGNikosG Posts: 705
    edited 2011-02-25 12:40
    Kye,
    the converter you mentioned above is the Parallax USB to Serial (RS-232) Adapter or another product?
    Kye wrote: »
    Disable any serial driver I/O code you have using pins 31 and 30. It sounds like you are suffering from the FTDI reset bug issue. (Basically, the propeller chip gets reset by the USB to serial converter in an infinite loop over and over again when the FTDI chip is not power by a computer).
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-02-25 23:11
    Hi NikosG,

    the propeller-demo-board has already an FTDI-Chip on board.
    Kye meant this onboard FTDI-Chip.

    your codelines like
    [FONT=monospace]
      [/FONT]pst.str( string("X---1",13)) 
    

    sends serial data towards the onboard-FTDI-chip. The onboard-FTDI-chip converts the serial datastream coming from the propeller into a USB-datastream going to your PC.

    if you try to send serial data when the USB-cable is DISconnected this will cause a reset of the propeller-board.
    After a reset the program is loaded new from the EEPROM-chip (which needs some seconds) and then the program starts running again.

    As a quick check if this is the case comment out EVERYTHNING that has to do with "PST"
    If the steppermotors then behave normal you now it is the ONBOARD FTDI-chip

    Anyway I recommend a dual way of learning:
    reading the manual about the propeller-chip and as soon as a question arises post this question in the forum
    this way you will climb up the learning-curve and get a deeper understanding of how it works.

    start playing with adding your own debug-output.
    If you know how to add debug-output this output will make it MUCH easier to understand what your code actually does

    best regards

    Stefan
  • NikosGNikosG Posts: 705
    edited 2011-02-26 13:12
    Hi Stefan,
    Comment out some code will be a temporary solution and thank you for this!
    But the solution suggested above by Kye and Ryman I think is more proper and my first question still remains. I’m saying this because I’ll need "PST" commands to complete my project and I can’t comment out them permanently for ever.
    However thank you very much for your solution and for your kind suggestion.
    I know some times I’m trying to solve problems beyond my level but all these amazing Propeller abilities have really seduced me!!!!
    I ask your understanding if some of my questions sounds inaccurate and absurd.

    Nikos.
Sign In or Register to comment.