Most viewed

30 Nov 2011

Pulse Widfth Modulation Fading LED




Description

Pulse Width Modulation allows microcontrollers to dim lights, control motor speeds, fan speeds and generate analog voltages. By changing the length of the pulse, the output can be controlled. The pulse occurs at a regular frequency, the modulation frequency. The length of the pulse ratio to period time is called the duty cycle.The larger the duty cycle the higher the output is.
swave.gif
The AVR microcontroller can be used to generate PWM signals. The PWM signals can be generated by hardware or by software. An microcontroller like the ATTiny2313 has one hardware PWM on board of the chip. The output of the PWM signal is at the PORTB.3(OC1) pin.
The hardware PWM can be programmed by setting the timer registers. The ATTiny2313 has three timer registers that you need to set to program the PWM:
  1. The Timer/Counter1 Control Register (TCCR1A) is to put the timer in PWM mode.
  2. The Timer/Counter1 registers (TCNT1H and TCNT1L) are used to set the modulation frequency.
  3. The Output Compare Register1 (OCR1A) is used to set the duty cycle.
PWM with the AVR-microcontroller is a matter of comparison. If the Timer/Counter1 is running and the value of the timer is matching the value that is put in the OCR1A register, the OC1 pin changes from high to low. By changing the value of the OCR1A register the lenght of the pulse can be changed.

Hardware

The PWM output can be used to fade a LED in and out. On the picture you can see the LED on a bread-board connected to the ISP-board with a flat-cable.
PWM Fading LED
Downloads
FileDescriptionFile size
Download this file (PWM Fading LED.zip)PWM Fading~.zipAVR Studio 4 project files for ATTiny23134 Kb

No comments:

Post a Comment

Confused? Feel free to ask

Your feedback is always appreciated. I will try to reply to your queries as soon as time allows.

Note:
Please do not spam Spam comments will be deleted immediately upon my review.

 

Based on your view




You have to try this

This is trending now #