]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/safe_numerics/example/motor_test3.c
3 * http://www.embedded.com/design/mcus-processors-and-socs/4006438/Generate-stepper-motor-speed-profiles-in-real-time
6 * Demo program for stepper motor control with linear ramps
7 * Hardware: PIC18F252, L6219
9 * Compile with on Microchip XC8 compiler with the command line:
10 * XC8 --chip=18F252 motor_test3.c
12 * Copyright (c) 2015 Robert Ramey
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)
21 // 8 MHz internal clock
22 #define _XTAL_FREQ 8000000
25 #include <stdbool.h> /* For true/false definition */
27 // ***************************
28 // nullify macro for literals
31 // ***************************
32 // map strong types to appropriate underlying types.
33 typedef uint16_t position_t
;
34 typedef int16_t step_t
;
35 typedef uint32_t ccpr_t
;
37 typedef uint16_t phase_t
;
38 typedef uint8_t phase_ix_t
;
39 typedef int8_t direction_t
;
41 // 1st step=10ms; max speed=300rpm (based on 1MHz timer, 1.8deg steps)
42 #define C_MIN literal((1000 << 8))
43 #define C0 literal((10000 << 8))
49 // move motor to position 200
51 while(busy()) __delay_ms(100);
52 // move motor to position 1000
54 while(busy()) __delay_ms(100);
55 // move back to position 0
57 while(busy()) __delay_ms(100);