Menu

CodeRewrite1

Anonymous

Rewriting the prototype code

The initial revision of the code is ugly written as it has been developed while debugging the hardware. The most problematic parts are the acceleration/deceleration phase, and the size of the code as the code is simply duplicated for each axis. The initial acceleration code comes from

  1. http://atmel.com/dyn/resources/prod_documents/doc8017.pdf) /
  2. http://eetimes.com/design/embedded/4006438/Generate-stepper-motor-speed-profiles-in-real-time

Other interesting considerations can be found in

  1. http://www.ti.com/lit/an/slyt482/slyt482.pdf
  2. http://www.trinamic.com/tmc/media/Downloads/webinar/2009-07_MotionControl_&_Motor-Basics_GG_web.pdf
  3. http://picprog.strongedge.net/step_prof/step-profile.html
  4. https://www.eetimes.com/design/other/4026992/Linear-motor-control-without-the-math-item-1?pageNumber=0&Ecosystem=audio-design
  5. http://www.embedded.com/columns/technicalinsights/56800129?_requestid=55193
  6. http://www.pmdcorp.com/news/articles/html/Mathematics_of_Motion_Control_Profiles.cfm
  7. https://github.com/GarethS/Motor

Details

  • Factorization of the code using structs for axis data: this avoids code duplication, but the use of generic struct pointers requires pointer arithmetic which results in a longer asm code. sdcc can't even compile it on a 16k PIC. Microchip XC8 succeeds with a code size of 15k (it claims it can reduce the code size to less than 6k, using the pro version). Here is the code produced with sdcc for an access to a long int (4 bytes), axis->wormperiod, whose address is stored in local registers r0x00, r0x01, r0x02:

        MOVF    r0x00, W
        ADDLW   0x18
        MOVWF   r0x03
        MOVLW   0x00
        ADDWFC  r0x01, W
        MOVWF   r0x04
        MOVLW   0x00
        ADDWFC  r0x02, W
        MOVWF   r0x05
        MOVFF   r0x03, FSR0L
        MOVFF   r0x04, PRODL
        MOVF    r0x05, W
        CALL    __gptrget4
        MOVWF   r0x03
        MOVFF   PRODL, r0x04
        MOVFF   PRODH, r0x05
        MOVFF   FSR0L, r0x06
    
  • Replaced generic pointer with array of struct. Global replacement of axis->field with motorsaxisindex.field. sdcc succeeds to compile with a final code size of 12.5k. Most of code in high_isr (4k) and main (2.5k).

  • S-Shaped acceleration/decelration for angular speed: this will replace the initial liner acceleration algorithm. In developement. See SShapeRamping for details.