summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/safe_numerics/example/motor_test3.c
blob: 0ef5a02272f5e7e411f3cfa3c0fc799b755021ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * david austin
 * http://www.embedded.com/design/mcus-processors-and-socs/4006438/Generate-stepper-motor-speed-profiles-in-real-time
 * DECEMBER 30, 2004
 *
 * Demo program for stepper motor control with linear ramps
 * Hardware: PIC18F252, L6219
 *
 * Compile with on Microchip XC8 compiler with the command line:
 * XC8 --chip=18F252 motor_test3.c
 *
 * Copyright (c) 2015 Robert Ramey
 *
 * Distributed under the Boost Software License, Version 1.0. (See
 * accompanying file LICENSE_1_0.txt or copy at
 * http://www.boost.org/LICENSE_1_0.txt)
 */

#include <xc.h>

// 8 MHz internal clock
#define _XTAL_FREQ 8000000

#include <stdint.h>
#include <stdbool.h>        /* For true/false definition */

// ***************************
// nullify macro for literals
#define literal(n) n

// ***************************
// map strong types to appropriate underlying types.
typedef uint16_t position_t;
typedef int16_t step_t;
typedef uint32_t ccpr_t;
typedef int32_t c_t;
typedef uint16_t phase_t;
typedef uint8_t phase_ix_t;
typedef int8_t direction_t;

// 1st step=10ms; max speed=300rpm (based on 1MHz timer, 1.8deg steps)
#define C_MIN  literal((1000 << 8))
#define C0    literal((10000 << 8))

#include "motor3.c"

void main() {
    initialize();
    // move motor to position 200
    motor_run(200);
    while(busy()) __delay_ms(100);
    // move motor to position 1000
    motor_run(1000);
    while(busy()) __delay_ms(100);
    // move back to position 0
    motor_run(200);
    while(busy()) __delay_ms(100);
} // main()