PWM Generation

Started by Mike Perks April 13, 2005
Since first getting started with BasicX 5 months ago, I have hit my
first real snag. I am generating dual PWM for motor control and now I
want to add an IR remote that needs InputCapture. There is a conflict
because both need to use Timer1 at the same time. This is really more of
a problem with the underlying Atmel chip than BasicX. My brief scan of
the group shows that this problem has not been discussed before.

My solution is to offload the PWM function. Are there other simpler
possibilities?

My requirements for a dual PWM are:
a) Low frequency e.g. 256Hz, higher frequencies cause motor whine and
above 20KHz is unnecessary
b) Control of on/off ratio from 0% to 100% with independent control over
each PWM generator
c) Minimum use of external components where possible
d) Possible later expansion to 4 channel PWM (not essential requirement).

I am considering the following options for PWM generation:
1) Comparator oscillator and comparator with SPI potentiometer to
control on/off ratio. For an example see http://www.4qdtec.com/pwmmod.html
2) 555 timer astable and comparator with SPI potentiometer (e.g.
http://casemods.pointofnoreturn.org/pwm/circuit3.html )
3) Programmable chip solution on say a Atmel 2313 that supports multiple
PWM outputs with bit-banged SPI or TWI as the uC interface. For an
example see http://www.awce.com/pak5.htm although COM3 interfacing will
not work as it also conflicts with Timer1.

Does anyone have experience with this type of circuit or can make
recommendations?

TIA
Mike


Hi Mike,

You could just use 2 BX-24's. Various simple serial protocols could provide inter-communication.

Eric
----- Original Message -----
From: Mike Perks
To: BasicX Yahoo Group
Sent: Wednesday, April 13, 2005 12:11 PM
Subject: [BasicX] PWM Generation

........My solution is to offload the PWM function. Are there other simpler
possibilities?..............


Eric,

Yes I thought of that too but it seems overkill (unless I need a whole
bunch of I/O processing). A few comparators and resistors should do the
job - I have NE556 and KA339 in my parts box already as well.

Mike

> Hi Mike,
>
> You could just use 2 BX-24's. Various simple serial protocols could
> provide inter-communication.
>
> Eric
> ----- Original Message -----
> From: Mike Perks
> To: BasicX Yahoo Group
> Sent: Wednesday, April 13, 2005 12:11 PM
> Subject: [BasicX] PWM Generation
>
> ........My solution is to offload the PWM function. Are there other
> simpler
> possibilities?..............
>




--- In basicx@basi..., Mike Perks <basicx@a...> wrote:
> [...] COM3 interfacing will not work as it also conflicts with Timer1.

I don't think Com3 conflicts with the use of Timer1 per se. Rather,
the problem is that many functions that use Timer1 also disable
interrupts thereby causing a potential problem with Com3.

According to the manual, if you are transmitting only and ensure that
all data has been transmitted before you invoke the conflicting I/O
routine, all is well.



re: PWM Motor Control

Mike, while I've designed lot's of H-Bridges and wrote lot's of code
on PICs, in the case of my current Robot project, I decided to
'farm-out' both PWM motor control and servo control (for Tilt and Pan
of a sensor platform) to Pololu's SMC02B and SSC02A's controllers. In
my case, I need to free-up the BX-24 for 'hardcore' FP math for
navigation and image recognition. I'm not sure of your requirements
but I reached a point where cost was trivial.

- Tom


Tom,

I'm going to send you a PM on what I have been doing as I think it might
be off-topic somewhat. We can always post the result.

For me there is a tradeoff between buy versus build. Obviously I don't
build logic gates out of transistors but equally I don't always buy
stuff off-the-shelf. So far I'm getting a great deal of satisfaction
building my own stuff because it turns out to be cheaper and have more
function than buying as shown by my BasicX/AVR development board and ISP
programmer. However I am a Software Engineer and so some of hardware
stuff gets a little beyond my reach. If I was charging my time to a
client then I would definitely buy but it's a hobby and a learning
experience so I don't mind.

Mike
http://home.austin.rr.com/perks/basicx/
http://home.austin.rr.com/perks/basicx/DevelopmentBoard.htm

>
> re: PWM Motor Control
>
> Mike, while I've designed lot's of H-Bridges and wrote lot's of code
> on PICs, in the case of my current Robot project, I decided to
> 'farm-out' both PWM motor control and servo control (for Tilt and Pan
> of a sensor platform) to Pololu's SMC02B and SSC02A's controllers. In
> my case, I need to free-up the BX-24 for 'hardcore' FP math for
> navigation and image recognition. I'm not sure of your requirements
> but I reached a point where cost was trivial.
>
> - Tom





Mike, I've got your e-mail and have had an initial look at your
links. You 'dropped a lot on my plate' ;-)

My first question is why all the 'glue' logic? This seems to be way
too complicated for such a simple task even with monitoring motor
stall current. I have no experience with the L6205N but after
glancing over the data sheet, I will probably order some for my
projects. One thing that 'caught my eye' was it's thermal shutdown
mode and the ability to monitor it. I think you can eliminate a lot
of analog 'glue' by monitoring the "EN" pin. As far as optoisolators,
I just can't see a need for them in this application if you use a
sepatate supply for the motors and good grounding practice. Again,
I've just had a 'glance' at your design but if you want wheel
feedback, I would use shaft encoders, not relying on measuring back-
EMF.

The bottom line... I'm impressed with your effort (we hardware guys
normally don't trust software guys with a soldering iron ;-). But I
just can't understand why all the extra 'glue'...

- Tom

--- In basicx@basi..., Mike Perks <basicx@a...> wrote:
> Tom,
>
> I'm going to send you a PM on what I have been doing as I think it
might
> be off-topic somewhat. We can always post the result.
[snip]


Just to recap, I am using the builtin PWM on BasicX but I discovered
that I will have a conflict with InputCapture so it looks like I will
need to build my own PWM generators. I don't think I got a full answer
to the best choice so I guess I will be experimenting. This circuit
looks the most promising:
http://casemods.pointofnoreturn.org/pwm/circuit3.html

My original append also resulted in questions about what I am trying to
do so I sent Tom Handley a PM with my schematic for a motor controller
and some questions. So for everyone's sanity to keep track of this
thread I have posted the schematic here:
http://home.austin.rr.com/perks/basicx/Projects/Motor%20Controller.pdf.

To answer Tom's question below - I have 3 pieces of glue logic:

1. Combinational logic gates that convert the sign/magnitude and brake
signals to the appropriate inputs to the L6205N chip. However I think
I'm misusing the Enable pin by sending PWM through it. I have an
improved circuit that basically always enables the L6205 and sends the
PWM through In1 and In2. Unfortunately it takes 12 Nand gates to do it
(or I could use 6 Ands, 4 Ors and 2 inverters). Tom Becker - I think I
need one of your FPGAs :)

2. Current sensing logic that compares the sense resistor voltage and
uses a comparator schmitt trigger to signal the BX-24. The idea is that
if the motors get stalled, I want to know about it and cut the power to
prevent burnout. For the cost of a few chips this seems better than the
alternative - diving across the floor to rescue it. The L6205 has some
built-in prevention as well like thermal cutout (which I experienced
while testing the circuit) but why not prevent it before it occurs i.e.
I looking for too large a current (motor stall) versus overcurrent (short).

3. Opto-isolators that allow 2 different voltage supplies - one for the
BX-24 and one for the motor controller. I have heard that noise can
travel through ground as well so I wanted complete ground isolation.
Does anyone have a definitive answer for me about ground isolation for
motors - I would prefer not to have to go back and fix it later when my
IR receiver, line detector or whatever doesn't work very well because of
ground jiiter.

Please let me know if you have any sage advice on all of this.

TIA
Mike

>
> Mike, I've got your e-mail and have had an initial look at your
> links. You 'dropped a lot on my plate' ;-)
>
> My first question is why all the 'glue' logic? This seems to be way
> too complicated for such a simple task even with monitoring motor
> stall current. I have no experience with the L6205N but after
> glancing over the data sheet, I will probably order some for my
> projects. One thing that 'caught my eye' was it's thermal shutdown
> mode and the ability to monitor it. I think you can eliminate a lot
> of analog 'glue' by monitoring the "EN" pin. As far as optoisolators,
> I just can't see a need for them in this application if you use a
> sepatate supply for the motors and good grounding practice. Again,
> I've just had a 'glance' at your design but if you want wheel
> feedback, I would use shaft encoders, not relying on measuring back-
> EMF.
>
> The bottom line... I'm impressed with your effort (we hardware guys
> normally don't trust software guys with a soldering iron ;-). But I
> just can't understand why all the extra 'glue'...
>
> - Tom


... There's an eight-bit PWM available from Timer2 on pin 25, but not dual PWM...

> ... a conflict with InputCapture...

There's an eight-bit PWM available from Timer2 on pin 25, but not dual
PWM like Timer1 offers. I just moved a 112Hz DC motor PWM to Timer2 so
I could use Timer1 as a 16-bit internal timebase. Somehow it feels nice
to have three timers running. Tom
Tom Becker
--... ...--
GTBecker@GTBe... www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700


Tom,

Good idea but as noted in my original append, I really need two
independent PWMs (one for each wheel) otherwise turning gets a bit hard
- not quite impossible but hard.

> > ... a conflict with InputCapture...
>
> There's an eight-bit PWM available from Timer2 on pin 25, but not dual
> PWM like Timer1 offers. I just moved a 112Hz DC motor PWM to Timer2 so
> I could use Timer1 as a 16-bit internal timebase. Somehow it feels nice
> to have three timers running. > Tom
>