Hi,
I've been dreaming for a long time to change some linistepper code just to add a few "features".
But, i'm nowhere an expert in PIC assembly.
So, i decide to rewrite linistepper to C. Thanks to Roman Black for good code commenting, making me who's bad in assembly can easily rewrite the thing in C :cheers:
Whats changed:
- Move high/low power table from code to EEPROM lookup
- Ignore ENABLE pin input.
- Use step signal timeout to switch between low and high power.
- Store stepping table to EEPROM.
- Use inline assembly for pwm loop (maintains 333kHz pwm)
- Disable runtime stepping mode change.
- Stepping mode is initialized on startup only to improve calculation time between step.
- Use quadrature input instead of STEP/DIR
Simply put, this version will drop motor current after ~1 second if there is no signal received in that timeframe. Motor current will go to full power when next stepping is received.
This 1 second timeout is changeable in source code.
This linistepper-c also support quadrature input (Phase-A and Phase-B)
From EMC2 manual:
type 0: step/dir
Two pins, one for step and one for direction. make-pulses must run at least twice for each step (once to set the step pin true, once to clear it). This limits the maximum step rate to half (or less) of the
rate that can be reached by types 2-14. The parameters steplen and stepspace can further lower the maximum step rate. Parameters dirsetup and dirhold also apply to this step type.The good thing with quadrature is your step can be as fast as your parallel-port. With step/dir, each step need to toggle between '1' and '0', so speed is cut by two.type 2: quadrature
Two pins, phase-A and phase-B. For forward motion, A leads B. Can advance by one step every time make-pulses runs.
Also, it's possible to detect a single miss steps with quadrature, as it is a form of Gray-code.
Btw, the step/dir code is also included in zip, but it's never tested.
The bad things:
1) The source code looks "hack"ish. This is due to:
- My incompetence
- SDCC workaround.
2) The code generated by SDCC is slow. It insert BANKSEL instruction every here and there. I've included hand edited assembly generated by SDCC to remove this unnecessary call, just as an example on how to improve further.
3)It's slower than the original linistepper in asm.
With linistepper-asm, there's only ~20us delay before it output a new motors' current value.
With SDCC compiled code, there's around ~50us before it output a new motors' current value.
By editing the sdcc code and remove unneeded BANKSEL, "thinking" time now drop from 50us to ~30us.
4)It might have bugs.
This software is still untested by many, so there's probably a few bugs creeping inside. If you find any, please update it here so we can share the fixes.
Thanks in advance.