Re: Update on PWM Generation

Started by Mike Perks April 17, 2005
Here is an update on a question I posted a few days ago about
alternatives to the builtin PWM generators in BasicX. I wanted IR remote
capability via InputCapture and this also uses the same Timer1 required
for PWM generation.

My solution for now (until I get more experience in AVR programming) is
to use some analog circuits to generate the PWM and then OR in the PWM
pulses into the motor control circuitry for direction and braking. I
implemented the circuit I also posted below
( )
<> and selected the
PWM ratio using a dual SPI digital potentiometer (MCP42010). I can
report that this circuit works extremely well. I fixed the frequency at
80Hz but other frequencies should work fine.

I then rewired my control circuitry so that a single Enable wire is used
to enable/disable the H-Bridge controller (L5205) and the direction,
braking and speed (PWM) from the BX-24 are used to drive the In1 and In2
inputs for each H-bridge. In all I use 5 output pins on the BX-24
(Enable, DirectionA, DirectionB, Brake, SPI Chip Select). There are an
additional 3 input pins used for over current detection and interrupt.

Lastly I hooked up my 38MHz IR receiver to BX-12 InputCapture pin and
then reused some previous command code software from my IR clock
project. The upshot is that now everything works. The robot can dance
and twirl on demand. I have a lot more testing to do but I can say that
I reached a major milestone.

My next task is to take some of the 9 chips and circuitry off the
breadboard and onto a more permanent circuit. Meaning I get to do some
soldering :) After that it's time to work on some sensors.

For other people who have done this before you are probably wondering
what all the fuss it about. For me being relatively new to BasicX and a
Software Engineer, this is a big deal. And the BasicX platform made this
so much easier to do. I would have spent much longer getting native AVR
C code working and wondering if it was my code or my poor hardware design.

I hope this was helpful and may give you some inspiration on your
project even if it is unrelated. If people are interested, let me know
and I will write it up and post it on my website.


> 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
> 2) 555 timer astable and comparator with SPI potentiometer (e.g.
> )
> 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 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?
> Mike