Machine Shop Home

Etude for PWM and FET

I wanted to see what a minimum set up would be for running a DC brushed motor using a software PWM signal from a parallel port pin and LinuxCNC.

The schematic of one configuration is to the right. The gEDA file for the schematic is here: pwm_fet-2c.sch (you may need to right click and use "Save Link As...")

The opto-isolator is used to translate the parallel port signal at 5 Volts to 15 Volts to drive the FET gate. The FET is specified as a logic level FET, but I found that the FET tended to run cooler with a higher gate voltage. The input should also have a standard diode added in series with the LED, LED1, and opto-isolator, U1. A standard diode has a much higher reverse voltage tolerance and protects the LED and opto-isolator in case the input sees a reverse voltage. The input resistor, R1, should be sized for something around 10mA across the three diodes, so V = I R, or V / I = R = (5 - .6 - .6 - .6) / .01 = 320 Ohms. R2 is a current limiter to protect the opto-isolator transistor (sized for 30mA, but may be conservative) while it charges the FET gate. R3 sinks the charge away from the gate when the opto-isolator turns off. You can see from the oscilloscope trace that R3 is pretty slow, but making R3 smaller will also reduce the gate voltage (due to the voltage divider configuration). D1 is a freewheel diode and is required in order to keep the voltage on the FET drain from getting to high when the FET turns off and the motor turns into a generator. I blew out the first FET because I thought I could get away with not having this diode. The diode should be a high speed or Schottky type which runs cooler. R4 is optional, but I used it with the oscilloscope to see what was going on with the current during FET switching and under different motor loads.

The upper scope trace shows the current sense voltage. The voltage is zero while the FET is off and the free wheel diode is allowing the motor to coast. The ramp is the voltage due to the current going through the FET and allows the motor supply to drive the motor. When I put a load on the motor this ramp moves up according to V = I R or V / R = I = Vscope / .1 Ohm. I have an Ammeter on my motor supply, and had it up to 5 Amps, but this is average current, so the peak amperage would be much higher and depend on the PWM duty to some extent.

The lower trace is the gate voltage. This is at a PWM duty setting of 20%. You can see the trailing edge curves a bit. The FET heats up during the time between being on and off, so the sooner we can get the gate down to zero the better. Actually, now I seem to recall that the opto-isolator input has the same off curve, so it's the parallel port pin that is probably a bit slow. Anyway, we have a way to fix it.


Copy the .hal and .ui files to a directory, open a terminal and cd to the directory, invoke with "halrun -f pwmfet.hal"

pwmfet.ui

pwmfet.hal (you may need to right click and use "Save Link As...")


# halrun -f pwmfet.hal

#loadrt threads name1=fast period1=50000 fp1=0 name2=slow period2=1000000
loadrt threads name1=fast period1=10000 fp1=0 name2=slow period2=1000000

loadrt hal_parport cfg="0x0378 out"
#loadrt hal_parport cfg="0xDCF8 out"

loadusr -Wn pwmfet gladevcp -c pwmfet pwmfet.ui

loadrt pwmgen output_type=0
loadrt conv_float_s32 count=1

addf  parport.0.read            fast
addf  pwmgen.make-pulses        fast
addf  parport.0.write           fast

addf  pwmgen.update             slow
addf  conv-float-s32.0          slow

setp  pwmgen.0.max-dc         1.0
setp  pwmgen.0.min-dc         0.0
setp  pwmgen.0.scale        100
setp  pwmgen.0.offset         0.0
setp  pwmgen.0.dither-pwm     0

net pwmen     pwmfet.hal_togglebutton1  pwmgen.0.enable       pwmfet.hal_led1
net pwmval1a  pwmfet.hal_hscale1        pwmgen.0.value
net pwmout    pwmgen.0.pwm              parport.0.pin-02-out
net pwmfreq1  pwmgen.0.pwm-freq         conv-float-s32.0.in
net pwmfreq2  conv-float-s32.0.out      pwmfet.hal_label1

sets pwmfreq1  4000

setp pwmfet.hal_table1 1
setp pwmfet.hal_table2 1


start

waitusr pwmfet

stop

unload all
        




Machine Shop Home

Pages Created by Kirk Wallace
kwallace@wallacecompany.com

Copyright © 2014 WALLACE COMPANY
Rev. Date: 2014/11/28 11:19 UTC KW