Yahoo Groups archive

AVR-Chat

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

Message

Re: [AVR-Chat] Can someone double check my assumptions ATMega128 PWM

2005-01-29 by Brian Dean

On Fri, Jan 28, 2005 at 06:54:31PM -0500, wbounce wrote:

> void initmotor(void)
> {
> OCR3A = 0;
> OCR3B = 0;
> 
> TCCR3A = BV(WGM31) | BV(WGM30) ; /* set timer/counter 3 to fast PWM mode
> 7 */
> TCCR3A |= BV(COM3A1) | BV(COM3B1); /* Clear OCnA/OCnB/OCnC on compare
> match when up-counting. */
> TCCR3B = BV(CS30) | BV(WGM32) ; /* prescale: 1 @ 16 MHz, 10 bit PWM
> overflows @ 15625 HZ */
> 
> // turn everything off
> OCR3A = 0;
> OCR3B = 0;
> 
> DDRE |= BV(PORTE3)|BV(PORTE4); /* enable PWM outputs */
> }
> According to how I read the data sheet this should be setting up
> (Page 133) Mode 7 fast PWM 10 bit with no prescale which should give me
> 15.6K PWM
> 
> And setting COM3A1 and COM3B1 should turn the pin to 0 when the counter
> hits the value I set in OCR3A or OCR3B?
> 
> Is this COM3A1 part correct?

Your code looks correct.  Do you have a scope to double check the
output waveform?

-Brian
-- 
Brian Dean
BDMICRO - ATmega128 Based MAVRIC Controllers
http://www.bdmicro.com/

Attachments

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.