Skip to content

Commit 61c66cf

Browse files
authored
Update README.md
1 parent a69c4f7 commit 61c66cf

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

README.md

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The code is simple enough to be ran on Arudino Uno board.
6161
#### Encoder
6262
- Encoder channels `A` and `B` are connected to the Arduino's external intrrupt pins `2` and `3`.
6363
- Optionally if your encoder has `index` signal you can connect it to any available pin, figure shows pin `4`.
64-
- The librtary doesnt support the Index pin for now (version v1.1.0)
64+
- The library doesnt support the Index pin for now (version v1.1.0)
6565
#### L6234 breakout board
6666
- Connected to the arduino pins `9`,`10` and `11`.
6767
- Additionally you can connect the `enable` pin to the any digital pin of the arduino the picture shows pin `8` but this is optional. You can connect the driver enable directly to 5v.
@@ -85,8 +85,8 @@ To use HMBGC controller for vector control (FOC) you need to connect motor to on
8585
Since HMBGC doesn't have acces to the arduinos external interrupt pins `2` and `3` and additionally we only have acces to the analog pins, we need to read the encoder using the software interrupt. To show the functionallity we provide one example of the HMBGC code (`HMBGC_example.ino`) using the [PciManager library](https://github.com/prampec/arduino-pcimanager).
8686

8787
- Encoder channels `A` and `B` are connected to the pins `A0` and `A1`.
88-
- Optionally if your encoder has `index` signal you can connect it to any available pin, figure shows pin `A3`.
89-
- The librtary doesnt support the Index pin for now (version v1.1.0)
88+
- Optionally if your encoder has `index` signal you can connect it to any available pin, figure shows pin `A2`.
89+
- The library doesnt support the Index pin for now (version v1.1.0)
9090
#### Motor
9191
- Motor phases `a`,`b` and `c` are connected directly to the driver outputs
9292

@@ -96,19 +96,47 @@ Motor phases `a`,`b`,`c` and encoder channels `A` and `B` have to be oriented ri
9696

9797

9898
## The code
99-
The code is organised in two libraries, BLDCmotor.h and endcoder.h. BLDCmotor.h contains all the necessary FOC funciton implemented and encoder.h deals with the encoder. I will make this better in future. :D
99+
The code is organised into a librarie. The library contains two classes `BLDCmotor` and `Endcoder`. `BLDCmotor` contains all the necessary FOC algorithm funcitons as well as PI controllers for the velocity and angle control. `Encoder` deals with the encoder interupt funcitons, calcualtes motor angle and velocity( using the [Mixed Time Frequency Method](https://github.com/askuric/Arduino-Mixed-Time-Frequency-Method)).
100100

101101
### Initialization
102-
The heart of the init is the constructor call:
102+
#### Motor initialisaiton:
103+
To intialise the motor you need to input the `pwm` pins, number of `pole pairs` and optionally driver `enable` pin.
103104
```cpp
104-
BLDCMotor motor = BLDCMotor(9,10,11,&counter[ENCODER_1],A0,A1,11,2400);
105-
//BLDCMotorint(phA, phB, phC, long* counter, int encA, int encB , int pp, int cpr)
105+
// BLDCMotor( int phA, int phB, int phC, int pp, int en)
106+
// - phA, phB, phC - motor A,B,C phase pwm pins
107+
// - pp - pole pair number
108+
// - enable pin - (optional input)
109+
BLDCMotor motor = BLDCMotor(9, 10, 11, 11, 8);
110+
```
111+
#### Encoder intiialisation
112+
To initialise the encoder you need to provide the encoder `A` and `B` channel pins, encoder `CPR` and optionally `index` pin.
113+
114+
```cpp
115+
// Encoder(int encA, int encB , int cpr, int index)
116+
// - encA, encB - encoder A and B pins
117+
// - ppm - impulses per rotation
118+
// - index pin - (optional input)
119+
Encoder encoder = Encoder(2, 3, 32768, 4);
120+
```
121+
122+
### Parametrisation
123+
```cpp
124+
// encoder initialise hardware pins
125+
// Pullup::EXTERN - external pullup added
126+
// Pullup::INTERN - needs internal arduino pullup
127+
encoder.init(Pullup::EXTERN);
128+
```
129+
130+
```cpp
131+
// interupt intitialisation
132+
// A callback and B callback
133+
attachInterrupt(digitalPinToInterrupt(encoder.pinA), []() {
134+
encoder.handleA();
135+
}, CHANGE);
136+
attachInterrupt(digitalPinToInterrupt(encoder.pinB), []() {
137+
encoder.handleB();
138+
}, CHANGE);
106139
```
107-
The first three arguments are pin numbers of them motor phases, either 9,10,11 or 6,5,3
108-
Fourth argument is a pointer to the encoder counter
109-
Fith and sixt argument are encoder pins channel A and channel B
110-
Seventh argument is number of Pole pairs of the motor
111-
And Eight argument is the cpr of the encoder
112140
113141
### Usage in loop
114142

0 commit comments

Comments
 (0)