Chapter 7: Microcontroller Interrupts and Timers
k.
ing with integers. If
e set the compare to 130 we get a rate of 1923.076923 which yields 60.096...Hz
on LED5, pretty darn close, but we have an error of 1 – (60/60.09615385 ) * 100
= 0.16 %, not bad at all. But is it close enough? Only you can decide that
Create a new directory Precision Blinking and copy the PC_Comm. and
Demonstrator .c and .h files from the PC_Comm. directory.
In Programmers Notepad change Demonstrator.h to:
// Demonstrator.h Precision Blinking version
#include <avr/signal.h>
#include <inttypes.h>
void initializer(void);
void parseInput(char *);
int parse_ctc(char *);
void set_ctc(int);
void MilliSec_init(unsigned char count);
void set_OCR0A(unsigned char count);
In Programmers Notepad change Demonstrator.c to:
// Demonstrator.c Precision Blinking version
#include "PC_Comm.h"
#include "Demonstrator.h"
unsigned char milliseconds = 0;
void initializer()
{
// Calibrate the oscillator:
What happens if we send it 100? Well, 250000/100 = 2500, so we would get a
1250 Hz blin
How do we get a 60 Hz blink? We can get LED3 to blink at 60 Hz if the base rate
is 480 Hz, which we can get from 960 interrupts per second, which we could get
from a compare count of 260.41666... and we ain’t gonna get that for two
reasons: one, the count overflows at 255 and two, we are deal
w