
I tried so many times but thats not controling the LED brightness. please help me .....
Hi Umadevi,
What method's have you tried to control the brightness of an LED with the atmega8?
With the atmega8, there's a couple options.. Using the PWM channels, or just using regular i/o with a timing loop turning on/off the port pins..
Regards,
Setting up timers are the best. Example code:
#include <avr/io.h>
#include <util/delay.h>
/*
* Assumptions:
* - LEDs connected to PORTB.7 and PORTB.6
*/
int main (void)
{
/* Waveform Generation Mode 3 - Fast PWM */
TCCR0A |= _BV(WGM01) | _BV(WGM00);
/*
* Compare Output Mode - fast PWM
* Non-inverting mode drives the output high while the counter
* is greater than OCRNx. Inverting mode drives the output low
* while the counter is greater than OCRNx.
*/
TCCR0A |= _BV(COM0A1) | _BV(COM0A0); /* inverting: fade down */
TCCR0A |= _BV(COM0B1); /* non-inverting: fade up */
/* reset all the timers and comparators */
OCR0A = 0;
OCR0B = 0;
TCNT0 = 0;
/*
* Clock Source 1 - CLK. Setting this bit late allows us to
* initialize the registers before the clocks start ticking
*/
TCCR0B |= _BV(CS00);
/*
* Arduino pins 5 & 6 (PORTD.5 and PORTD.6) are PWM driven by TIMER0
* "The setup of the OC0x should be performed before setting the Data
* Direction Register for the port pin to output." -- S14.5.3
*/
DDRD |= _BV(PORTD5) | _BV(PORTD6);
while (1){
/*
* slowly crank up the compare register. since one output
* is inverting, the net result is to fade from one channel
* to the other.
*/
OCR0A++;
OCR0B++;
_delay_ms(10); /* busy wait. could be done with timers too. */
}
return 0;
}Thanking you Richcj,
But when I executing this program in AVR Sudio4 software it shows 11 errors. I don't know that how we can solve this. Can you suggest me..for how to solve.
I am sending the errors message what I got while executing..
those are,
Build started 27.3.2012 at 18:55:12
avr-gcc -mmcu=atmega8 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT control_brightness.o -MF dep/control_brightness.o.d -c ../control_brightness.c
In file included from ../control_brightness.c:2:
c:/winavr-20090313/lib/gcc/../../avr/include/util/delay.h:85:3: warning: #warning "F_CPU not defined for <util/delay.h>"
../control_brightness.c: In function 'main':
../control_brightness.c:12: error: 'TCCR0A' undeclared (first use in this function)
../control_brightness.c:12: error: (Each undeclared identifier is reported only once
../control_brightness.c:12: error: for each function it appears in.)
../control_brightness.c:12: error: 'WGM01' undeclared (first use in this function)
../control_brightness.c:12: error: 'WGM00' undeclared (first use in this function)
../control_brightness.c:20: error: 'COM0A1' undeclared (first use in this function)
../control_brightness.c:20: error: 'COM0A0' undeclared (first use in this function)
../control_brightness.c:21: error: 'COM0B1' undeclared (first use in this function)
../control_brightness.c:24: error: 'OCR0A' undeclared (first use in this function)
../control_brightness.c:25: error: 'OCR0B' undeclared (first use in this function)
../control_brightness.c:32: error: 'TCCR0B' undeclared (first use in this function)
make: *** [control_brightness.o] Error 1
Build failed with 11 errors and 1 warnings...
thanking you,
with Regards,
G. Uma Devi
may I know which micro controller we can use for this program ? I am using Atmega 8. So I changed the Timer0 as Timer1. Now the program is working. Thank u.
any Atmel part...That's the beauty of AVR C code .... this was for a Atmega 644p
Sorry for messing up the timmer. I looked at the data sheat quick and tought you had a timer 0 opps....
Ok sir, Thank u for your valuable message for me. I will check the program by hardware.
I want to design the circuit for propeller clock which I saw from you tube. can u suggest me for how to develop that and what kind of hardware we can use and what are the topics we should cover for build the software program? please if you have any idea, suggest me please...
Privacy Statement | Terms & Conditions | Careers | webmaster@digikey.com |
|
701 Brooks Avenue South, Thief River Falls, MN 56701 USA Phone: 1-800-344-4539 or 218-681-6674 or Fax: 218-681-3380 |
|||||||||

Quick Links:














