-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepper.h
100 lines (83 loc) · 2.54 KB
/
stepper.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*********************************************************************
*
* Stepper motor control
*
*********************************************************************
* FileName: stepper.h
* Dependencies:
* Processor: PIC18F2525
* Complier: XC8 v1.45
*
* Software License Agreement
*
* Copyright © 2011-2019 Sylvain Girard
*
* Author Date Comment
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Sylvain Girard 28/03/2011 Creation
********************************************************************/
#ifndef _STEPPER_H
#define _STEPPER_H
#include <p18cxxx.h>
//******* D E F I N I T I O N S ************************************************/
#define MOTOR_TRIS TRISB
#define MOTOR_PORT PORTB
#define MOTOR_1A PORTBbits.RB0
#define MOTOR_2A PORTBbits.RB1
#define MOTOR_3A PORTBbits.RB4
#define MOTOR_4A PORTBbits.RB5
#define PWM PORTBbits.RB3
#define DIRECTION_IN 0
#define DIRECTION_OUT 1
#define HALF_STEP 1
#define FULL_STEP 2
#define FULL_STEP_LOWCONSO 3
#define TIMER_BASE_PERIOD 150
//******* D A T A S T R U C T U R E S ******************************************************/
typedef union
{
unsigned int lt;
char bt[2];
} un_timers;
typedef struct
{
unsigned char motor_1a;
unsigned char motor_2a;
unsigned char motor_3a;
unsigned char motor_4a;
} st_motor_seq;
typedef union
{
unsigned char byte;
struct
{
unsigned is_moving :1;
unsigned last_direction :1;
unsigned manual_move :1;
unsigned park :1;
};
} u_stepper_flag;
//******* P R O T O T Y P E S ***********************************************************/
void timer0_isr (void);
void stepper_init(void);
void stepper_stop(unsigned char force);
void stepper_start_in(void);
void stepper_start_out(void);
void stepper_high_speed(void);
void stepper_relative_move(unsigned int nb, unsigned char dir);
void stepper_absolute_move(unsigned int position);
unsigned char stepper_mode(unsigned char mode);
//****** V A R I A B L E S ********************************************************/
#ifndef _STEPPER_C
extern unsigned int stepper_delay_manual;
extern unsigned int stepper_delay_auto;
extern unsigned int stepper_pos_max;
extern unsigned int stepper_pos_min;
extern unsigned int stepper_position;
extern unsigned int stepper_backlash;
extern u_stepper_flag stepper_flag;
//extern unsigned char stepper_is_moving;
//extern unsigned char stepper_last_direction;
extern void (*p_step_sequencer)(void);
#endif
#endif //_STEPPER_H