Multi-channel PWM ATmega8

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I just need to know wheather my informations are right or not. I was interested in PWM control of RGB LED. So th easiest and most accurate thing is to use 3 PWM channels of ATmega8. But than I realised that 3 channels is not enough, becouse in my other future-planned projects, mainly robots, I will need to precise control of 4 DC motors connected thru Hbridge to change polarity, and maybe even some servos. So, am I right when I thing this can be only achieved using software PWM?

And if it does, isnt ATmega8 even on 16MHz too slow to control for example ten servos? Becouse there is a time limit for pwm input, since in software yoiu will be feedig just one servo at a time. But you know surely better than me. Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
So, am I right when I thing this can be only achieved using software PWM?
On a mega8, yes.
Quote:
And if it does, isnt ATmega8 even on 16MHz too slow to control for example ten servos?
No, it should be able to handle that just fine.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have only a few hardware PWM output pins, but if you connect an external demultiplexer chip, you can then control ten RC servos with single PWM output pin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

But than I realised that 3 channels is not enough

Why not to try atmega88? it's atmega8 with some extras like 6 pwm channels.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for tips. Can I have further question? Is there any way to make software PWM to control brighteness of multiple LEDs? Servo can handle the time between controlling others, but I think you would notice immediate brighteness loss or gain when you switch to PWM other LEDs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's an example of soft PWM:

https://www.avrfreaks.net/index.p...

This is manipulating PC0 but could be any pin or any number of pins.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is worth mentioning that the requirements of LEDs and servos are quite different, despite the fact that they both use PWM. An LED may require anything in a 0-100% duty cycle, whereas a servo is restricted to a .5-1% ( 1-2ms pulse width at 50Hz ) range. Because of these differences the "best" way to generate the PWM signal is different as well. That having been said, there are excellent examples of both floating around the fora here.

Martin Jay McKee

As with most things in engineering, the answer is an unabashed, "It depends."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

.5-1%

5%..10% perhaps? ;-)

(frame time is 20ms, pulse is 1ms to 2ms. 1/20th is 5%)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Software PWM of LED's works pretty well and frees up hardware PWM for more demanding applications. I made a fan controller that used 4 RGB LED's (12 software PWM channels) in the corners of the fan and use one hardware PWM to drive the fan motor. Using interrupts it's pretty easy to do software PWM but it cannot run as high frequency as hardware PWM. For LED dimming you usually don't need very high frequency or super precise PWM so software PWM works.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to do something similar. I have atmega 644P and I want 4 PWM outputs. So far I'm using Timer1, normal mode, let it overflow and use OVF ISR vector to set PinD3 low. Then I use Comp vector to set it high. OCR1A is variable and it's set depending on output from MPU6050 gyroscope. So, when I turn the gyroscope one way, PWM width is larger. But now I have a problem that I can only set OCR1A once. What I need is for example to have interrupt every time when OCR1A is equal to TCNT1. For example, OCR1A=10000, OCR1A=20000, OCR1A=30000. Interrupt vector should fire every time. But of course this is not possible this way. Any suggestions?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PWM modes cause the OCRnx registers to be buffered.  Writes to those registers are buffered but ignored until a specific point in the timer's period (depends on the exact mode), at which point the actual register is updated with the buffered value.

 

If you wan't to be able to update OCRnx arbitrarily, don't use a PWM mode.  Instead, use a non-PWM mode like CTC.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have atmega 644P and I want 4 PWM outputs.

You aren't telling us much.  What is the needed PWM frequency, and needed resolution? A '644 has "Six PWM channels".  You say you need four.   If a critical part of the app, then a '1284 has an additional 16-bit timer.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pololu sells strings of RGB leds on a strip. Each has a WS8212 IC. You can set the RGB level of ea led to 0-255. Thats 16 million colors. Search here for WS2812.

 

Imagecraft compiler user