Thread: ATMEGA16 PWM
View Single Post
  #5   Spotlight this post!  
Unread 07-04-2006, 12:00
Don Reid Don Reid is offline
Registered User
#0997
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Corvallis, Oregon
Posts: 45
Don Reid will become famous soon enough
Re: ATMEGA16 PWM

Quote:
Originally Posted by sparksandtabs
Usually from what I have seen for the atmegax series you can use any code from a lower processor on a higher level processor with out changing register names. I don't know if it is true but I guess I can try your code and find out.
When a newer processor add resources the register names may change, for example with one UART there is UBRRL, but with 2 UARTS there is UBRR0L and UBRR1L.

Quote:
What compiler do you use?
I use avr-gcc on Linux

Quote:
I am going to look at some things but do you think it will be safe to hook the servo up to the STK500.
I don't think a 5V logic signal can hurt a servo even if it doesn't like the timing. The power to the servo needs to come from a source that can supply enough current.

Quote:
wow....that is above my reading level. If possible seeing as how I am a begginer would you mind commenting some, I mean most of that code. I have never seen the #endif and all those # commands before other than #include and #define Could you possible offer an explanation?

Also I need "main.h" and "stdint.h"
The #ifdefs include or don't include parts of the code for different purposes. the SIM set creates a version that runs on a workstation and simulates the behavior. The pwm simulation isn't very interesting, it just returns the setting multiplied by a constant. The PWM_INT set causes an interrupt every cycle.

You should look at the register settings this code does, and look at the manual sections for those registers to understand how it uses the timer to do PWM. Then you can write you own code or modify this to do what you want.

main.h isn't very much:

Code:
#define F_CPU 14745600UL

extern int direction;	// 1 = right side, -1 = left side (reverse)
stdint.h is part of the standard C library. It came with avr-gcc. You can do without it by changing "uint8_t" to "unsigned char" etc.
__________________
Don Reid