EmbeddedRelated.com
Forums
Memfault Beyond the Launch

6 PWM, Serial Tx and Rx on Atmel ATmega8 or 16?

Started by macmen_seattle May 21, 2004

I am struggling (newbie) with code that will do the following, say on an ATmega running at
8MHz:

1. PWM for six motors (not servos) running in one direction. 6-8 bit duty cycle resolution
is fine.
2. Sample a few sensors.
3. Receive motor speed commands via serial.
4. Send sensor readings via serial.
5. Kill all motors if no commands are received after X ms.

Seems simple but I can't determine what should be interrrupt-driven and what should be
polled. Using timers alone for the PWM is out (I think) because I need to run six motors.
Run the PWM frequency too high and I consume all of the cycles checking to see if a motor
needs to be started or stopped.

Also need a serial packet protocol to frame the packets. Delay before packet? 8th bit set
on packet header and limit it to 7-bit data? 0xAA as header and then escape it if it appears
in the data?

Your recommendations are welcomed. Sample code would be greatly appreciated. Thank
you in advance.

Greg Schumacher

And now we return you to your regularly scheduled thread....


>>> macmen_seattle@macm... 22/05/2004 10:54:34 am >>>

I am struggling (newbie) with code that will do the following, say on
an ATmega running at
8MHz:

1. PWM for six motors (not servos) running in one direction. 6-8 bit
duty cycle resolution
is fine.
2. Sample a few sensors.
3. Receive motor speed commands via serial.
4. Send sensor readings via serial.
5. Kill all motors if no commands are received after X ms.

Seems simple but I can't determine what should be interrrupt-driven and
what should be
polled. Using timers alone for the PWM is out (I think) because I need
to run six motors.
Run the PWM frequency too high and I consume all of the cycles checking
to see if a motor
needs to be started or stopped.

Also need a serial packet protocol to frame the packets. Delay before
packet? 8th bit set
on packet header and limit it to 7-bit data? 0xAA as header and then
escape it if it appears
in the data?

Your recommendations are welcomed. Sample code would be greatly
appreciated. Thank
you in advance.

Greg Schumacher

And now we return you to your regularly scheduled thread....

---------------------

Rather than struggle trying to do all this in one chip, do you have the
option of breaking down the functions using multiple chips?
For example, using one AVR for each group of 3 motors and then another
AVR for the main control and serial comms?
You could use say a 6/8 bit bus and a few control lines going to each
motor control chip, or use a simple serial protocol between chips.
Many people make the mistake of trying to do too much in the one chip.
Unless you have a compelling reason (cost, board space etc) to use one
chip, your development will be much easier if you use more than one chip
in this application I think.

Regards
Dave :)




Memfault Beyond the Launch