File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff 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+
267281uint16_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+
274300uint16_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;
Original file line number Diff line number Diff 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
210211private:
211212
You can’t perform that action at this time.
0 commit comments