Sign in

username:

password:



Not a member?

Search avrclub



Search tips

Subscribe to avrclub



avrclub by Keywords

AT90S2313 | AT90S8515 | ATMega | ATmega128 | ECL | FETS | IAR | Keyboard | LCD | STK50 | TMOS | UART

Ads

Discussion Groups

Discussion Groups | AVRclub | Re: LED brightness control using PWM

Atmel AVR Microcontroller discussion group.

LED brightness control using PWM - nandak84 - Nov 29 23:34:00 2005

Hey guys,
I am new to Microcontroller programming and would really appreciate if
you guys can direct me to learn about AVR Atmega88 programming.
I have been given a task of controlling the LED brightness using PWM
signals, and I have not been very successful at it.

I am using AVR Studio 4 in Windows and I have an AVR evaluation board
i.e. starter Kit with all the different slots for any Atmel micro.

Please Help me. Thank you for your time and effort.
Cheers
NK




(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )


Re: LED brightness control using PWM - ekow - Nov 30 1:26:00 2005

You can read a nice tutorial at http://www.avrbeginners.net/ .
there is a sample program to control led brigthness with PWM,
but using another AVR AT90S2313
you can easily modif the code for atmega88.

ekow





(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

LED brightness control using PWM - Francois Rigaud - Nov 30 11:59:00 2005

Hello,
> Subject: LED brightness control using PWM

> I am new to Microcontroller programming and would really appreciate if
> you guys can direct me to learn about AVR Atmega88 programming.
> I have been given a task of controlling the LED brightness using PWM
> signals, and I have not been very successful at it.

This is a pascal E-lab listing
this soft, for example, make à pwm with the value of 3 trimers,
connected on port ADC
Device: Tiny 26 with Phase lock loop (pll) 64 MHz
trimers 1 and 2 : small and big gain adjustement
trimer 3 : % pwm
Maybe with small change you're making you're projects

Maybe there are a small bog when scanning frequency with trimer
but this software make what i want.

An option, are to use codevision demo, freeware
because codewizard (automatic programme generator) is
simple and efficiency for specify register .....
You need to read Atmel datasheet.
---------------------------------------------------
program gene_pwm;
{ $W- Warnings} {Warnings off}

{$DEBDELAY} // shortens the mDelays in the Simulators by 90%
Device = Tiny26, VCC=5;
Import SysTick;
From System Import longword ;
Define
ProcClock = 14745600; {Hertz}
SysTick = 1; {msec}
StackSize = $00016, iData; // la puce est un peu petite pour
faire ça
FrameSize = $00016, iData;
Implementation
{$IDATA}
var adc_conv_finie[@ADCSR,4]:bit; // @ADCR,4=ADIF
adc_result[@ADCL]:word; // pour lire directement ADCL et
ADCH
adc0, adc1:word;
freq:longword;
larg:word;
//freq_exacte:longword;
{--------------------------------------------------------------}
{ functions }
procedure InitPorts;
begin
PortA:= %00000000; DDRA:= %11110000;
PortB:= %00000000; DDRB:= %00001111;
TCCR0:=0; // timer 0
TCNT0:=0;
PLLCSR:=%010; // PLLE = 1
{$X-} while not bit(PLLCSR,0) do EndWhile; {$X+}
setbit(PLLCSR,2,true); // enable 64 MHz
TCCR1A:=$42;
TCCR1B:=$01;
TCNT1:=0;
OCR1A:=0;
OCR1B:=0;
OCR1C:=0;

TIMSK:=$00;

GIMSK:=$00;
MCUCR:=$00;
GIFR:=$00;
ADMUX:=%00000000; // 14745600/128 115200 Hz couramment sur 13
cycles donc
ADCSR:=%11000111; // 113 µs par acquistion soit 8.8 KHz
end InitPorts;

procedure erreure(i:byte); // pour le traitement d'erreure
begin
end;

function lit_adc(adc_input:byte):word; // 0: adc0 pa0 et ça marche au
simulateur
begin
// parceque "single Ended input" et AVCC reférence
ADMUX:=adc_input {or %00100000}; // et ADLAR=1 pour 8 bits
Setbit(ADCSR,6,true); // start, 113 µs en conversion normale
// Wait for the AD conversion to complete
// bloque le simulateur mais fonctionne réellement
{$X-} while adc_conv_finie=false do EndWhile; {$X+}
return ( adc_result );
end;

procedure calc_out; // basé sur 64 MHz clock (pas très précise)
var {freq1,}freq2:longword; // gamme de fréquence pour un diviseur cf
p52
pck:byte;
divise_pck:word;
ocr:byte;
freq_pck:word;
begin
pck:=0;
divise_pck:=%1000000000000000; // parceque rol 1 -> %0001
repeat // alghorithme bête et méchant, à amélliorer si
possible
pck:=pck+1;
divise_pck:=divise_pck rol 1; // *2;
freq2:={64000000 div 256} 250000 div longword(divise_pck);
until (freq>freq2) or (pck>%1111);
if pck>%1111 then
erreure(1); // hors des fréquences disponible
else
ocr:=byte( (freq2*256) div freq);
TCCR1B:=pck;
OCR1A:=byte (muldivint(larg,word(ocr),1024));
OCR1C:=ocr;
//freq_exacte:=(64000000 div longword(divise_pck));
//freq_exacte:=freq_exacte div longword(ocr) ; // calcul de la
frequence reelle
EndIf;
end;

{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
InitPorts;
EnableInts;
loop
adc0:=lit_adc(0); // frequence gros gain
adc1:=1+lit_adc(1); // frequence, ajustement fin
larg:=lit_adc(2); // % PWM
freq:=longword(adc0)*489+longword(adc1); // 1024*488=500736 Hz
calc_out;
endloop;
end gene_pwm.
------------------------------------------------------------------
François Rigaud




(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )