Shop OBEX P1 Docs P2 Docs Learn Events
Getting a handle on counters?? — Parallax Forums

Getting a handle on counters??

photomankcphotomankc Posts: 943
edited 2010-01-15 06:33 in Propeller 1
I've been working on my driver for a stepper controller and making decent progress. Got a motor moving stuff around now and going to the positions it's told to go to. The driver is designed to run in two modes, first mode is slaved to an external step/dir signal. Mode 2 is internally controlled via commands. Each command is 32bits (may change to 64 later) and tells the driver how far to move, direction, and speed.

I have been using spin to directly toggle the pins and it works alright. I keep thinking about counters though and maybe there would be an easier way to do it. Right now if anything in my loop changes I have to reverify my overhead+pulse high time and account for that in the pause between pulses. Kind of a pain. I'd rather simply be able to tell it how long to delay and know that it will happen at that frequency. Seems a perfect fit for a counter. I don't understand one thing though. Is it possible to get the counter to always output a fixed pulse high time with a variable low time with 1uSec resolution?

Next problem I see is acceleration. To accelerate I have to constantly update the delay time after each pulse to a shorter delay until I reach the target rate. I think the only hope there would be to run in PASM to be able to change the counter parameters fast enough to keep up which probably is where my counter idea falls apart anyway. I'd have to be tied up in a loop through a table to set those values anyway so toggling the pin is really not that big an added burden.

Anyway I know there are folks that use the counters in ways that I wouldn't ever think of so I'm just fishing for ideas. Someday I'm going to simply have to sit down and write the command fetch/execute code in PASM, or maybe BEAN's propbasic.

Comments

  • TonyWaiteTonyWaite Posts: 219
    edited 2010-01-14 19:09
    Hi,
    Picking up on your PropBASIC thoughts, Bean has posted servo demo code on the main PropBASIC
    thread.
    T o n y
  • photomankcphotomankc Posts: 943
    edited 2010-01-14 19:17
    Hmmm.... I wonder if was getting wrapped into the positive pulse aspect too far..... it really is PWM but it's just a low pulse whose width is being adjusted.
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-01-14 23:07
    Did you make a test what the fastest pulse-frequency is if you use SPIN?

    Typical ramps are quadratical functions so calculating them in realtime in PASM would be a little complicated

    One way to keep it the stepper-loop fast is to pre-calculate the delay-times and store the values in a byte-array
    Size 100-200 bytes (=steps) to ramp up and down.

    Then your stepper-loop is just incrementing the index of the byte-array which should be much faster than calculating
    floating-point or even integer.

    best regards

    Stefan
  • photomankcphotomankc Posts: 943
    edited 2010-01-15 06:33
    StefanL38 said...
    Did you make a test what the fastest pulse-frequency is if you use SPIN?

    Typical ramps are quadratical functions so calculating them in realtime in PASM would be a little complicated

    One way to keep it the stepper-loop fast is to pre-calculate the delay-times and store the values in a byte-array
    Size 100-200 bytes (=steps) to ramp up and down.

    Then your stepper-loop is just incrementing the index of the byte-array which should be much faster than calculating
    floating-point or even integer.

    best regards

    Stefan
    Ding, ding, ding.· This is my accel plan in a nutshell.·· Early code will just use the pre-calculated data from my Excel spreadsheet.· Later I want to calculate the table at startup if the accel parameter has changed, otherwise load the table from EEPROM.·

    Bare minimum loop is about 12 to 14Khz.· Checking for enable after each step to make sure I can stop in the middle of a move·if commanded, lowers that to about 9.6KHz.· Since I can shift to lower microstep modes on the fly I can still reach higher speeds even if the base mode is 1/16th using SPIN.· I just look at what I was asked to do and shift into the mode that will allow me to reach it and divide the steps requested appropriately.

    ·
Sign In or Register to comment.