Or should I say, "not reading?" I am able to drive the motor using packet serial mode, and I believe I am even able to control speed with the quadrature encoder, but I don't have the tools to verify that. The motor does ramp up and down as would be expected with the accel and decel parameters with quadrature decoder commands. Something it doesn't do when given a simple speed command like (Serout P15, i19200, [128, 0, 127, (255 & 0X7F)]) The program will execute until the Serin command, and at that point it will just hang. No errors, no warnings, just stops. I am only trying this in debug mode, but have tried both animated and not. I have a feeling it's something I'm doing wrong with the serin command. I'm using a dev board, so the hardware serial port is tied to the USB. The following code is from the Roboclaw datasheet, only modified to work on p15 of my nano.
Code:
Encoder1 Var Long
Sts Var Byte
CRC Var Byte
Clear
Pause 2000
serout p15, i19200, [128, 20, (148 & 0x7F)]; Resets encoder registers
Main
Pause 100
ReadEncoderM1
serout p15, i19200, [128, 16] 'highlights here and hangs
serin p15, i19200, [Encoder1.byte3, Encoder1.Byte2, Encoder1.Byte1, Encoder1.Byte0, Sts, crc]
debug ["Encoder1: ", DEC Encoder1, 13, "Status Byte: ", BIN Sts]
pause 500
goto Main
If I use this code, the motor appears to run fine, but does not give me any feedback... which, unfortunately, is required in this case.
Code:
Speed Var Long
Accel Var Byte
CRC Var Byte
Address con 128
CMD Var Byte
Clear
Gosub MixStop ;Stop any previous running command and set speed / accel values
;Program starts here. Each label specifies what the command does.
MixForward
CMD = 36
CRC = (Address + CMD + Speed.byte3 + Speed.byte2 + Speed.byte1 + Speed.byte0 + Accel) & 0x7f
serout p15, i19200, [Address, CMD, Speed.byte3, Speed.byte2, Speed.byte1, Speed.byte0, Accel, CRC]; Drive forward
Gosub WaitCMD
Gosub MixStop
goto MixForward
WaitCMD
CRC = 0 ;Clear CRC
Pause 5000 ;Run CMD for 5 seconds
Return ;Go back to command after gosub
MixStop
Speed = 0 ;Max pulse per second
Accel = 30 ;ramp up pulse per second
CRC = (Address + CMD + Speed.byte3 + Speed.byte2 + Speed.byte1 + Speed.byte0 + Accel) & 0x7f
serout p15, i19200, [Address, CMD, Speed.byte3, Speed.byte2, Speed.byte1, Speed.byte0, Accel, CRC]; Stop
Pause 5000
SetValues
Speed = 4000 ;Top speed / max pulse per second
Accel = 50 ;Ramp up / down pulse per second
Return