Author Topic: pwm help  (Read 1971 times)

0 Members and 1 Guest are viewing this topic.

Offline superchikuTopic starter

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
pwm help
« on: February 24, 2008, 02:42:20 PM »
iam using the atmega16 mcu and i need to control motors but i dont know how to do pwm using atmega16 (registers,functions etc to be used) so i decided to go in a simple way as the admin wrote in some tutorial in which i need to check  the delay of my mcu so i made a sample program and loaded in the mcu but instead of blinking it continuously lit on the source code of my program is as follows
# include<avr/io.h>
# include<util/delay.h>
 int main(void)
{
 unsigned long int i,j;
DDRD=0x40;
while(1)
 {
 
 PORTD=0x40;
   for(i=0;i<1000;i++)
   {
    for(j=0;j<65000;j++){}

 }
PORTD=0x00;
  for(i=0;i<1000;i++)
   {
    for(j=0;j<65000;j++){}

 }
}

return(1);
}
plzz tell me how to rectify this code inorder to know the no of cycles it takes for 1 ms pause so that i can use pwm or u can tell me how i can use pwm the traditional way like wat registers to initialize and wat functions to use(plzz write a small cource code as an example if u decide to say abt pwm)

plzz help me

JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline hazzer123

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
Re: pwm help
« Reply #1 on: February 24, 2008, 02:57:21 PM »
How about using this software - http://www.avrprojects.net/articles.php?lng=en&pg=67

It creates assembly code which delays for the specified amount of time.

To place assembly inside C code, you have to use inline assembly tags - http://www.nongnu.org/avr-libc/user-manual/inline_asm.html

Hazzer123
Imperial College Robotics Society
www.icrobotics.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: pwm help
« Reply #2 on: February 27, 2008, 08:24:11 PM »
Why not just get a motor driver instead? Controlling those are much easier.

If you do a search for PWM in the ATmega16 manual, you will learn more about how to use it.

If you want code, check out AVRlib:
http://www.mil.ufl.edu/~chrisarnold/components/microcontrollerBoard/AVR/avrlib/

and look at the timer.c pwm commands:
http://www.mil.ufl.edu/~chrisarnold/components/microcontrollerBoard/AVR/avrlib/docs/html/group__timerpwm.html

 


Get Your Ad Here

data_list