Control of new motor for a vintage sewing machine

Encoders are best for position measurement
If you have a disc with 1,2,or4 holes and an optical pickup , you can write your own code and the data rate will be ok . As I said before speed control won’t be easy as you probably have a very non linear system , meaning optimal control will have ti be slow .
But build something and play with it .

Car ignition systems have been made using 30tooth discs and that works at 8000rpm on fairly basic processors (8bit, 8MHz)

Here

Early stuff

Thanks for your comment and links. I guess that your point is, that the high processing power of the ESP32 is not needed, and the Arduino is sufficient.
One thing about an engine is, that its lowest typical speed is about 800 rpm. It is still rather many counts each second on the 30tooth disc. I like to go down to 60 rpm with the DC motor, and then you may need to wait about 16 ms or more for a count on the encoder to correct any speed. It may be OK, but a bit disturbing for me.

I start to think, that the old way with an extra small brushed DC-motor used as tachogenerator would be best. Then you can get an analog reading of speed when ever you want. The price of such small DC motors are very low, and you can get 5 pole rotor coreless types with quite low ripple voltage. A very cheep 3-pole DC-motor was used as feed back in the above videos of the sewing machine with traditional analog electronics, and it works. Using digital encoders may be the wrong way to go.

This video go a bit into reading of a digital encoder, but provide no direct solution to the slow speed problem: https://youtu.be/HRaZLCBFVDE

I have started to work on this concept, but I have encountered something, that worries me. It is about the use of timer1 on the Arduino Nano.

I am using this standard programming example for analog input and output, that is just a little modified. I added a analogWrite in the setup and changed the delay in the loop.

When I use analogWrite in the loop, then the output PWM works fine. When I use

OCR1A = outputValue;

Then the PWM output on pin 9 becomes tri state, so no output from timer. I like to know why, because I do not like the possibility, that the output can become tri state in fractions of the time.
Can Assigning a value to the OCR1A just like that make the output become tri state?

I have tried to look the timer1 control registers, and they are not changed. So I guess something affects the state of the I/O-ports described in section 14 in the 328P manual. This section is hard to read, and therefore I hope for some help.

This is the code I use:

/*
  Analog input, analog output, serial output

  Reads an analog input pin, maps the result to a range from 0 to 255 and uses
  the result to set the pulse width modulation (PWM) of an output pin.
  Also prints the results to the Serial Monitor.

  The circuit:
  - potentiometer connected to analog pin 0.
    Center pin of the potentiometer goes to the analog pin.
    side pins of the potentiometer go to +5V and ground
  - LED connected from digital pin 9 to ground through 220 ohm resistor

  created 29 Dec. 2008
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInOutSerial
*/

// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9;  // Analog output pin that the LED is attached to

int sensorValue = 0;  // value read from the pot
int outputValue = 0;  // value output to the PWM (analog out)

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
  analogWrite(analogOutPin, outputValue);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // change the analog out value:
  //analogWrite(analogOutPin, outputValue);
  OCR1A = outputValue;
  // print the results to the Serial Monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  // wait 2000 milliseconds before the next loop for the analog-to-digital
  // converter to settle after the last reading:
  delay(2000);
}

The problem describe with pin 9 state have been solved. It is described here: https://forum.arduino.cc/t/unexpected-behavior-of-analogwrite/1194809

Hello backflip.

I have built a sewing machine motor control that implements much of what you seem to be looking for. It uses an Arduino Nano to control a standard sewing machine motor. The motor itself is from a typical universal motor kit such as you can buy to fit nearly all vintage sewing machines.

I own and use a vintage Adler sewing machine (from 1926) for leather projects. The usual foot pedals make it difficult to control the machine at low speed, so I made my own. The fact that I'm sewing leather makes it more complicated. Leather takes more force to puncture, then it "grabs" the needle when it starts going back up. It is very difficult to manage a steady (slow) speed when sewing leather.

The controller uses a slotted disk and infrared detector pair to read the speed. There's an interrupt that counts the time for each pulse.

For smooth control of the output, I use the TimerOne library. It gives me 1023 steps of PWM.

It uses AutoPID with the pulse period to calculate the PWM output to maintain the speed - pretty much no matter the load on the motor.

Since I'm not good at PID tuning, it uses the pidautotuner library to determine the needed PID coefficients. Push button tuning.

It can run steadily at 60 stitches per minute - or a bit lower.

It has a "low speed" mode where it holds a set speed, then when you push the pedal a little further it goes into proportional mode - press harder for faster.

The only thing it doesn't do that I think you wanted was needle positioning. I didn't put a sensor in for it, though it shouldn't be hard to add one if it's really needed. I just nudge the foot pedal when I need to raise the needle (or do it by hand.)

The code for the finished project is on my GitHub Bigfoot page. That includes the software, all the hardware (circuit diagram, PCB layout, components, etc.) as well as all the drawings I made to build the housing for it.

2 Likes

You can read the whole tale of its development here.

2 Likes

Thank you for your comment.

I did not know about this quite cheap encoder, that you links to. You are right, that I want to be able to use low speed for heavier fabrics and heavier thread (Tex 135). In order to sew leather you got such requirements. But you need that for strong seems in vinyl or dense webbing as well.

In this video (you see linke above as well), you see five tests, you can do to make sure, that you got good speed control. The machine use a speed reducer, an universal motor and electronics with a small DC-motor for speed feed-back. It is conventional electronics and no Arduino:

This video demonstrate a speed range on sewing machine of 8 to 540 stitches/minute.
In my experience, you need the motor to provide a torque on the main shaft of the sewing machine of at least 3 Nm, and with the common universal motors for sewing machines, you can achieve that with a gear ratio between motor and machine of 1:20. You find the torque-speed characteristics of some of the common sewing machine universal motors here:
https://youtu.be/VLU_s1RGasA&t=216

When you sew at low speed, it will only be a small part of the time, that a high torque is needed. The universal motors and the DC-motors I look for would overheat, if the high torque should be provided continuously, but it would not happen. Some way of measuring current and estimate the motor winding temperature could add some protection of the motor against over temperature. I have got one of the 250 W Chinese universal motors, and it heats up very fast, when it provides torque near its maximum.

Furthermore, I should like the machine to sew fast like 1800 stitches/minute. A few popular vintage household sewing machines are able to handle that, such as Pfaff 130 or Pfaff 230. I think some of the smaller cheap DC-motors designed for use in powerful battery tools might be able to handle this. The universal motors for sewing machines are not able to do that range of speed and torque.

I noticed in your link, that DC voltage was used to control the universal motor. It do demonstrate, that it is possible, but it do also include some risks to use this high DC voltage on them. If for some reason the belt to sewing machine snaps, the motor can increase speed that high, that centrifugal forces will destroy the motor. AC voltage limits the possible speed on these motors.
The other problem is arcing at the commutator. At high current and torque, arcing can cause short circuit. AC current ensures clearing of the commutator arcing at zero crossings in the current.

I built in a fail safe function so that if the belt snaps on my machine, the Arduino will shut down the motor after five seconds. The fail safe uses the rotation speed pulses. If there's no pulse for five seconds, it shuts off the PWM. Besides catching a run-away condition, it also activates if the machine jams. Five seconds of "stuck" isn't enough to damage the motor, but long enough to be sure that it really isn't moving.

It uses DC, and there's a capacitor to smooth it, but the capacitor is small enough that it can't supply a really heavy load. If the motor jams, the DC will become pulsed, allowing arcs to quench.

At high speed, regulation isn't terribly important. Once you get above a few hundred stitches per minute, inertia takes over and the speed kind of regulates itself.

At the same time, you don't need tremendous torque at high speed. If you are flying along at 1200 stitches per minute then it is unlikely that you are sewing heavy stuff. The long stitches used for thick material means that at really high stitch rates the material would be going through your hands far to fast to be guided accurately. A 5 mm stitch length at 1800 stitches per minute works out to about 9 meters a minute - call it thirty feet of material per minute. I know I can't work with anything that fast.

That is to say, high speed is for lighter stuff, not for the heavy stuff where good speed control and high torque are needed.

The control I built has an upper limit, though you can easily change it if needed. I have it set to 800 stitches per minute

A 10000 RPM universal motor should be able reach 1500 stitches per minute The motor I am using is rated 10000 RPM. The motors in the various motor kits range from 5000 to 10000. I've seen motors with those ratings for sale at various places

Yes, we agree, that it is the slow speed and heavy fabrics, that needs the good speed control. It also needs high torque on the sewing machine shaft, and it will determine the needed gearing to the motor. I also agree, that high speed are for lighter fabrics. You need relative high power to drive a sewing machine at high speeds, but the torque there is rather low. In one of my linked videos of the Pfaff 230 above, the speed of 1830 stitches/minute needs about 80 W shaft power, and it is a torque of 0.42 Nm on the main sewing machine shaft. The gearing at belt is 3.5:1. At low speed, you can in principle increase the gearing until you get the torque you need from the motor. The normal universal motors cannot provide sufficient torque for heavy fabrics at a gearing of about 4:1.

The nominal 180 W universal motor I got have a rated speed of 10.000 rpm. It can provide a max shaft power of 54 W at 5700 rpm at 226 VAC. At 10.000 rpm it can provide a power of 44 W. At no load the speed reach 17.500 rpm. I have not been able to find accurate information about the meaning of the rated speed of the universal motors from the Asian manufacturers. I know that some European manufacturers years back marked the speed near the max shaft power point of the motor. Most of the universal motors used for the vintage household sewing machines got a max shaft power in the range 20 to 40 W and a specified input power in the range 60 to 100 W.

It is good to know, that you build in some protection against high motor speed.

I just tried to make a concept study with a brushed DC motor using another small DC motor as a tacho generator for feed back of speed. Current feed back is used for an inner proportional control loop. In this way I obtained a speed range of 300 to 1 relative easily. I made a 7 min video about it, because it may be easier to explain what I did:

https://youtu.be/mmy6z2qqFD4

There is a lot of detail here, that is not included. Please ask, if you want more information.

Timer1 of the Arduino Nano v.3 is used for the PWM control to get a PWM frequency of 20 kHz on the motor. Timer1 do also trigger the ADC so you can measure the current in the H-bridge transistors at the right time. Mode 10 is used according to Table 16-4 in the 328P documentation. For current measurement, the ADC used the Timer1 Counter overflow as given in Table 24-6. This ensures right timing the ADC measurement without the use of an interrupt routine. The used ADC clock frequency is 1 MHz (it is normally set to 125 kHz by default).

1 Like

Great project well done. Thanks for sharing.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.