Getting a handle on counters??
photomankc
Posts: 943
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.
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
Picking up on your PropBASIC thoughts, Bean has posted servo demo code on the main PropBASIC
thread.
T o n y
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
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.
·