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:
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?