Shop OBEX P1 Docs P2 Docs Learn Events
using multiple frequencies to control a stepper motor. - Page 3 — Parallax Forums

using multiple frequencies to control a stepper motor.

13»

Comments

  • It's saying that PWM_FREQ is not defined. Look at your declaration for PWM_FREQ in the CON section. It has two underscores instead of one.
  • bbrienbbrien Posts: 561
    edited 2020-12-17 21:58
    Fixed the double underscore , now I get error "expected ",". " on line for Step.Synth( SIDE_RATE) at closing ")". New program follows
  • In the OBJ Stepper.spin can I use a decimal in the scale.
  • Dave HeinDave Hein Posts: 6,347
    edited 2020-12-18 00:20
    No, but we can change the way the frequency is computed to make it more precise. I'll take a look at it.
  • I modified the telescope mount program so that it passes the frequency scaled by 10 to the stepper.set_speed routine. I defined the constant RA_RATE to set the base value for the RA speed. This should be set to the frequency needed to generate the sidereal speed. The value is currently set to 9_5, which corresponds to 9.5 Hz.

    The SCALE value in stepper.spin must be changed to a value of 4 so that it divides the parameter received in set_speed by 10 to get the right frequency.
  • bbrienbbrien Posts: 561
    edited 2020-12-21 19:43
    OK now it's working like a champ. I got it down to 8Hz and the orion mount is tracking about one minute slow in 30 minutes. The meade mount uses a larger gear on the RA axis which is good news. Thanks for all your help. Willl include picture
    2560 x 1920 - 907K
  • Hello from Thailand. I am working on the big scope using Dh 14 program and I ran into a snag here. When I use7 as the SIDE_RATE, I get a frequency of 7Hz but when I use 7_5 I do not get 7.5Hz like before. I wonder what is going on.

  • JonnyMacJonnyMac Posts: 8,973
    edited 2022-06-12 19:38

    If you use 7 for 7 Hz, you cannot use 7_5 (which is 75) for 7.5 Hz. The problem is easily fixed by changing the SCALE constant in the stepper object from 40 to 4, and then always setting the speed in 0.1Hz units, so 7_0 is 7.0 Hz and 7_5 is 7.5Hz.

    Note: The Propeller compiler ignores the _ in numbers -- this is not a replacement for a decimal point. Many of us use this style to indicate that the value doesn't represent whole units.

  • JonnyMacJonnyMac Posts: 8,973
    edited 2022-06-13 16:18

    Note: The way Dave wrote that stepper code means you can only ever run one instance of it in a program. If you decide you need two steppers, you'll need to move the values that are in the dat section to a var section. All instances of a given class share the dat and code sections from the class.

  • I don't quite understand what you said . To run two steppers should I run two instances and put data from both DAT sections in a VAR or run one instance and put DAT into a VAR.

  • bbrienbbrien Posts: 561
    edited 2022-09-14 19:00

    can somebody please help me? in this thread post number 70 JonnyMac suggests that I move the data from the DAT section to the VAR section but what else should I also do with the stepper object. am including the file for stepper.spin.

                                                                                                                 thanks
    
  • If you're going to have multiple copies of the same object running in an application and the parameters for each need to be unique, put them into RAM. If they're in a DAT section they will be shared among all copies of the object class, and the last object configured will control the parameters for all.

  • If I am using two steppers labeled step1 and step2 can I use two objects labeled stepper and stepper2 , I can copy and "save as" on stepper2

  • JonnyMacJonnyMac Posts: 8,973
    edited 2022-09-16 18:30

    @bbrien said:
    If I am using two steppers labeled step1 and step2 can I use two objects labeled stepper and stepper2 , I can copy and "save as" on stepper2

    You could, but that's not wise -- you'd have two files doing the same thing. Since you won't do it yourself, I updated Dave's stepper driver so that you can run multiple copies without conflicts. Note that this is updated and styled to the way I write Spin, but it works exactly like Dave's version. I've added "dh_" to the name so you can have both versions in your library. A small change is that my update always has the stepper output pin return to low when you stop the motor.

    [snip]

    Update

    Dave used a local variable in the pulse-generator cog that I didn't think was necessary. Looking at that code again, he may have used that to prevent a possible race condition. I have updated my version of the code to guard against that as well. Please use the version that is dated 16 SEP 2022.

  • JonnyMacJonnyMac Posts: 8,973
    edited 2022-09-16 18:14

    (deleted by JM)

  • Ok Jon I am assuming that these are Objects and I don't have to change any of the coding other than the startups. Will make the changes and start testing tomorrow. Will let you know in a few days.
    thanks

  • JonnyMacJonnyMac Posts: 8,973
    edited 2022-09-16 02:42

    Make your life easy
    -- download and save "dh_stepper.spin" into your Library folder
    -- in you app, change "stepper" to "dh_stepper"

    My version of Dave's code runs exactly like his, but allows multiple instances to run, each using their own pin set. Once you get that running you may be happy. If at a later time you want to save the two cogs, you can use jm_daul_step-dir.spin, but that takes more code changes, so save it for later.

  • bbrienbbrien Posts: 561
    edited 2022-09-16 18:00

    Thanks for the clarification, will do both. Ah, one more point: do I use"" dh_stepper.start(RA_SPEED, RA_DIR, DEC_SPEED, DEC_DIR) "" in the start-up codes

  • JonnyMacJonnyMac Posts: 8,973
    edited 2022-09-16 18:15

    do I use"" dh_stepper.start(RA_SPEED, RA_DIR, DEC_SPEED, DEC_DIR) "" in the start-up codes

    No. As I stated, all you need to do is download dh_stepper.spin to your Library folder, and then change

      step1 : "stepper"                                             ' stepper motor driver
      step2 : "stepper"
    

    to

      step1 : "dh_stepper"                                          ' stepper motor driver
      step2 : "dh_stepper"
    

    That's it. The new object is 100% compatible with the old so you don't have to make any other changes.

    Please... DO NOT download the other object (I removed it from this thread). It's quite clear that you don't yet know enough about Spin programming to deal with the changes required to use that object in your app. Right now, getting your code to work is a greater priority than having efficient code.

  • Important: I looked at Dave's original version and concluded he made a deliberate choice about the use of a local variable. I have updated my version of Dave's object to do the same. Please, download the latest version and make sure that the date inside the file is listed as 16 SEP 2022.

  • Ok , now I have compiled the program. Now I can get back to programming the new hand controller . Chat with you later
    Brien

  • bbrienbbrien Posts: 561
    edited 2022-12-06 05:27

    New program is working and is almost perfect, only problem is the speed at RA = 7_2, mount gains about 19 minutes and at 7_1 looses about 22 minutes. I need to change increments from 0.1Hz to 0.01Hz. Need Help. Reference post #81.I have included the object "dh_stepper" if this helps.

  • Upon further reading, I am becoming more confused , is this even a spin language or is this some form of C language. I need to change the resolution of the frequency.

  • In the section (set_speed(tHz)) What does" ||tHz mean and what does it do."

  • @bbrien said:
    In the section (set_speed(tHz)) What does" ||tHz mean and what does it do."

    Total guess, but it might be tens of Hz, or thousands of Hz

    Ie. Instead of 0.01 Hz you would multiply by 1000 and so use set_speed(10). This technique of multiplying up avoids needing to use decimal places in the code.

  • The || operator means “absolute value”. So in this case it is using the absolute value of tHz for the division operation.

  • JonnyMacJonnyMac Posts: 8,973
    edited 2023-01-01 05:56

    Instead of 0.01 Hz you would multiply by 1000 and so use set_speed(10). This technique of multiplying up avoids needing to use decimal places in the code.

    It's not that simple. The system frequency is one of the terms in the expression and you'll get a roll-over.

    I did a bit of experimenting and changed the set_speed() method to work with 1/100Hz values.

    pub set_speed(hHz)
    
    '' Set stepper output speed (frequency) in 0.01Hz units
    '' -- e.g., 10_00 = 10.00Hz
    '' -- direction output set by sign of speed (negative speed for reverse)
    
      if (hHz == 0)                                                 ' stop?
        hcticks := 0
        outa[dc] := 0
      else
        hcticks :=  5 * clkfreq / ||hHz * 10                        ' ticks in 1/2 cycle at hHz
        outa[dc] := hHz <-= 1                                       ' set direction to sign bit
    

    Copy and past this into dh_stepper.spin (replace the old version of the method) and then use 0.01Hz units.

    I tested with the value 7_15 (7.15Hz) and checked with a logic analyzer using 100MHz sample rate. See attached.

    1920 x 1040 - 55K
Sign In or Register to comment.