avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] PWM newbie problem


From: Steve Turner
Subject: [avr-gcc-list] PWM newbie problem
Date: Thu, 18 Mar 2004 15:29:42 -0700

Hi everyone,
    I am just starting with the AVR's. I have a program to control an LED using 
PWM with 2 switches (4 possible values). I am using the STK-500. I can't seem 
to find any problems with the program, but the LED appears to be fully lit no 
matter what I press. Any observations would be appreciated. 

Steve Turner
Fort Collins, CO
SteveOnWeb.Com

#include <avr/io.h>

void ioinit (void)
{
 DDRC = 0x00;  // Make inputs 
 DDRD |= (1<<5); // Make OCR1A output
 TCCR1A=0x91; //compare A for non-inverted PWM and 8 bit resolution
 TCCR1B=0x02; //clock / 8 prescaler
}

int main (void)
{
 ioinit();
 unsigned int oldtogs; //storage for past value of input
 oldtogs = 0;

 while (1) // Loop forever
 {
  
  if (PINC != oldtogs)
  {
   oldtogs = PINC; //save toggle switch value
   switch (PINC)
   {
    case 0:
     OCR1A = 25; //10% duty cycle
     break;
    case 1:
     OCR1A = 51; //20% duty cycle
     break;
    case 2:
     OCR1A = 76; //30% duty cycle
     break;
    case 3:
     OCR1A = 102; //40% duty cycle
     break;
   }
  }
 }
}
_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list


reply via email to

[Prev in Thread] Current Thread [Next in Thread]