Category Archives: Sewing Machine

5070753028_98552330a1_b

Sewing Machine EMI Woes

I think I got my sewing machine to stop randomly rebooting!

(Yes, I am a huge dork…)

LCD with filter capacitor

Motor with grounding wire

This isn’t the first time I’ve delt with EMI problems in my hobby projects, but this one actually turned out to be a lot more annoying than the others. This project has no really high-frequency signals, no super-wide parallel busses, no 100 MHz clocks. But it does have a few ingredients in a small recipe for disaster:

  1. A single power supply input
  2. A pretty high powered DC motor
  3. Several relatively high current items running at different voltages (LCD backlight, LED work light, microcontroller)
  4. Multiple switching power supplies
  5. Analog and digital components
  6. A 10 MHz SPI bus running over perhaps 20 inches of ribbon cable

The symptoms were usually pretty simple. At random intervals while sewing, sometimes after 15 minutes, sometimes after only 2 seconds, the whole system would reboot. The microcontroller resets, and everything goes on like normal. Sometimes instead of rebooting, the LCD would become corrupted but the system would otherwise be fine. Sometimes the motor speed controller (on one of the microcontroller ‘cogs’) would keep running, but the UI (on a different ‘cog’) would crash. Sometimes there would be noise in the tachometer sensor, causing the estimated machine angle to ‘creep’ upwards slowly.

Most of these symptoms seemed like power noise. So I tried adding capacitors, isolating the power supplies, etc. Some of these seemed to make the problem a bit better, but nothing solved it completely. Even with the high-current components totally isolated from the microcontroller, I’d see crashes. So bit by bit, I started the process of elimination, and I ended up with a pretty long list of fixes. I still don’t know if each and every one of these was necessary, but at this point I feel like I’m a doctor trying to cure some terminal illness. I guess about the root cause, prescribe some medication, and if that doesn’t help I try something else. Or if the situation is getting desperate, we’ll just try everything at once. So, before I ended up declaring the problem solved, I ended up doing all of the following:

  1. Tweaked the values of the reset circuit’s RC filter, in case it was spontaneously triggering a reset.
  2. Several additional capacitors on the main board, filtering the input power (6V) as well as the 3.3V supply for the μC
  3. The unused “current sense” output from the LMD18200 was hooked up in such a way as to couple lots of noise into the μC’s ground. Disconnected it.
  4. Some noise was also flowing into the μC’s ground via the outputs for motor PWM and direction. Added series resistors to all of these signals.
  5. An LC filter on the 6V supply as it enters the main board. The higher-current but noise-tolerant loads like the LCD backlight and the LED work light are not protected by the filter, but the 3.3V regulator and the analog circuitry are.
  6. Grounded the motor’s metal enclosure. It was actually throwing off enough EMI that, even with the μC on an isolated power supply, crashes occurred with the motor running but not without. After grounding it, the problem was nearly gone.
  7. I still had occasional crashes, and less occasional LCD glitches. It turns out that the DC-DC converter on the Spark Fun LCD board is rather noisy, and it was coupling noise back into the 6V power supply. Since this power goes overt he long ribbon cable alongside our high-speed SPI bus, it is pretty likely to corrupt bits in that bus. Fixed this by adding a big electrolytic cap directly to the Vbatt input on the LCD board.

Whew.. and after all that, I think it’s finally all fixed.

5050372440_1a6bb354a8_b

Sewing Machine Update: LCD

Life has been super crazy lately, and I haven’t taken much time out lately for hacking on projects. This weekend, though, I finally got that magic combination of time and motivation back, yay.

The occasion: I still owe my boyfriend some cute plushies. Oh, and perhaps I want to try sewing myself a skirt. (Maybe someday I’ll even make a North Skirt). But for any of that, I need my sewing machine to work. Well, it did work… I was just getting annoyed by having to have it hooked up to a computer, and loading different firmware images onto it for different sewing modes. I’d been meaning to add some kind of user interface to the project, but I decided to save that part of the project for later. Well, the future is now… or yesterday, at least?

I had a rather cute 128×128 Nokia 6100 knockoff LCD that I wanted to use with the project. It’s inexpensive, not a bad quality/price tradeoff, and they’re pretty easy to interface with. Spark Fun already has plenty of drivers on their page for different microcontrollers. But of course, not a Propeller. And after searching through the Parallax forums, I couldn’t find any existing driver that was open source, fast, and that actually worked with my LCD.

So, the first step was to write a driver. And thus the first deliverable of the weekend:

Propeller Nokia6100 Driver Demo

With that out of the way, the rest of the job was pretty easy. I really wish I’d done this earlier, since the graphical LCD makes a great tool for illustrating the internal state of the machine’s motion controller. I decided to leave some graphs on it that show current pedal position, shaft angle estimate, and RPM estimate. Oh, and I demand cuteness! So, there’s also a little Kirby sprite that walks along at a rate proportional to how fast you’re sewing. But Kirby is tired, and if you don’t sew his eyelids get heavy…

Sewing machine with LCD and Wheel

(Embedded video)

More things:

5050383246_b385f57780_b

DIY Sewing Machine Retrofit

The story behind this project is a bit overcomplicated. That’s all below, if you’re interested. I made a video to explain the final product:

Back Story

This all started when I bought a sewing machine for making fabric RFID tags a little over a year ago, and started using it to make cute plushy objects. Well, as much as I like making plushy objects, I haven’t actually made very many of them since buying the machine. So, my boyfriend has been guilting me into making him a few as gifts for Christmas, birthday, valentine’s day. Naturally, being the great partner I am, this gets me thinking about ways to soup up my sewing machine first 🙂

The original machine did bug me in many ways when working on fine detail work. I’m lazy and uncoordinated with a needle, so I tend to sew almost everything by machine, even when the individual stitches all have to be lined up just right. In fact, when sewing the face parts on my meat and crab plushies, I found myself sewing individual stitches by turning the flywheel by hand.

I don’t know whether more expensive sewing machines are any better, but on my cheap Singer Inspiration 4210 the stock motor is nearly unusable at slow speeds. It stalls easily, makes an awful buzzing noise, maintains an uneven speed, and delivers very little torque.

Sensors

My first experiments were to instrument the sewing machine with sensors that I could use to estimate the speed and angle of the main shaft.  I needed some kind of absolute angle reference, plus some way of counting how far the shaft has traveled. For the angle reference, I found a really handy place to mount a photo-interrupter sensor. This cam is part of the mechanism that advances the machine’s feed dogs. It conveniently moves this metal bar back and forth once per revolution of the shaft.

Photo-interrupter mounted

For sensing the shaft speed accurately, my preferred solution would have been a high-resolution encoder wheel attached to the motor or the main shaft. But that would, at the very least, involve making a rotary encoder disc and attaching it somehow to one of the sewing machine’s moving parts. I wanted to avoid messing with the machine’s moving parts as much as possible, so I looked for non-contact solutions. I noticed that, with a little signal conditioning, an IR reflection sensor works pretty well for counting teeth on the machine’s drive belt. After switching motors, I modified this to sense teeth on the motor’s sprocket instead, but the same signal conditioning circuit works in either case. The signal conditioner is an dual op-amp configured as an amplifier, bandpass filter, and comparator with hysteresis.

Optical tachometer

Lastly, there’s the most important sensor: the foot pedal! I wanted to keep the original foot pedal feel, but use it as a generic input device for the microcontroller. So, I removed all electronic parts other than the variable resistor itself, and connected that to a 1/8″ jack. With a little modification, the jack fit into the same hole that was originally used for the mains cord.

Pedal after modification

Induction Motors Suck

This is where the project got a bit out of hand and I started making wrong turns. At first, I was hoping it would be possible to implement smooth closed-loop control by using the original motor and a simple triac-based speed controller for the motor. This seemed straightforward enough. But I didn’t have all of the parts on hand to do a normal optotriac + triac based driver circuit. So I went shopping at HSC. No optotriac, but there were some solid state relays. Alas, after I got them home and looked up the data sheets, it turns out they are the zero-crossing switching variety. Useless for speed control. So, back to the drawing board. No optotriacs on hand. Well, I could move the opto-isolation, putting the microcontroller on a line-powered circuit, and opto-isolating the serial port instead. But that sounded really annoying to debug safely, especially for me without an isolation transformer or variac. But that would require a low-voltage power supply on the mains  side of the optoisolator anyway, and if I had to go to that trouble I might as well just use a transistor to switch on the triac…

So I started rummaging through my junk bins again, and I found an old X10 lamp module. This must have a triac in it, I thought. It won’t have an optoisolator, since X10’s cheap circuits never bother with mains isolation. But it might have a power supply and zero-crossing circuit I could use. So I find a handy LM465 schematic online, and I start paring down the circuit into just a bare-bones triac driver, zero crossing detector, and +15V power supply. I got pretty far along on this triac-based speed controller before I switched tactics:

Old triac-based controller (closeup)

I was experimenting with closed-loop servo control using this triac controller, but the results were pretty uninspiring. With a triac, you can only change speeds as fast as twice your AC power frequency. And a 120 Hz control loop just isn’t tight enough to keep the sewing machine operating smoothly at low speeds. The motor’s lousy torque at these speeds certainly doesn’t help.

I also had lots of trouble with EMI in this design. With all the parts strewn about my desk and electrically isolated but not RF shielded, my microcontroller would randomly reset after the motor ran for a few seconds or so. I first saw this with my trusty Propeller. I tried switching to an AVR Butterfly, half to try and avoid the EMI, half to have its LCD and joystick as a user interface. But, no luck.

I was curious how they solve this problem in industry. Servo motors are pretty common in industrial automation, and surely you must need a fancier way to control the speed of a large motor in order to build a heavy-duty servo. Well, it seems that there are two solutions:

  • Just use a DC motor instead of AC. This is more expensive, but it’s simple and until recently it was the only option.
  • Variable-frequency drive. You still use an AC motor, but now you use an AC-to-DC power supply plus a DC-to-AC inverter to control the frequency of the motor’s power supply. With an induction motor, this controls the speed.

VFD seems quite cool, and I was really close to attempting to build a simple VFD controller using parts from a dead UPS. But then my better senses caught up with me…

So, I was about to settle for this mediocrity and finish off my triac-based controller with some buttons and mounting hardware from HSC, when I randomly happened upon the perfect DC motor. I didn’t know it was perfect at the time, but I had a hunch. As soon as I got it home and sat it next to the original motor, I knew.

New motor, old motor

I was pretty lucky. The speed range was good, the sprocket had the same pitch, and it had plenty of torque at low speeds. The only problem: It’s just barely too large to fit inside the sewing machine cabinet. So, I had to improvise the mounting a bit. I ended up slicing off the bottom panel of the sewing machine, bolting its frame to some scrap pressboard, and mounting the motor using a hacky arrangement of pressboard scraps, screws, and zip ties.

I started out building a simple MOSFET speed controller for the motor, since I’d never used a MOSFET to control an inductive load before. But after spending an hour or two trying to squash transients and convince my FETs to switch at a high enough frequency, I figured I’d had enough pain for one week. I had a spare LMD18200 chip with this project’s name on it.

The LMD18200 is an amazingly versatile and robust little chip. I used it for my laser projector project a while back. It was really overkill for that, but it’s about right for this sewing machine’s beefy new motor. I needed a pretty heavy duty motor drive capacitor too, so I ended up mounting the LMD18200, capacitor, and DC-DC converter in a small metal box for safety reasons. If the capacitor fails, I’d prefer not to have burning hot electrolyte and shrapnel all over my face.

Motor drive and power supply box

Future work?

Enough rambling for now. And I guess I should stop hacking my sewing machine, and start sewing cute things 🙂

I did leave plenty of room in this build for later expansion. I’d like to add some kind of user interface for switching sewing modes. Right now I’m using the USB port for that, but a little LCD with a rotary encoder knob would be just swell. I’ve also thought of other ways to automate the sewing machine to make common tasks easier. For example, it would be useful to have a mode that automatically lifts the presser foot between stitches in single-stitch mode. I already found a good place to mount an RC servo motor for that.

And then there’s the idea of building a CNC embroidery machine around this, using Lego Mindstorms to make the cartesian robot…

Links