More SAMD21 M0 weirdness

My assumption was that using Arduino IDE was the quickest and simplest way to venture into the world of 32 bit ARM processors, but I am starting to think otherwise. This post is the second about things not working as expected and time used to figure out what's wrong.

For a motor-controller project, I was testing Allegro's A4950 h-bridge when I realized that while varying motor speed using a PWM signal, sudden torque spikes were happening.

My first idea was that the power supply was to blame, so I replaced it, to obtain exactly the same result.

The code I was running was very simple and on close inspection, I could not find any reason for the observed glitch, that somehow had a periodic nature: one acceleration and deceleration period would work ok and the next one will show three or four torque spikes.

As I was using an Arduino-form M0 board (SAMD21-based) I decided to bring back my trusted Arduino UNO and to run exactly the same code. This time all worked nicely, no sudden accelerations on the motor while speed was going up and down.

So next stop was to grab the M0 PWM output and to look for possible anomalies that would explain the problem (or maybe the problem is with the h-bridge I am testing, after all, I have never used that chip before).

So this is a quick recap of the captured PWM signal:

This is the PWM cycle before the glitch where duty cycle was 75.75%

Suddenly the next cycle is ON 2.3ms while the former was only 1.034 milliseconds, to account for a duty cycle of 87%. That was totally undesired and unexpected.

And the next PWM cycle after the glitch goes back to normal, again 1.028 milliseconds of ON time to account for a duty cycle of 75.17%.

So there it was, it appears that some of the calls to analogWrite may cause some glitch in the PWM output. If I want to keep on using this board I will need to figure out how to change the PWM duty cycle without experiencing that problem, which means to use some time to learn how SAMD21 timer registers work.

That is why I am starting to think that I rather use 8-bit Arduinos for prototyping as they have quite a predictable behavior while the same seems not to be true for some of the new brethren. While this may look like some Arduino-bashing article it is not. It is more a warning call for people like me that want to save themselves the pain of ARM datasheet reading.

Comments

Popular posts from this blog

VFD control with Arduino using RS485 link

4xiDraw: Another pen plotter

Software I2C for Arduino