Wednesday, February 26, 2014

PWM Generator

The PIC16F876 Microcontroller has two precision PWM, Capture and Compare Module in it.  The maximum frequency of the PWM signal is 32,768 Hz, but is easily changed from the minimum frequency (dependent on clock speed) up to 32 KHz.  The Capture and Compare module is based on one of the Timers in the PIC, which drives a 10 bit accumulator in the Capture Module.  Then the Compare Module will drive an output pin high or low depending on the duty cycle register.  The resolution of the PWM is based on the size of the accumulators, and this PIC has 10 bit accumulators, or 1024 bits, so our duty cycle resolution is around 0.1 percent.  Here is a pretty picture...
If we were to compare this to an older PWM Generator based on a NE555 Timer the PIC PWM Generator is extremely precise.  The instruction cycle in the PIC at 4 MHz is 1 uS, and the PWM output can change states within 30 uS.  The NE555 Timer based PWM generators I've built range from 20% to 80% PWM, while the PIC PWM generator can go from rail to rail, 0% to 100%.  I picked a chunky transistor for the output as well.  The IRFZ44 is a 60 Volt, 50 Amp continuous, 200 Amp pulsed MOSFET.  So this PWM generator can directly drive DC motors, or it can be used to control high impedance signal level PWM controls.  Above I think I have the schematic worked out.  Below I am starting to work on the Layout.
The first build is on a protoboard, so I can work out a logical parts placement, and make sure the circuit functions before I make printed boards.  I have already built a few of these, and they are in service.  This copy is going to be my reference design, and I'll be making printed boards after this point.  This means I'll be able to take you through the layout process next.  There is an extra part on the board which is a RS232 Communications Converter.  This is to provide communications to the PC for debug, and adjustments.  There is a tentative plan to make this a Dynamic PWM generator which can be adjusted by a computer interface, or the analog speed control knob.  Probably for the printed design I will switch over to a USB interface to connect to computers that are more modern than my development machine.

No comments:

Post a Comment