motor_test2.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_test2.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. // ***************************
  22. // alias integer types standard C integer types
  23. typedef int8_t int8;
  24. typedef int16_t int16;
  25. typedef int32_t int32;
  26. typedef uint8_t uint8;
  27. typedef uint16_t uint16;
  28. typedef uint32_t uint32;
  29. // 1st step=50ms; max speed=120rpm (based on 1MHz timer, 1.8deg steps)
  30. #define C0 (50000*8l)
  31. #define C_MIN (2500*8)
  32. #include "motor2.c"
  33. void main() {
  34. initialize();
  35. while (1) { // repeat 5 revs forward & back
  36. motor_run(1000);
  37. while (run_flg);
  38. motor_run(0);
  39. while (run_flg);
  40. motor_run(50000);
  41. while (run_flg);
  42. }
  43. } // main()