Hi Guys
I am having troubles getting the motor driver to read the encoder for a EMG30 motor from Devantech.
All other data requests can be returned to USB to display on hyperterminal no problems but when it comes to receiving 4 bytes of data I am stuck!
I have tried most options (arrays, etc) but have yet to crack it! I am missing something. I have searched and used other examples from the internet all without success.
/*_________________________________________________________
The Data sheet for the MD25:
GET ENCODER 1, GET ENCODER 2 or GET ENCODERS
When a read encoder command is issued the MD25 will send out 4 bytes high byte first, which should be put together to form a 32 bit signed number. For example a GET ENCODER 1 command may return 0x00,0x10,0x56,0x32.
So declare a 32 bit signed variable in your program, for C:
long result;
result = serin() << 24; // (0x00 shifted 24 bits left, effectively * 16777216)
result += serin() << 16; // (0x10 shifted 16 bits left, effectively * 65536)
result += serin() << 8; // (0x56 shifted 8 bits left, effectively * 256)
result += serin(); / (0x32)
result now equals 1070642 decimal or 0x105632 hex. If the highest bit was set then it would be -ve.
read encoders will send encoder count 1 and then encoder count 2 but is put together in exactly the same way. The registers can be zeroed at any time by writing 0x35 to the MD25.
*/______________________________________
The encoder read function example from Robot-electronics.co.uk for serial connection is
long readEncoder(){ // Function to read and display the value of both encoders, returns value of first encoder
long result1 = 0;
long result2 = 0;
Serial.write(CMD);
Serial.write(READENCS);
while(Serial.available() <
{} // Wait for 8 bytes, first 4 encoder 1 values second 4 encoder 2 values
result1 = Serial.read(); // First byte for encoder 1, HH.
result1 <<= 8;
result1 += Serial.read(); // Second byte for encoder 1, HL
result1 <<= 8;
result1 += Serial.read(); // Third byte for encoder 1, LH
result1 <<= 8;
result1 += Serial.read(); // Fourth byte for encoder 1, LL
result2 = Serial.read();
result2 <<= 8;
result2 += Serial.read();
result2 <<= 8;
result2 += Serial.read();
result2 <<= 8;
result2 += Serial.read();
A month of failures and I have no other option but to ask for help!
Does anyone have a code for this function to use to grab 4 bytes of data and return a value for use as a counter to get a motor to stop at a given angle!
I am using the Axon 2 with the Devantech MD25 driver.
The joys of programing!
Otherwise the Axon 2 is a great piece of kit, 5 stars for that bad boy SoR!!
Thanks Heli