motor_test1.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * david austin
  3. * http://www.embedded.com/design/mcus-processors-and-socs/4006438/Generate-stepper-motor-speed-profiles-in-real-time
  4. * DECEMBER 30, 2004
  5. *
  6. * Demo program for stepper motor control with linear ramps
  7. * Hardware: PIC18F252, L6219
  8. *
  9. * Compile with on Microchip XC8 compiler with the command line:
  10. * XC8 --chip=18F252 motor_test1.c
  11. *
  12. * Copyright (c) 2015 Robert Ramey
  13. *
  14. * Distributed under the Boost Software License, Version 1.0. (See
  15. * accompanying file LICENSE_1_0.txt or copy at
  16. * http://www.boost.org/LICENSE_1_0.txt)
  17. */
  18. #include <xc.h>
  19. #include <stdint.h>
  20. #include <stdbool.h> /* For true/false definition */
  21. typedef int8_t int8;
  22. typedef int16_t int16;
  23. typedef int32_t int32;
  24. typedef uint8_t uint8;
  25. typedef uint16_t uint16;
  26. typedef uint32_t uint32;
  27. // 1st step=50ms; max speed=120rpm (based on 1MHz timer, 1.8deg steps)
  28. #define C0 (50000 << 8)
  29. #define C_MIN (2500 << 8)
  30. #include "motor1.c"
  31. void main() {
  32. initialize();
  33. while (1) { // repeat 5 revs forward & back
  34. motor_run(1000);
  35. while (run_flg);
  36. motor_run(0);
  37. while (run_flg);
  38. }
  39. } // main()