Chapter 7: Microcontroller Interrupts and Timers
set[j] = '\0';
arse_set number too large");
}
else
t));
}
ed[11];
unt,speed,10);
('\r');
milliSecInit(count);
*
/
// Sets the compare value
setOCR0A(count);
// Set PWM Phase Correct mode, CLK/8 prescaler
if(j>4)// must be < 256
{
sendString("Error - P
return 0;
{
set_speed(atoi(se
return 1;
}
void set_speed(int count)
{
char spe
sendString("Setting the Compare Timer Count to: ");
itoa(co
sendString(speed);
sendChar
}
/
The USART init set the system oscillator to 2 mHz. We set the
Timer0 prescaler
to clk/8 which gives a 250 kHz input to the timer/counter. A
compare of 250 throws
an interrupt every millisecond.
- void milliSecInit(unsigned char count)
{
// Enable timer0 compare interrupt
TIMSK0 = (1<<OCIE0A);