add timer and more debug code

This commit is contained in:
David Voswinkel
2009-07-05 10:49:32 +02:00
parent fef90c7f6e
commit c55a66f90d
5 changed files with 85 additions and 43 deletions

View File

@@ -1,6 +1,6 @@
#include <io.h>
#include <interrupt.h>
#include <signal.h>
#include <avr/io.h>
#include <avr/interrupt.h> /* for sei() */
#ifndef OCR1A
@@ -12,26 +12,26 @@
#endif
//#define XTAL 11059201L // nominal value
#define XTAL 20000000L
#define XTAL 20000000UL
#define DEBOUNCE 256L // debounce clock (256Hz = 4msec)
#define DEBOUNCE 500UL // debounce clock (256Hz = 4msec)
#define uint8_t unsigned char
#define uint unsigned int
uint8_t prescaler;
uint8_t volatile second; // count seconds
uint16_t prescaler;
uint16_t volatile second; // count seconds
SIGNAL (SIG_OUTPUT_COMPARE1A)
ISR (SIG_OUTPUT_COMPARE1A)
{
#if XTAL % DEBOUNCE // bei rest
OCR1A = XTAL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times
OCR1A = 20000000UL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times
#endif
if( --prescaler == 0 ){
prescaler = (uint8_t)DEBOUNCE;
prescaler = (uint16_t)DEBOUNCE;
second++; // exact one second over
#if XTAL % DEBOUNCE // handle remainder
OCR1A = XTAL / DEBOUNCE + XTAL % DEBOUNCE - 1; // compare once per second
@@ -39,24 +39,24 @@ SIGNAL (SIG_OUTPUT_COMPARE1A)
}
}
uint16_t timer_start( void )
void timer_start( void )
{
TCCR1B = (1<<WGM12) | (1<<CS10); // divide by 1
// clear on compare
OCR1A = XTAL / DEBOUNCE - 1; // Output Compare Register
OCR1A = XTAL / DEBOUNCE - 1UL; // Output Compare Register
TCNT1 = 0; // Timmer startet mit 0
second = 0;
prescaler = (uint8_t)DEBOUNCE; //software teiler
TIMSK = 1<<OCIE1A; // beim Vergleichswertes Compare Match
prescaler = (uint16_t)DEBOUNCE; //software teiler
TIMSK1 = 1<<OCIE1A; // beim Vergleichswertes Compare Match
// Interrupt (SIG_OUTPUT_COMPARE1A)
sei();
}
uint16_t timer_stop(void)
{
cli():
return second
//cli();
return second;
}