diff --git a/src/adc.c b/src/adc.c index 63cf8d842cf89d43d5f58d6a6ad5bb641644e898..ab3750935d3a8625a6969ec9f50137763d544071 100644 --- a/src/adc.c +++ b/src/adc.c @@ -70,14 +70,13 @@ void adc_init(void) adc_running=0; adc_num_samples=ADC_MAX_NUM_SAMPLES; ram_data[ADC_NUM_SAMPLES]=ADC_MAX_NUM_SAMPLES; - adc_sample_period_ms=0x01; - ram_data[ADC_SAMPLE_PERIOD]=0x01; + adc_sample_period_ms=100; + ram_data[ADC_SAMPLE_PERIOD]=100; adc_set_sample_period(adc_sample_period_ms); // configure the timer 2 to perform periodic conversions (1 ms period) TCCR2=(1<<WGM21);// CTC mode, no output, prescaler to 0 (no clock source) TCNT2=0x00;// start from 0 - TIMSK=0x00;// interrupts not enabled } void adc_start(void) diff --git a/src/compass.c b/src/compass.c index 371ea868454af4258a60e84995388e0d38a8ff9d..df04eb3e33fa31ff0e9991c297cc102d0bd8d78c 100644 --- a/src/compass.c +++ b/src/compass.c @@ -19,8 +19,6 @@ volatile uint8_t compass_stop_cal; volatile uint8_t compass_stop_op; volatile uint8_t compass_start_op; volatile compass_states_t compass_state; -// time control variables -volatile uint8_t compass_delay_done; /* private functions */ void compass_avrg(uint16_t heading) @@ -64,20 +62,19 @@ void compass_start_time_delay(uint8_t delay_ms) OCR0=delay_ms*16;// set count value TCCR0&=0xF8; TCCR0|=0x07;// enable clock - compass_delay_done=0x00; } uint8_t compass_is_delay_done(void) { - return compass_delay_done; -} - -/* interrupt handlers */ -ISR(TIMER0_COMP_vect) -{ - compass_delay_done=0x01; - // disable clock - TCCR0&=0xF8; + if(TIFR&(1<<OCF0)) + { + // disable clock + TIFR|=(1<<OCF0); + TCCR0&=0xF8; + return 0x01; + } + else + return 0x00; } /* public functions */ @@ -88,7 +85,6 @@ void compass_init(void) compass_stop_cal=0; compass_stop_op=0; compass_start_op=0; - compass_delay_done=0x00; compass_state=idle; compass_current_sample=0; compass_num_samples=COMPASS_MAX_NUM_SAMPLES; @@ -97,7 +93,7 @@ void compass_init(void) /* use timer 0 to control the operation delay */ TCCR0=(1<<WGM01);//campare mode, output disable, prescaler 0 ASSR=0x00;// disable assynchronous operation - TIMSK=(1<<OCIE0);// enable interrupts + // interrupts not enabled OCR0=0xFF; TCNT0=0x00;