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.initialize(); 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.
200 | 511 | 676 |
---|---|---|
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.begin(9600); // ... 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); Serial.println(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.
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 limit | Upper 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.
Top Comments