Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

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

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

2004-05-24 by macmen_seattle

I am struggling (read: 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  
n 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....

Re: [AVR-Chat] 6 PWM, Serial Tx and Rx on ATmega8 or 16?

2004-05-24 by Richard Reeves

> 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.
Bear with me, I might not explain this well...
When I played with software PWM once, I did it as per attached code.
Basically, I use a timer to generate a master clock, on which I 
increment all the registers holding the PWM counts.  If any hit zero 
or the limit, their respecive bits are set or cleared.  Someone I 
gave the code to fairly recently had it working, I think.
 
> 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? 
That's how MIDI works.  I've got some code somewhere I used to decode 
some MIDI messages, I think.



Richard
---
"Iz dana u dan ona dolazi i odlazi u talasima"
   http://www.van-gogh.co.yu/

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.