Pages: [1]   Go Down
Author Topic: Simulate AS5045 Magnetic Rotary Encoder Serial Output with Arduino?  (Read 1096 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to control the motor speed with an Arduino on a Hobie Cat eVolve kayak motor. Like this: http://www.hobiecat.com/kayaks/accessories/evolve/#

The throttle lever uses an AS5045 magnetic rotary encoder to read the throttle position and sends that info to the eVolve's microcontroller using the AS5045's synchronous serial interface.

To control the motor speed I was trying to simulate the serial response from the AS5045 with an Arduino Mega and send that to the eVolve's microcontroller. However, I haven't been able to get the eVolve to read the correct response and get an error E23 "Value Range False". Which I think means the value it's interpreting is out of the ~2000 to 4095 expected value range of the 12bit encoder.

I'm not sure if the Arduino is fast enough to simulate this response or if my code (hopefully) is just really bad,  smiley-red. Any suggestions or ideas on simulating this output or another method of controlling the motor's speed are welcome.

AS5045 Datasheet: http://www.ams.com/eng/content/view/download/1243

The unsuccessful code is:
Quote
#include <digitalWriteFast.h>
const int ledPin = 13;
const int clockPinin = 0; //Interrupt connected to Torqeedo control clock
const int CSnPinin = 8; //output to chip select, data output initiated when CSn goes low
const int outputPin = 3; //Simulate AS5045 response pin

int y = 0; // Bit counting variables
long motorSpeedBinary = 240935; //Start with motor stopped 111010110100100111

void setup()
{
  pinMode(CSnPinin, INPUT); // CSn -- has to toggle high and low to signal chip to start data transfer
  pinMode(outputPin, OUTPUT); // SDA
  
  //Attach the interrupt to the clock pin and monitor for rising voltage
  //When clock starts switching data is being sent across serial.
  attachInterrupt(clockPinin, motorSpeed, RISING);
}

void loop()
{
if (!digitalReadFast(CSnPinin) && y == 0) {
  pinMode( outputPin, OUTPUT );  // Exit tri-state mode
  digitalWriteFast(outputPin,HIGH); // Initialize output pin to high to signal serial data transfer starting.
}
else if (digitalRead(CSnPinin)) { // Csn pin is high so no data is being sent through serial
  //When not sending data put output pin in tri-state mode
  digitalWrite( outputPin, LOW );
  pinMode( outputPin, OUTPUT );  // now we're sourcing current, i.e. GND
  pinMode( outputPin, INPUT ); // now we're tri-stated
}

}


void motorSpeed()
{
    if (y <18){
    digitalWriteFast(outputPin,bitRead(motorSpeedBinary, 17-y)); //Send data through serial bit by bit
    y++; //Increment bit to be sent
  }
  if (y>17) { //Last bit has been sent get ready for next transfer.
   y = 0;
  }
}


I have been able to read the values from the AS5045 using this:
Quote
#include <digitalWriteFast.h>

const int clockPinin = 0; //Interrupt connected to clock
const int CSnPinin = 8; //output to chip select
const int outputPin = 3; //read AS5040
const int progPin = 9; //Programming pin attached to AS5045

int inputstream = 0; // one bit read from pin
long packeddata = 0; // two bytes concatenated from inputstream

int y = 0;

//Timer variables
unsigned long oldTime = 0;
unsigned long newTime =0;

void setup()
{
  Serial.begin(115200);
  pinMode(CSnPinin, INPUT); // CSn -- has to toggle high and low to signal chip to start data transfer
  pinMode(outputPin, INPUT); // SDA
  pinMode(progPin,INPUT);
  
  //Attach the interrupt to the clock pin and monitor for rising voltage
  attachInterrupt(clockPinin, motorSpeed, RISING);
}

void loop()
{

}

void motorSpeed()
{
  //Increment through incomming data and read into variable
  if (y<18){
    inputstream = digitalReadFast(outputPin); //Read current bit
    packeddata = ((packeddata << 1) + inputstream); //Save recent bit into the packeddata variable
    y++;
  }
  if (y>17){

    Serial.print("Cs:");
    Serial.print(digitalReadFast(CSnPinin));
    Serial.print(" Prog:");
    Serial.print(digitalReadFast(progPin));
    Serial.print(" Data:");
    Serial.println(packeddata,BIN);
    y = 0;
    packeddata = 0; 
  }  
}


Logged

Pages: [1]   Go Up
Jump to: