508 |
kaklik |
1 |
/*
|
|
|
2 |
* Copyright (C) 2004 Darren Hutchinson (dbh@gbdt.com.au)
|
|
|
3 |
*
|
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
|
5 |
* it under the terms of the GNU Library General Public License as published by
|
|
|
6 |
* the Free Software Foundation; either version 2 of the License, or (at your
|
|
|
7 |
* option) any later version.
|
|
|
8 |
*
|
|
|
9 |
* This program is distributed in the hope that it will be useful, but
|
|
|
10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
11 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
|
|
|
12 |
* License for more details.
|
|
|
13 |
*
|
|
|
14 |
* You should have received a copy of the GNU Library General Public License
|
|
|
15 |
* along with this software; see the file COPYING. If not, write to
|
|
|
16 |
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
|
|
17 |
* MA 02111-1307, USA.
|
|
|
18 |
*
|
|
|
19 |
* $Id: stepper.h,v 1.7 2004/04/05 06:42:15 dbh Exp $
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
#ifndef _STEPPER_H_
|
|
|
23 |
#define _STEPPER_H_
|
|
|
24 |
|
|
|
25 |
/* Define the encoding used to hold the exictation values for each
|
|
|
26 |
* stepper coil.
|
|
|
27 |
*/
|
|
|
28 |
#define _EX_ENTRY(c1, c2) (((c1) << 4) | (c2))
|
|
|
29 |
#define _GET_C1(e) ((e) >> 4)
|
|
|
30 |
#define _GET_C2(e) ((e) & 0xf)
|
|
|
31 |
|
|
|
32 |
#define EX_0 0x0 // Inactive
|
|
|
33 |
#define EX_P_0_2 0x1 // +0.2 active
|
|
|
34 |
#define EX_P_0_4 0x2 // +0.4 active
|
|
|
35 |
#define EX_P_0_67 0x3 // +0.67 active
|
|
|
36 |
#define EX_P_1 0x4 // +Active
|
|
|
37 |
|
|
|
38 |
#define EX_M_0_2 0x9 // -0.2 active
|
|
|
39 |
#define EX_M_0_4 0xa // -0.4 active
|
|
|
40 |
#define EX_M_0_67 0xb // -0.67 active
|
|
|
41 |
#define EX_M_1 0xc // -Active
|
|
|
42 |
|
|
|
43 |
/* Define the struture used to pass excitation information from
|
|
|
44 |
* the stepper module to the excitation module
|
|
|
45 |
*/
|
|
|
46 |
struct excitation_s
|
|
|
47 |
{
|
|
|
48 |
uint8_t excitation;
|
|
|
49 |
uint8_t useRelay;
|
|
|
50 |
};
|
|
|
51 |
|
|
|
52 |
extern struct excitation_s raExcitation;
|
|
|
53 |
extern struct excitation_s decExcitation;
|
|
|
54 |
|
|
|
55 |
/* Define a structure to hold the current "state" for each axis. This
|
|
|
56 |
* allows up to use the same code for both axis, so I don't feel
|
|
|
57 |
* tempted to skimp on the features
|
|
|
58 |
*/
|
|
|
59 |
struct stepState_s
|
|
|
60 |
{
|
|
|
61 |
// Input (from the combiner)
|
|
|
62 |
int8_t reqSpeed; // Rate requested
|
|
|
63 |
|
|
|
64 |
// Output (to the driver)
|
|
|
65 |
struct excitation_s *pExcite;
|
|
|
66 |
|
|
|
67 |
// Configuration
|
|
|
68 |
uint16_t backlash; // #steps to counteract backlash
|
|
|
69 |
uint8_t finPos; // Finish movement in positive direction
|
|
|
70 |
uint8_t finNeg; // Finish movement in negative direction
|
|
|
71 |
|
|
|
72 |
// Machine state
|
|
|
73 |
uint8_t stepCtr; // Current step in cycle
|
|
|
74 |
int8_t curSpeed; // Current rate (when moving after spin)
|
|
|
75 |
void *pState; // State pointer
|
|
|
76 |
uint16_t count; // Counter used in states
|
|
|
77 |
|
|
|
78 |
uint8_t *pTable; // Current step table
|
|
|
79 |
|
|
|
80 |
// Support function state
|
|
|
81 |
uint8_t clkDivRatio; // Current clock div
|
|
|
82 |
uint8_t divCtr; // Clock division counter
|
|
|
83 |
};
|
|
|
84 |
|
|
|
85 |
/* These are held in stepper.c */
|
|
|
86 |
extern struct stepState_s raState;
|
|
|
87 |
extern struct stepState_s decState;
|
|
|
88 |
extern int8_t trackingRate;
|
|
|
89 |
extern uint8_t transRatio;
|
|
|
90 |
|
|
|
91 |
/* Prototypes */
|
|
|
92 |
void stepperInit(void);
|
|
|
93 |
void setRaSpeed(int8_t speed);
|
|
|
94 |
void setDecSpeed(int8_t speed);
|
|
|
95 |
|
|
|
96 |
void setupRateTable(uint8_t transRatio);
|
|
|
97 |
void setTrackRate(int8_t rate);
|
|
|
98 |
|
|
|
99 |
/* DEBUG: Uses half step instread of microstep if true */
|
|
|
100 |
extern uint8_t doHalfStep;
|
|
|
101 |
|
|
|
102 |
#endif /* _STEPPER_H_ */
|
|
|
103 |
|