Time for the first electronics post. We're going to drive my turntable motor with the Arduino Uno and the Infineon motor shield.



The Infineon DC Motor Control Shield is connected to the Arduino UNO. The Arduino controls the motor power by sending PWM signals to the shield.

The duty cycle of the PWM defines how much power is going to the motor. I'm using that technique to speed up and slow down the motor.


The signal


The Arduino is generating the PWM signal. When you drive a motor with PWM, it's not the frequency that drives the motor speed, but the duty cycle of the signal.



The easiest way to get a PWM signal on an Arduino with variable duty cycle is by calling analogWrite().

There's noting wrong with that for most applications, but it's not ideal for my project.

The frequency of this standard method is somewhere between 900 and 1000 Hz. And that is in the audio range.

I risk getting my turntable's signal polluted by the PWM signal.


To mitigate that, I used a library that supports higher frequency PWM: the Timer1 lib.


The Timer1 Arduino library


This library allows me to lift the PWM frequency above the frequencies that we can hear (if you are not a bat).

I settled for 33.3 kHz (a period of 30 µs).


#include <TimerOne.h>

const byte PWMpin = 9; // PWM only supported on pin 9 or 10
const byte INH_1 = 11;
int iDC = 705; // exact speed at 10 volt

void setup(void) {
  // ...
  pinMode(PWMpin, OUTPUT);  
  pinMode(INH_1, OUTPUT);
  Timer1.pwm(PWMpin, iDC, 30); // duty cycle [10 bit], period [us] <8388480
  digitalWrite(INH_1, HIGH); // enable OUT1


I define two pins as outputs here:


Pin 9 is connected to the half H-Bridge IN port. This is the PWM input that will control how much energy the motor shield sends to the motor.

Pin 11 connects to the half H-Bridge INH port. Driving this one low will stop the motor, whatever we do with pin 9.


Then we tell the library to generate a 33 kHz signal on pin 9, with a duty cycle of 705.

The duty cycle range goes from 0 to 1023. So you have to interpret this 705 as (705/1023)*100 = 68%.

I've chosen 705 because that gives me a correct turntable speed when I supply 10 V to the motor shield.



The pictures below show the PWM signal at different duty cycles.

The signal is probed at pin 9 of the Arduino.




Test Bed


I've extended my sketch to make the duty cycle variable. You can enter a duty cycle in the Arduino IDE serial monitor, and that value is then sent to the Timer1 lib.


void setup(void) {
  // ...
  Serial.println("Ready for input...");

void loop(void)
  while (Serial.available() > 0) {
    // look for the next valid integer in the incoming serial stream,
    // between 5 and 1023,
    // < 5 is no signal, > 1023
    iDC = Serial.parseInt();
    Timer1.setPwmDuty(PWMpin, iDC);


The setPwmDuty() immediately changes the duty cycle, and alters the motor speed.

This is an ideal test bed to exercise the motor driver design.




The Result


With the firmware ready and everything wired up, let's have a look at some results.


IMG_4353.JPG p002.JPG

The picture below shows the input and output signal of the shield at a duty cycle of 705 (68%).

The yellow signal is probed at pin 9 of the Arduino. The blue signal is measured at out1 of the shield.


You can see the switching time on the capture. i've highlighted it with the two vertical cursors. I measured 4.40 µs.

You can find a more detailed review of the shield and the signals  in Vintage Turntable repair: Can I fix a Perpetuum Ebner from 1958 - part 3 - Infineon Motor Driver shield.


The Limits


The shield doesn't work from 0 to 100%. I've used the test bed to measure the working range in my circuit and with my firmware.

It's dependent on the frequency. The half H-Bridge needs time to switch on and off. So the total period of a PWM signal plays a role in the upper and lower limits.

I hit them around 10% and 86%. You can see that in the captures below.


In each of the captures, the blue signal is the output just outside the working range.

The white signal is a stored signal just within the range.


Lower limitUpper limit


You can see that the output signal flatlines in both situations. The output under 10% is 0 V, above 86% it's the input voltage of the shield (give and take some).



Voila. The motor drive part is finished. I'm now ready to start with the speed detector.



Table of Contents
Chapter 1: Fix the turntable
1: Perpetuum Ebner Musical 1
2: A Time to Kill and a Time to Heal
3: Preparation for Motor Drive
4: Motor control with Infineon Motor Shield and Arduino UNO
5: Turntable speed sample testbed with Arduino UNO
6: Turntable Speed Sensor design
7: Control Theory - End of Chapter 1
Chapter 2: First Enchantments
8: Digital Light Organ Enchantment
9: Autonomous Servo Lift
10: SMD Time - Solder the IR Speed Sensor PCB
11: Yelp - who can Help me to Compile and Run my First SAMA5D4 C Program
12: Son et Lumiere - End of Chapter 2
Chapter 3: Taming the Board
13: Breakthrough - Run my own C++ Program on the SAMA5D4
14: Digital Light Organ Input Buffer
15: SAMA5D4 Blinky
16: Scope Creep
17: Audio Sampling with 16-bit ADC ADS8343
18: Sending Files to SAMA5D4 over USB
19: Port my Light Organ from Arduino to SAMA5D4
20: Fast Fourier Transform on the SAMA5D4 - End of Chapter 3
Epilogue: Reaching for the Clouds
21: Right-Sizing my Plans
22: My Own C++ Buffered Sampler on the SAMA5D4
23: Building In the Motorized Light Organ
24: Up to the Clouds with Yún
25: Publish or Perish
26: Turntable Finished
Stretch & Boni
Bonus 1a: Remote Light Organ with WiFI pt. 1
Bonus 1b: Remote Light Organ with WiFI pt. 2
Grande Finale: Paho MQTT Client on the SAMA5D4
Related blog
Vintage Turntable repair: Can I fix a Perpetuum Ebner from 1958
Review 1: Atmel SMART SAMA5D4 Xplained Ultra Unboxing and First Steps
Review 2: Atmel SMART SAMA5D4 Xplained Ultra - Building the Libraries from Source
Review 3: Digital Continuous Rotation (360°) Servo Part 1
Review 4: Digital Continuous Rotation (360°) Servo Part 2
Review 5: Atmel SMART SAMA5D4 Xplained Ultra - TCP/IP running
Review 6: Atmel SMART SAMA5D4 Xplained Ultra - LINUX Distro with SSH support
Enchanted Objects: Let's work together to tame the ATMEL SMART SAMA5D4 Xplained Ultra kit
17 bis: Off South...
Review 7: Atmel SMART SAMA5D4 Xplained Ultra - C++ ADC Example on Linux
Review 8: Atmel SMART SAMA5D4 Xplained Ultra - Product Review
Review 9a: Atmel SMART SAMA5D4 Xplained Ultra - Set up ADC Buffer with Hardware Trigger Part 1
Review 9b: Atmel SMART SAMA5D4 Xplained Ultra - Set up ADC Buffer with Hardware Trigger Part 2
Review 10: Atmel SMART SAMA5D4 Xplained Ultra - New Content on AT91.com
1958 Turntable from the Black Forest - Summary of the Enchanted Player Story