Skip to content

Commit 03391c2

Browse files
author
Richard Unger
committed
add setZero capability to AS5047U
1 parent d7cd0c1 commit 03391c2

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/encoders/as5047u/AS5047U.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,39 @@ void AS5047U::enableUVW(bool enable){
264264

265265

266266

267+
268+
uint16_t AS5047U::getZero(){
269+
uint16_t command = AS5047U_ZPOSM_REG | AS5047U_RW;
270+
spi_transfer16(command);
271+
command = AS5047U_ZPOSL_REG | AS5047U_RW;
272+
uint16_t result = spi_transfer16(command);
273+
AS5047UZPosL posL = {
274+
.reg = nop()
275+
};
276+
return ((result&0x00FF)<<6) | posL.zposl;
277+
}
278+
279+
280+
267281
uint16_t AS5047U::setZero(uint16_t value){
268-
// TODO implement me!
269-
return 0;
282+
uint16_t command = AS5047U_ZPOSL_REG | AS5047U_RW;
283+
/*uint16_t cmdresult =*/ spi_transfer16(command);
284+
command = AS5047U_ZPOSL_REG;
285+
AS5047UZPosL posL = {
286+
.reg = spi_transfer16(command)
287+
};
288+
posL.zposl = value&0x003F;
289+
spi_transfer16(posL.reg);
290+
command = AS5047U_ZPOSM_REG;
291+
spi_transfer16(command);
292+
spi_transfer16((value>>6)&0x00FF);
293+
delayMicroseconds(50);
294+
return getZero();
270295
}
271296

272297

273298

299+
274300
uint16_t AS5047U::nop(){
275301
uint16_t result = spi_transfer16(0xFFFF); // using 0xFFFF as nop instead of 0x0000, then next call to fastAngle will return an angle
276302
return result&AS5047U_RESULT_MASK;

src/encoders/as5047u/AS5047U.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class AS5047U {
206206
void enableUVW(bool enable);
207207

208208
uint16_t setZero(uint16_t);
209+
uint16_t getZero();
209210

210211
private:
211212

0 commit comments

Comments
 (0)