-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathAS5040.h
81 lines (66 loc) · 2.01 KB
/
AS5040.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
/*
* AS5040.h - Arduino library for AMS AS5040 magnetic rotary encoder chip
* version 1.0 2014-03-05
*
* Copyright (c) 2014 Mark Tillotson. All rights reserved.
*
* This file is part of "Mark's AS5040 library for Arduino"
*
* "Mark's AS5040 library for Arduino" is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "Mark's AS5040 library for Arduino" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with "Mark's AS5040 library for Arduino".
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AS5040_h
#define AS5040_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
// mode defines
#define AS5040_QUADRATURE 0x1
#define AS5040_STEPDIR 0x2
#define AS5040_COMMUTATE 0x3
#define AS5040_COMMUTATE_4POLE 0xB
#define AS5040_10BIT 0x0
#define AS5040_9BIT 0x4
#define AS5040_8BIT 0x8
#define AS5040_7BIT 0xC
#define AS5040_WIDE_IDX 0x10
// defines for 5 bit _status value
#define AS5040_STATUS_OCF 0x10
#define AS5040_STATUS_COF 0x08
#define AS5040_STATUS_LIN 0x04
#define AS5040_STATUS_MAGINC 0x02
#define AS5040_STATUS_MAGDEC 0x01
class AS5040
{
public:
AS5040 (byte pinCLK, byte pinCS, byte pinDO, byte pinPROG = 0xFF) ;
boolean begin () ;
boolean begin (byte mode) ;
boolean begin (byte mode, boolean reverse, unsigned int offset) ;
unsigned int read () ;
byte status () ;
boolean valid () ;
int Zaxis () ;
private:
byte _pinCLK ;
byte _pinCS ;
byte _pinDO ;
byte _pinPROG ;
byte _status ;
byte _parity ;
byte even_parity (byte val) ;
} ;
#endif