Getting Started

(lily) #1

Chapter 7: Microcontroller Interrupts and Timers


seen that the human eye perceives fast blinking LEDs as being
also see rapidly pulsed light as having brightness
eak and the average. This means that a high intensity
s brighter than it would powered by a direct
e average of the pulsed signal. Our
less
ly can we control the brightness, we can do a
into thinking it’s seeing something brighter even though we

. This is good news for our power use, but bad news in trying
s. Cutting the duty cycle in half
a halving of the perceived brightness.


llow us to play with the frequency and the duty cycle
n we can play with the parameters and see how we think they affect brightness.

de? Nope, all we have to do is change the
TCC0RA register from WGM01 = 1 and
GM0

py the .c and .h files and the makefile from
Demonstrator files milliSecInit routine

// Set Clear on Timer Compare (CTC) mode, CLK/8 prescaler
TCCR0A = (1<<WGM01)|(0<<WGM00)|(1<<CS01);

PARE0) change:

D, 0);

We have already
co tly on. Our eyes
ween the p


nstan
somewhere bet
pulse with a low duty cycle pulse look
current providing the same power as th
perceptual peculiarity gives us a way to provide a brighter seeming light with
power if we use PWM. So not on
trick to fool the eye
are using less power
to extrapolate duty cycle to perceived brightnes
does not translate into


Let’s write a program to a
the


Is it hard to write the PWM co
waveform generation bits in the
W 0 = 0 to WGM01 = 0 and WGM00 = 1.


Create a new directory, PWM, and co
the Precision Blinking directory. In the
change:


to:
// Set PWM Phase Correct mode, CLK/8 prescaler
TCCR0A = (0<<WGM01)|(1<<WGM00)|(1<<CS01);


and in the SIGNAL(SIG_OUTPUT_COM


PORTD = milliseconds++;


to
if(PORTD &= 1) cbi(PORT


:

else sbi(PORTD, 0);

Free download pdf