Pulse Width Modulation (PWM) is an electronic means of controlling power to a load such as a DC motor, lamp or LED. The basic idea of PWM is that by applying maximum voltage to a load for only a fraction of a period of time - relating to the PWM frequency - the result will be an average voltage being delivered to the load which is proportional to the PWM duty cycle.
I created a simple adjustable PWM control that has a range of 0 to 100%. The duty cycle can be adjusted in either 1% or 0.1% increments. There are eight different selectable PWM frequency values; 31Hz, 62Hz, 125Hz, 250Hz, 500Hz, 1000Hz, 2000Hz and 4000Hz. The output driver can supply up to 1.5A at 15VDC.
MICROCONTROLLER CIRCUIT
The microcontroller used was a FREESCALE MC9S08D4. Timer channel 0 was configured to provide edge aligned PWM. The frequency (period) of the PWM output is determined from the value in the timer modulus register (TPMMOD). In this case, 1000 was chosen to provide 1000 steps in the PWM range from full off to full on.
The PWM frequency is varied by changing the timer clock divisor value. The timer modulus register always remains at 1000.
The duty cycle is determined by the value in the timer value register (TPMC0V). A value of 0 in the timer value register will result in a duty cycle of 0%. A value greater than the modulus (1000) will result in a duty cycle of 100%.
Also, there is a bicolor LED that provides a visual indication of the PWM output, changing from red at either FULL OFF or small PWM values to yellow at intermediate PWM values to green at either FULL ON or high PWM values.
A green LED (PTA4) is provided to indicate when the PWM output is either at a value of exactly 50% or is at a value of exactly 100% (FULL ON).
A hardware interrupt (IRQ) controlled by a pushbutton switch is used to select both the PWM frequency and the PWM increment value of either 1% or 0.1% in an alternating fashion. When a new frequency is selected, the increment value is set at 1%. Pressing the pushbutton again will keep the same PWM frequency and duty cycle but the increment value is changed to 0.1%.
Pressing and releasing the pushbutton will scroll the frequency selection from 31Hz to 4000Hz in eight steps alternating with the increment value and then the selection will loop back to the starting point (31Hz) and repeat. A yellow LED (PTA3) is used to indicate when the increment value is at 0.1%.
A BOURNS PEL12S lighted encoder is used to adjust the PWM value by changing the timer value register (TPMC0V). I used the keyboard interrupt (PORT PTA1/KBIP1) connected to the “A” output. The “B” output was connected to PORT PTA2. The interrupt function compares the pre-interrupt encoder value (located in main function) to the encoder value found during the interrupt routine. There are four switch / case statements to determine if the rotation is clockwise or counter-clockwise and also increments or decrements the PWM value by either 10 (1%, yellow “RATE” LED off) or 1 (0.1%, yellow “RATE” LED on).
OUTPUT DRIVER
The output driver consists of a 4N37 optoisolator which provides complete isolation between the microcontroller circuit and the output load. This also allows the load to have its own power source separate from the microcontroller power supply. The 4N37 output provides gate drive to a pair of 2N7000 MOSFETS in parallel.
The MOSFETS supply the base drive to a 2N3055 power transistor. A 50 ohm 3W resistor limits the base current to about 300mA at 15VDC. The 2N3055 controls the ground side of the load.
A PTC fuse rated at 1.6A (3.2A TRIP) provides load protection. A load switch allows disconnecting the load without having to change the PWM value.
MICROCONTROLLER CIRCUIT (PDF)
OUTPUT DRIVER CIRCUIT (PDF)
PWM CONTROLLER PCB
FINISHED PCB
No comments:
Post a Comment