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 19 #include <xc.h> 20 #include <stdint.h> 21 #include <stdbool.h> /* For true/false definition */ 22 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 30 // 1st step=50ms; max speed=120rpm (based on 1MHz timer, 1.8deg steps) 31 #define C0 (50000 << 8) 32 #define C_MIN (2500 << 8) 33 34 #include "motor1.c" 35 main()36void main() { 37 initialize(); 38 while (1) { // repeat 5 revs forward & back 39 motor_run(1000); 40 while (run_flg); 41 motor_run(0); 42 while (run_flg); 43 } 44 } // main() 45