I gave up using PWM for a digital to analog converter and bought a real=20 10-bit DAC. On 11/16/2012 3:00 AM, David Meiklejohn wrote: > As some of you will know, I write (and sell) PIC tutorials: > www.gooligum.com.au/tutorials.html. > > =20 > > I've just started working on a PWM lesson, using the 16F684, and am think= ing > about what examples to include - and I'd really appreciate any > thoughts/feedback! > > =20 > > Simple single-output PWM is easy enough. To show the effect of changing > duty cycle, dimming an LED works well. And to show the effect of changin= g > period, using the PWM output to drive a piezo speaker is effective - I've > written a little example that changes the frequency as a pot is adjusted. > > =20 > > Simple (no dead band) half-bridge output is also easy to demonstrate - > driving a piezo push-pull fashion makes it obviously louder. > > =20 > > However - people want to know how to drive motors. I've had requests for > tutorials about driving RC servos, but I think I'd do that as a separate > topic. Just good old-fashioned brushed DC should do to start with. > > =20 > > Motors aren't quite as simple to drive as an LED though, and this is wher= e > I'm wondering what the best approach is. > > =20 > > For single-output, I could specify a MOSFET and flyback diode, or a motor > driver such as an L293D. Any thoughts? > > =20 > > For half-bridge motor control, I'm thinking that the L293 is the way to g= o. > The two complementary PWM outputs on the PIC connect to two inputs on the > L293, with the motor between the L293's outputs. It would go full speed > forward with 100% duty cycle, stop at 50%, and full reverse at 0%. That'= s > the theory, anyway. I've never used a half-bridge PWM for motor control > before. That arrangement seems quite inefficient, because it's pushing > current through the motor 100% of the time (50% one way, then 50% reverse= d), > even when its stationary. That also seems to be true of the "half-bridge > output driving a full-bridge circuit" shown in the 16F684 data sheet. Am= I > right? But does it work well enough anyway? > > Also I'm not sure, if I go with the L293 arrangement, whether dead-band > delay is relevant. It certainly would be best to mention it in any > tutorial, and I understand about shoot-through current and can explain wh= y > that's to be avoided, but if I'm not using MOSFETs to build a half-bridge= , > is there any practical way to explain the potential need for dead-band > delay, that relates back to the L293 circuit? > > =20 > > As for full-bridge, I'm leaning toward using discrete MOSFETs, although i= t > would end up being a little cumbersome if breadboarded. I'm assuming > P-channel on the high side and N-channel on the low, to avoid the need fo= r > drivers - that for a low-power (small hobby DC motor) app, the 20 mA that > the PIC pins can supply is adequate to switch logic-level MOSFETs quickly > enough. I'm also wondering whether, in a low-power application like that= , > the MOSFET's body diodes will be able to handle the flyback current, or i= f > external diodes are necessary. My aim, since this is a tutorial on using > PWM, is to keep the electronics as simple as possible, but no simpler. B= y > the way, I'm assuming a single 5V supply for PIC and motor, but obviously > with some decoupling around the motor. Again, not designing for field > reliability, just a simple lash-up, but I don't want the PIC resetting ev= ery > few seconds due to power supply noise, either. > > =20 > > Does any of this make sense? Anyone have any better suggestions on > demonstrating PWM in a simple way, that doesn't use a lot of hardware tha= t > students may not have (or buy cheaply)? > > =20 > > =20 > > Thanks in advance, > > =20 > > David Meiklejohn > > www.gooligum.com.au > > =20 > > =20 > --=20 John Ferrell W8CCW That which can be destroyed by the truth should be. P.C. HODGELL --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .