Mini Lathe PWM Controller Repair CJ0618

A few years ago I picked up a broken open box mini lathe from a local tool importer via Craigslist. It was advertised as an unbranded 7×12 digital mini lathe with only a picture and a brief description. I knew it would be the perfect addition for my home shop if I could get it working. It turned out to be a CJ0618B mini lathe, originally manufactured by Real Bull Machine. This lathe is relatively uncommon compared to the ubiquitous Seig C2, making it difficult to find information about it online. It seems to be extremely similar to the Seig C2, though with a lower build quality, fit, and finish.

While the slightly more common CJ0618A model comes with a version of the classic KB controller, the CJ0618B has a custom pulse width modulation (PWM) controller. This PWM controller appears to have closed loop spindle speed control, a feature rarely seen in these low-end mini lathes.

When functioning properly, pressing the start button on the lathe will power a display that indicates RPM, which can be adjusted with the keypad. The spindle motor would start after pressing the forward or reverse buttons. However, when you pressed the forward button on mine, the lathe would do nothing for a few seconds and then beep loudly and flash ‘A001″ on the display. Fortunately the lathe came with a small booklet that explains the operation and fault codes of this controller. This was rather lucky, as I could not find a pdf of this online despite using all my google-fu. I scanned a copy and put it up here:

According to the manual, “A001” is an underspeed error. This occurs when the controller is trying to start the motor, but is either seeing no spindle rotation, or a lower RPM than it was commanding. In my case it was the former.

I took the controller off the lathe to look at the internals and found two printed circuit boards (PCBs): one appeared to be for logic and the other for power. The logic board was labeled MCUPWM8T and had a microcontroller (MCU), a few through hole components, an unmarked IC, and the 4 digit 7 segment LED display. It had three harnesses attached to it, one from the tachometer sensor, one for the buttons, and one going to the other board. The other larger board handles the mains power and performs the DC conversion and switching, labeled KPWT-600B. There were no obvious smoked or failed parts on either board, so identifying and fixing the failure would take a lot more digging.



I took a look at the the overall layout of the power board to get sense of what was going on. Based on the components and their general location, I determined the following layout broken down by key functions:


Power Supply

Much of the board area is dedicated to converting 120 VAC into 5 VDC,12 VDC, and 107 VDC out. The 107 VDC line is created using a large bridge rectifier off mains power and a large filter capacitor. The relay coils are driven by a dedicated 12 VDC tap on the transformer and small rectifier. The 12 VDC of the logic ICs is created from a 18 VDC tap off the transformer. A 78L12 voltage regulator generates the 12 VDC line for the logic ICs. This regulator feeds a LM7805 regulator that powers the microcontroller. My guess for why they have both a 12 V tap on the transformer and a 12 V voltage regulator is so that they could use a smaller voltage regulator to feed only the logic ICs instead of the higher current relay coils.

Motor Control Relays

The power board has two relays: one switches the positive and negative leads going to the motor to control spindle direction and the other is a braking relay. When the braking relay is activated, it disconnects the motor from the controller and shorts a 10 W resistor across the motor leads. This load causes the motor to rapidly brake, slowing it much faster than if you were to just disconnect power and let it freewheel. This is especially useful if you have a large piece of metal in the chuck, as the chuck stops almost instantaneously.

Power Switching

This circuit is the heart of the motor controller.   Pulse width modulation (PWM) is a way to control the speed of a motor by sending short pulses of a constant voltage, rather than raising or lowering the voltage. This allows the motor run at a slow speed while still providing sufficient torque. This is a pretty simplistic explanation, go here if you want a more in-depth answer. The MOSFET is driven with a gate driver, a TLP250 from Toshiba. This IC both isolates the microcontroller from the high voltage MOSFET and switches the MOSFET with a higher voltage and current than the microcontroller could. There’s also a large diode mounted to the same heatsink as the MOSFET. This appears to be a fly back diode to protect the circuit from back EMF generated when the motor is powered off.

Overcurrent Protection

This board uses a LM358P dual op amp to implement the overcurrent protection functionality. One side is used as an amplifier to amplify the voltage measurement taken from a current sense resistor on the controller output. This voltage is very small (<0.5V), which is why the amplifier is necessary. This voltage is proportional to the current draw of the motor; the higher the current draw, the higher the voltage. The other side is used as a comparator to compare the amplified current sense voltage to a reference voltage. There’s a small set of DIP switches that allow you to set the max motor current before the overcurrent protection kicks in. The output from the comparator will either turn on the green “normal” LED and send Vcc to the gate driver IC, or will turn on the red “OP” LED and cut off Vcc to the gate drive IC.

Power Board Control

Fortunately the connector pinout between the logic and power board was labeled so I could pretty easily see how the logic board controls the power board.


The power board supplies 5 VDC and ground to the logic board. The logic board returns a PWM signal and two relay control lines. The logic board also reads the input from the optical sensor mounted to the spindle and converts it to RPM. Since the spindle was not rotating, possible failure modes include

  • Logic board not outputting the PWM signal
  • Power board not switching MOSFET based on the PWM signal
  • MOSFET is switching, but isn’t receiving voltage from power supply
  • MOSFET is switching, but voltage is not making it to motor

Measuring a PWM signal is pretty easy if you have an oscilloscope. I didn’t have one, so I connected the output to an Arduino and wrote a simple sketch to confirm that is was outputting a PWM signal. I later realized that my multimeter, a Fluke 177, has the ability to measure a simple frequency signal like this.

I inspected the RPM sensor mounted to the spindle and found a broken trace on the PCB, which I fixed with some 30 AWG wire. The tachometer sensor is an optical slot switch and was marked as WYC H12A5. I measured the output and found it to be very weak, outputting  <1 V when unblocked. I replaced the switch with a Sharp GP1S53VJ000F optical switch.


While these sensor problems might have been problematic later on, they weren’t the cause of my issue, as the motor wasn’t even attempting to rotate. It seems like the microcontroller will wait for 4 to 5 seconds before throwing the error code. If your lathe turns on, but doesn’t indicate an RPM on the display, and shuts off after a few seconds I would check the output of this sensor at the logic board.

Since the PWM signal was being generated correctly, I decided to check for proper voltages around the board. I found the data sheets for the IC’s and located the Vcc pins for each. I measured around 8 VDC at the gate driver, but the data sheet specified a minimum of 10 VDC. I traced it back to a bad 12VDC regulator and shot off an order to Digikey. A few days later I replaced the failed regulator and powered the controller on.


The input at the logic ICs was now a steady 12 V! My joy was short lived as the controller still gave me the A001 error. However now the red overcurrent protection (OP) LED was on. What was odd was that the LED turned on the moment the controller was powered on. This behavior made me suspect there was something wrong with the circuitry that activates the OP LED, because the light was turning on with no current having gone through the motor.


I traced more of the circuit and found that the op amp output controls power to the LEDs as well as switching power to the gate driver IC. This ensures that the motor stops when the overcurrent protection is activated. I used a digital multimeter to measure the pins of the op amp and found the voltage comparator section of it was not working correctly. The non-inverting input was larger than the inverting input, so the output should have been high, but was reading low. This was causing the overcurrent protection to be activated. Another order to Digikey and I had a new TI LM358P op amp.

When the controller turned on I was greeted with a green LED and no red OP LED! I tried once more to fire up the motor, but alas A001 was staring back at me again.


At this point I started diving deeper into the board to create a schematic of the entire circuit. Despite only being a single layer PCB, this proved difficult because the components are packed very tightly and there are many traces that weren’t visible unless the components were desoldered. A few days of on and off troubleshooting and I began to suspect the gate driver. All the other components between the output of the gate driver and the MOSFET gate seemed fine, but there was never any voltage on the gate pin when the controller was attempting to start up the motor.

The original IC, Toshiba TLP250, has since been discontinued. You can still get them on eBay from China, but I didn’t really want to wait that long. After a little bit of research I found Toshiba had a new gate driver IC, TLP351, that is pin compatible. Another Digikey order later and I had a replacement IC. At this point I wasn’t expecting much given the history of debugging this PCBA, but when I turned on the controller, the motor sprang to life! It was quite a thrill after several weeks of working on this.

I began to play with the motor and speed settings and noticed a weird issue. I wasn’t able to get the rotation direction to reverse. On a lathe sometimes you want the spindle to turn one way or the other, depending on which side of the part your cutting tools is. On this controller if you press reverse while the motor is spinning, it is supposed to ramp down in speed, stop, and the ramp back up in the opposite direction. On mine it would ramp down, stop, and then ramp up in the same direction.

I also noticed the direction control relay would close when the controller was turned on, but would never open when it should have. The same was true of the brake relay, the motor coasted to a stop, instead of being shorted to the braking resistor.

I started to dig back into the power and logic board to see how the relays were controlled. I checked for 12 VDC on one side of the coil and found it on both relays. Tracing back the path to ground it seems the relays are grounded at the logic board. Taking a closer look at the logic board, I found a 8 pin DIP IC with its part number marking intentionally removed, which made investigating this IC challenging. This device was the interface between the microcontroller output pins and the relay coils path to ground. I traced back all the pins and came up with the below schematic:


Using the schematic, it’s evident that this is an IC that controls two 12 VDC relay coils by switching them to ground, runs on 5 VDC, and takes a logic level input from a microcontroller. I also noticed that the input from the microcontroller went to two pins each. I thought this might be some kind of Darlington array transistor, but the pinout didn’t match anything that I could find. Searching around online I stumbled across a list of logic ICs and sorted them by pin count until one caught my eye: a dual 2-input NAND 30 V / 250 mA relay driver. Based on the data sheet, the pinout didn’t match exactly, but it was close.


A little more searching and I found it’s not uncommon to use logic gates (AND, NAND, OR gates) to allow a microcontroller to switch a high current load, like a relay or light. Eventually I came across a NAND gate that matched the pin out: TI SN75451BP Dual Peripheral Driver.


One last order to Digikey and I had a fully functional lathe controller!


Total parts replaced:

  1. 78L12 12VDC voltage regulator
  2. TI LM358P dual op amp
  3. Toshiba TLP250 gate driver
  4. TI SN75451BP NAND Gate
  5. Optical slot switch

Given all of these failed components are ICs, I would guess that some kind of voltage spike or power surge occurred and blew all these components simultaneously.

This repair tested the limits of my board troubleshooting and repair abilities. It was frustrating at times to find and fix issues only to reveal more issues, but I am glad I stuck with it as I now have a fully functionally lathe.

Here are some more photos of the PCBs, some with the components removed so you can see the traces better.




Building a CNC Mill Stepper Driver

When I bought my Sherline mill, it came with stepper motors, but no driver box. The drive box takes the output from a PC parallel port (small electrical signals indicating which axis should move and in what direction).

Drive boxes contain several essential parts:

  1. Power supply
  2. Stepper motor drivers
  3. Break out board
  4. Connectors
  5. Fuses and wiring

I’m kind of particular about the control electronics of a piece of equipment. Control electronics should be layout in such a way that they are easily serviced. Nothing worst than trying to trace down a problem in a rats next of wiring. Below is as list of some practices I like to use when laying out an electronics enclosure.

  1. Components should be spaced to allow airflow around them
  2. Components should be removable without taking out an inordinate amount of other components
  3. Mount components to a removable panel, rather than directly to the enclosure
  4. Wiring should be neatly bundled, using removable wiring loom where possible
  5. Removable connectors are preferred over soldered connections
  6. Wire ferrules should be used when making connections to terminal blocks.
  7. Wiring going to a removable external panel should have extra length to allow the panel to be removed without straining connections (called a service loop)

Finding the right enclosure was probably the hardest part of this project, mostly because I had many criteria.

  1. Mostly made of metal
  2. Top should be removable without taking front or rear panel off
  3. Removable front and rear panels
  4. At least 10″x10″ and ideally ~4″ tall (based on some rough dimensions of the power supply and driver)
  5. Less than $50

I found several enclosures that fit a few of the requirements, such as:

Par-metal table top series. Nice, but too much money.


Circuit Specialists EM Series Price is right, but a little too tall.

em-04-0The one I settled on was from eBay, but I also found it on amazon


This enclosure fit all my criteria. My only gripe with it would be that the front and back panel are plastic and snap in place instead of using screws.

As I mentioned above, mounting components such as drivers and power supplies to a removable panel inside the enclosure makes assembly and service much easier. Parts can be installed and wired on the bench and the panel can be placed into the enclosure in one shot. This is a pretty common practice in industrial control panels. In fact, most enclosure suppliers (like Hoffman) sell panel kits that fit into their enclosures.

I took measurements of the inside of my enclosure and cut a panel out of 0.090″ aluminum sheet. 1/4″ nylon spacers and 8-32 hardware secure the panel to the enclosure. To find the position of mounting holes, I printed out a 1:1 scale outline of the power supply and laid it down next to the driver adjusting their relative locations until I was happy with the clearance.



When it came to the rear panel layout I did use CAD software, as I wanted the connectors to spaced evenly and I needed to make sure I had room to run the wiring. Again, I printed a 1:1 scale drawing with the cutouts and screw holes marked, and traced that onto the rear panel.

controller rear controller inside

A step drill made quick work of the holes for the circular DIN connectors and AC input fuse.


The remainder of the cutouts were made on the mill.

IMG_4428 IMG_4431

A sharp utility knife squared off the corners of this cutout for the power switch on the front panel.


Skipping forward a few steps, the AC input connector and fuse has been installed and wired to the front power switch and power supply.


I used 4 wire 22 gauge shielded security system cable from McMaster to make the internal connections from the driver board to the DIN connectors. Where the wires connect to the Phoenix connectors (also called Euroblocks, those green pluggable screw terminal connectors) I terminated the wires with wire ferrules and heat shrink over the cable covering.


Using wire ferrules instead of bare stranded wire in a screw terminal is good practice, as the strands of wire tend to get broken in screw terminals, increasing the contact resistance.

If you’d like to learn more than you ever probably wanted to about wire ferrules and their use, see this white paper from Weidmuller.



A cable tie mount on the power supply neatly bundles the stepper motor cables.


One last overall shot


At this point I thought I was done. However, my decision to use the 4 axis all-in-one board was bugging me. It’s known to be buggy, and if one axis blew the board could be taken out entirely. In the name of making a more robust driver, I switched to individual axis drivers and a break out board.


The breakout board was pretty easy to mount. 4-40 self tapping screws and nylon spacers secured the board to the enclosure panel. The individual drivers where more challenging. There wasn’t enough room to lay them flat, which meant they need to be mounted on the edge of their heat sink. I thought about a few ways to mount them (screws coming up from the bottom, adhesive, pieces of all thread) before I came up with the idea of using a small strap through the heat sink fin.

Using the same 0.090″ aluminum, I machined some 3/8″x4″ straps, with 1/8″ holes for 4-40 hardware.

Laying out a hole pattern to space the drivers on a 2″ pitch.


First test fit.


Success! The driver is firmly attached, and most importantly, I can remove the driver easily if I need to change setting on the DIP switches. An added bonus is that the heat sink can conduct some of its heat away to the aluminum panel beneath it.

Fortunately the wiring I had made previously for the stepper outputs fit fine, so those did not have to be remade.


Some labels on the back finish the driver box off.



Automated Piston Cycler Device with Arduino

I built this control box to cycle a piston in some of our assemblies at work. We had problems with rebuilt assemblies sticking after a few hours of cycling. The rebuilders couldn’t test this because they would have to manually cycled the piston back and forth many times to verify the functionality (time-consuming). This piston cycler is capable of automatically cycling a dual action cylinder at an adjustable rate, and enable the operator to pause the motion to make adjustments, and continue testing. The counter keeps track of the number of cycles for record keeping purposes. Here’s how I made it.

Continue reading

Electronics Flea Market

While in the bay area this weekend  I stopped at the Electronics Flea Market. This swap meet occurs on the second Saturday of the month during the summer, and is held at De Anza College in Cupertino. The majority of the stuff being sold falls into one of three categories: ham radio equipment from the 40’s, miscellaneous circuit components, and electronics from the 80’s.  In addition,  most of the cliental are either in their 40’s or in their 70’s. I guess the lure of 30 year old test equipment and  tube transistors has a specific audience. At any rate, there were some pretty cool stuff hidden among all the junk.


I had a homework problem in my machine elements course that used this exact gear box.
Continue reading