At first the driver wouldn't compile, as the timers are different from the Mega8 to the Mega324P. I've managed to get it to compile without errors, but it still doesn't work properly. Here's the code with the timers changed & commented - am I missing something? Have I got the timers wrong? Any help is muchly appreciated!
I did get it to work flawlessly on a Mega8L that I had lying around, but need it to work on the 324P (need the extra pins).
Code: Select all
static void beep(uchar duration)
{
beepCnt = duration * 200;
TIMSK2 |= 1 << OCIE2A;
//TIMSK is original, have choice between TIMSK 0 - 2
//OCIE2 is original, can be OCIE2A or B
}
UTIL_INTERRUPT(SIG_OUTPUT_COMPARE2) /* run with global interrupt enable */
{
if(--beepCnt <= 0){
TIMSK2 &= ~(1 << OCIE2A);
/TIMSK is original, have choice between TIMSK 0 - 2
//OCIE2 is original, can be OCIE2A or B
PORTD |= 2; /* make sure LED is off */
}else{
if(beepCnt & 1){
PORTD |= 2;
}else{
PORTD &= ~2;
}
}
}
static void initHardware(void)
{
uchar i, j;
DDRC = 0;
PORTC = 0x20;
DDRD = 0x07; /* 0000 0111 bin includes USB reset */
PORTD = 0x3a; /* 0011 1010 bin */
setOutput(outputStatus);
j = 0;
while(--j){ /* USB Reset by device only required on Watchdog Reset */
i = 0;
while(--i); /* delay >10ms for USB reset */
}
DDRD = 0x02; /* 0000 0010 bin remove USB reset condition */
/* ADC used for clock speed input: */
ADMUX = 0x44; /* ref=AVcc, select PC4 */
ADCSRA = 0xc7; /* enable ADC, start conversion, rate = 1/128 */
/* Timer0 used to sample input (~50Hz) */
TCCR0A = 5; /* prescaler = 1024 */
//TCCR0 is original, TCCR0A or B
/* Timer1 used for event clock */
TCCR1A = 0; /* normal mode, no output actions */
TCCR1B = 0x08 | 5; /* CTC mode, clear on OCR1A, prescaler = 1024 */
OCR1A = 0xffff;
/* Timer2 used for acoustic signaling, we want 2kHz interrupt rate */
TCCR2A = 0x08 | 3; /* CTC mode, prescaler = 32 */
OCR2A = 188;
//TCCR2 & OCR2 are original, A or B choice on both
}
DBG1(0x00, (void *)&codeEepromSize, sizeof(codeEepromSize));
for(;;){ /* main event loop */
wdt_reset();
usbPoll();
if(TIFR1 & (1 << OCF1A)){
TIFR1 |= 1 << OCF1A; /* clear pending flag */
//TIFR is original, can be TIFR0-2
timerInterrupt();
}
pollAction();
if(TIFR0 & (1 << TOV0)){ /* debounce by sampling with reduced rate */
TIFR0 |= 1 << TOV0;
//TIFR is original, can be TIFR0-2
pollInput();
pollOutput();
pollCommands();
THANKS!
Joe