Galaxis Codebase
1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
quadrature_counter.h
Go to the documentation of this file.
1
/*
2
* quadrature_counter.h
3
*
4
* Created on: Jul 1, 2019
5
* Author: nixone
6
*
7
* Sensor description:
8
*
9
* Sensor name: LS7366R
10
*
11
* Datasheet URL: https://lsicsi.com/pdfs/Data_Sheets/LS7366R.pdf
12
*
13
* Communication Protocol: SPI (SPI2 of STM32)
14
*
15
* Important Registers:
16
* STR: 8-bit
17
* ___________________________
18
* |CY|BW|CMP|IDX|CEN|PLS|U/D|S|
19
* ---------------------------
20
* CY: Carry (CNTR overflow) latch
21
* BW: Borrow (CNTR underflow) latch
22
* CMP: Compare (CNTR = DTR) latch
23
* IDX: Index latch
24
* CEN: Count enable status (0= disabled, 1= enabled)
25
* PLS: Power loss indicator latch, set upon power up
26
* U/D: Count direction indicator, 0= count down, 1= count up
27
* S: Sign bit 1= negative, 0= positive
28
*
29
* MDR0: 8-bit
30
* _______________________
31
* |B7|B6|B5|B4|B3|B2|B1|B0|
32
* -----------------------
33
* quadrature count mode:
34
* xxxxxx00: non-quadrature count mode (A = clock, B = direction)
35
* xxxxxx01: x1 quadrature count mode (one count per quadrature cycle)
36
* xxxxxx10: x2 quadrature count mode (two counts per quadrature cycle)
37
* xxxxxx11: x4 quadrature count mode (four counts per quadrature cycle)
38
*
39
* running mode:
40
* xxxx00xx: free running
41
* xxxx01xx: single cycle
42
* xxxx10xx: range-limit
43
* xxxx11xx: modulo-n
44
*
45
* index:
46
* xx00xxxx: disable index
47
* xx01xxxx: configure index as "load CNTR" (CNTR = DTR)
48
* xx10xxxx: configure index as "reset CNTR" (CNTR = 0)
49
* xx11xxxx: configure index as "load OTR" (OTR = CNTR)
50
*
51
* async index:
52
* x0xxxxxx: async index
53
* x1xxxxxx: sync index
54
*
55
* filter clock division factor:
56
* x0xxxxxx: factor = 1
57
* x1xxxxxx: factor = 2
58
*
59
* MDR1: 8-bit
60
* _______________________
61
* |B7|B6|B5|B4|B3|B2|B1|B0|
62
* -----------------------
63
* Byte Counter Mode:
64
* xxxxxx00: 4 byte counter mode
65
* xxxxxx01: 3 byte
66
* xxxxxx10: 2 byte
67
* xxxxxx11: 1 byte
68
*
69
* Enable Counting:
70
* xxxxx0xx: enable counting
71
* xxxxx1xx: disable counting
72
*
73
* B3 not used
74
* B4-B7 for FLAG setup, not used by us
75
*
76
*/
77
78
#ifndef QUADRATURE_COUNTER_H_
79
#define QUADRATURE_COUNTER_H_
80
/* INCLUDES */
81
82
#include <stdbool.h>
83
#include <stdint.h>
84
85
/* DEFINES */
86
87
/*
88
* STR bit defines
89
*/
90
#define QCTR_CARRY_BIT 0x7U
91
#define QCTR_BORROW_BIT 0x6U
92
#define QCTR_CMP_BIT 0x5U
93
#define QCTR_IDX_BIT 0x4U
94
#define QCTR_CEN_BIT 0x3U
95
#define QCTR_PLS_BIT 0x2U
96
#define QCTR_UD_BIT 0x1U
97
#define QCTR_S_BIT 0x0U
98
99
/*
100
* MDR0 defines
101
*/
102
#define SYNC_MODE 0x40U
103
#define RUNNING_MODE 0x00U
104
#define COUNT_MODE 0x03U
105
#define INDEX_MODE 0x00U
106
#define FILTER_MODE 0x00U
107
108
/*
109
* MDR1 defines
110
*/
111
#define FLAG_MODE 0x00U
112
#define DATA_WIDTH 0x00U
113
#define CNTR_BYTES (0x4U - DATA_WIDTH)
114
#define QCTR_MAX_BYTES 0x4U
115
#define ENABLE_CNTR 0x00U
116
#define DISABLE_CNTR 0x04U
117
118
/* TYPEDEFS */
119
120
#if(CNTR_BYTES == 0x4U)
121
typedef
int32_t
quadratureCounterValueType
;
122
#elif(CNTR_BYTES == 0x3U)
123
typedef
int32_t
quadratureCounterValueType
;
124
#elif(CNTR_BYTES == 0x2U)
125
typedef
int16_t
quadratureCounterValueType
;
126
#else
127
typedef
int8_t
quadratureCounterValueType
;
128
#endif
129
130
#endif
/* QUADRATURE_COUNTER_H_ */
quadratureCounterValueType
int32_t quadratureCounterValueType
Definition:
quadrature_counter.h:121
nodes
ECUNode
util
quadrature_counter.h
Generated by
1.8.17