• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #include <xc.h>
20 #include <stdint.h>
21 #include <stdbool.h>        /* For true/false definition */
22 
23 // ***************************
24 // alias integer types standard C integer types
25 typedef int8_t int8;
26 typedef int16_t int16;
27 typedef int32_t int32;
28 typedef uint8_t uint8;
29 typedef uint16_t uint16;
30 typedef uint32_t uint32;
31 
32 // 1st step=50ms; max speed=120rpm (based on 1MHz timer, 1.8deg steps)
33 #define C0    (50000*8l)
34 #define C_MIN  (2500*8)
35 
36 #include "motor2.c"
37 
main()38 void main() {
39     initialize();
40      while (1) { // repeat 5 revs forward & back
41         motor_run(1000);
42         while (run_flg);
43         motor_run(0);
44         while (run_flg);
45         motor_run(50000);
46         while (run_flg);
47     }
48 } // main()
49