Thursday, October 12, 2017

Dimming LED using PWM and Timer/Counter in AVR


Abbreviations:
PWM -  pulse width modulation
WGM - waveform generation mode
TCCR - 
COM - compare output mode
CS - clock select mode 
OCR - output compare register, continuously compare with counter value (TCNT0), match -> interrupt, or generate waveform of OC0




Fast PWM mode:

We will set WGM00 and WGM01 to 1 to enable "Fast PWM" mode.

TCCR0A |=  (1<<WGM00)|(1<<WGM01)|

1st Using Delay to Create PWM:



2nd Using Wave Generator in MCU: