Skip to content

Commit

Permalink
add resultoutput function, mode = 0, output PWM, mode = 1 output analog
Browse files Browse the repository at this point in the history
  • Loading branch information
baorepo committed Aug 20, 2019
1 parent 32a49e6 commit 15ba2fd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
13 changes: 12 additions & 1 deletion AS5600.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/****************************************************
/* AMS 5600 class for Arduino platform
/* Author: Tom Denton
Expand Down Expand Up @@ -47,7 +48,17 @@ AMS_5600::AMS_5600()
_mag_lo = 0x1c;
_burn = 0xff;
}

/* mode = 0, output PWM, mode = 1 output analog (full range from 0% to 100% between GND and VDD*/
void AMS_5600::setOutPut(uint8_t mode){
uint8_t config_status;
config_status = readOneByte(_conf_lo);
if(mode == 1){
config_status = config_status & 0xcf;
}else{
config_status = config_status & 0xef;
}
writeOneByte(_conf_lo, lowByte(config_status));
}
/****************************************************
/* Method: AMS_5600
/* In: none
Expand Down
3 changes: 3 additions & 0 deletions AS5600.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/****************************************************
/* AMS 5600 class for Arduino platform
/* Author: Tom Denton
Expand Down Expand Up @@ -43,6 +44,7 @@ class AMS_5600
int getBurnCount();
int burnAngle();
int burnMaxAngleAndConfig();
void setOutPut(uint8_t mode);

private:

Expand Down Expand Up @@ -77,6 +79,7 @@ class AMS_5600
int readOneByte(int in_adr);
word readTwoBytes(int in_adr_hi, int in_adr_lo);
void writeOneByte(int adr_in, int dat_in);


};
#endif
39 changes: 39 additions & 0 deletions examples/resultoutput/resultoutput.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <Wire.h>
#include <AS5600.h>
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define SERIAL SerialUSB
#define SYS_VOL 3.3
#else
#define SERIAL Serial
#define SYS_VOL 5
#endif

AMS_5600 ams5600;

int ang, lang = 0;

void setup()
{
SERIAL.begin(115200);
Wire.begin();
SERIAL.println(">>>>>>>>>>>>>>>>>>>>>>>>>>> ");
if(ams5600.detectMagnet() == 0 ){
while(1){
if(ams5600.detectMagnet() == 1 ){
SERIAL.print("Current Magnitude: ");
SERIAL.println(ams5600.getMagnitude());
break;
}
else{
SERIAL.println("Can not detect magnet");
}
delay(1000);
}
}
/* mode = 0, output PWM, mode = 1 output analog (full range from 0% to 100% between GND and VDD*/
ams5600.setOutPut(0);
}

void loop()
{
}

0 comments on commit 15ba2fd

Please sign in to comment.