Arduino Engineering Kit encoders return incorrect readings

I'm working through the Arduino Engineering Kit material, using MATLAB/Simulink R2018b on Windows 7.
The examples in Chapters 2.1 (Arduino Getting Started) and 2.2 (MATLAB Getting Started) worked OK, and so did everything in Chapter 2.3 (Simulink Getting Started) as far as the open-loop control example - but when I tried the closed-loop control example the motor went haywire, running erratically forwards and backwards at maximum speed. Looking at the outputs from the encoder block on the scope, the position, and speed if I add that as a second output, are both varying apparently at random in the range +/- 2e+9, even if the motor is stationary:
simulink encoder issue 2018-11-28_09h19_04.png
Now when I go back to the MATLAB examples that worked previously, the encoder object returns a constant value of 12 for readCount and 65 for readSpeed no matter what the position of the actual motor is.
I haven't changed the connections between the Arduino and motor/encoder since the point when it was working, I've checked with a voltmeter that the encoder outputs are changing between 0 V and 3.3 V as I rotate the motor, as expected, so I don't think it's the hardware, and I've tried uninstalling all Arduino-related add-ons and reinstalling them in the order specified in the Engineering Kit instructions, but no success.
I have the latest versions of everything, as far as I know: MATLAB/Simulink 2018b, MATLAB Support Package for Arduino Hardware 18.2.0, Simulink Support Package for Arduino Hardware 18.2.0, Arduino Engineering Kit Hardware Support 18b 1.1.1, Arduino IDE 1.8.7, Arduino SAMD Boards 1.6.19, and MKRMotorCarrier library 1.0.1 as specified in the ArduinoKitHardwareSupportReadMe.txt file, although I see the latest version available of that library is 1.0.3.
What can I try next? My best guess is that something in the configuration or firmware of the MKR motor carrier has been incorrectly changed by the Simulink support package, but how do I fix that? Should I try reflashing the motor carrier firmware as described here? Any ideas?

 Accepted Answer

So when you are going through steps shown in the online material, what happens if you try to do open loop control again and measure the speed of the encoder? Is it anywhere close to the figures shown in the material. Feel free to email me from here and I can help you check what is wrong.

7 Comments

Here's the result of running the open loop model from the examples, to which I've added the encoder read from the MKR Motor Carrier library and wired it to a second scope:
simulink encoder issue 2018-11-29_09h21_34.png
If you can't make it out from the image, the scale on the encoder scope goes from -5 x 1e8 to 20 x 1e8.
You should be comparing the speed and not the count on the encoder. Have you tried following the online material to build your own models as this seems to be an old model.
If you do not want to build your own models, please upgrade the Arduino_Engineering_Kit_Project_Files to version 1.2. Remember to uninstall the old project files before installing this version. Try to do everything from inside Add-On explorer.
Thanks
Another suggestion would be to use the Motor_test_encoder sketch avaialble in Chapter 3 to test if everything is okay with the encoder and motor. Remember though that the connections might be different and you will have to match yours with that shown in the circuit diagram right next to the code.
HTH,
Madhu
Thanks for the response. I did build my own models from the online material before trying the version from the examples, with the same result. I was using the zip download of the project files from here but I have downloaded and installed the toolbox version instead, again with the same result. I'm sure I have the current version of both zip and toolbox so can you explain why you think it's an old one please?
When I try the Motor_test sketch from chapter 3.1 it uploads and runs but in the serial terminal the MKR1000 sends the response Couldn't connect! Is the red led blinking? You may need to update the firmware with FWUpdater sketch.
There isn't a red LED blinking on either the MKR1000 or the motor carrier - but I don't know which LED that's supposed to be, because of the complete lack of documentation for the motor carrier - and I can't find a sketch called FWUpdater anywhere in my installation.
I thought it was the old one because in that version we took the output directly from the encoder speed output and used that, which turned out to work only 95% of the times and was not reproducible when it did fail.
Anyways if the firmware needs to be updated, the easiest way would be to reach out to Arduino Customer Support at engkit@arduino.cc. I cannot create the request on your behalf as I do not have your email address and the registration code from the kit which I do not feel comfortable asking you to share in a public forum like this.
Madhu
The response from Arduino technical support suggested reflashing the firmware on the motor carrier board using the Flasher example (Arduino IDE > Files > Examples > Mkrmotor Carrier> Flasher).
The first time I tried this it worked once then the same behaviour came back again. After repeating the procedure it so far seems to have fixed the problem. I'll let you know whether this fix turns out to be permanent.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!