measuring with adcbut 10ms is not fast enough
This commit is contained in:
parent
c50925a376
commit
eb0a53092d
|
@ -292,6 +292,7 @@ void do_mode4(void) {
|
||||||
;
|
;
|
||||||
void do_mode5(void) {
|
void do_mode5(void) {
|
||||||
|
|
||||||
|
static bool sample;
|
||||||
static timer_t mytimer;
|
static timer_t mytimer;
|
||||||
uint16_t led1;
|
uint16_t led1;
|
||||||
uint16_t led2;
|
uint16_t led2;
|
||||||
|
@ -299,50 +300,46 @@ void do_mode5(void) {
|
||||||
|
|
||||||
if (ModeChanged) { //init after mode change
|
if (ModeChanged) { //init after mode change
|
||||||
ModeChanged = false;
|
ModeChanged = false;
|
||||||
|
ADMUX = (1<<REFS1) | (1<<REFS0); //use internal 1.1V as reference
|
||||||
|
ADCSRA = (1<<ADPS1) | (1<<ADPS0);// prescaler F_CPU/8
|
||||||
|
ADCSRA |= (1<<ADEN); // ADC enable - turn it on
|
||||||
|
// do one conversion
|
||||||
|
ADCSRA |= (1<<ADSC);
|
||||||
|
while (ADCSRA & (1<<ADSC) ) {} //wait for conversion to end
|
||||||
|
uint16_t __attribute__((unused)) dummy = ADCW; //read once
|
||||||
timer_set(&mytimer, 10);
|
timer_set(&mytimer, 10);
|
||||||
|
sample = false;
|
||||||
};
|
};
|
||||||
|
if (timer_expired(&mytimer)) {
|
||||||
|
if (sample){
|
||||||
//check for Buttons
|
//make a measurement
|
||||||
if (btn_state(BTNST_SUP, BTN_LEFT)) {
|
// single measurement
|
||||||
|
ADMUX = (ADMUX & ~(0x1F)) | 1; // select channel 1
|
||||||
};
|
ADCSRA |= (1<<ADSC); // start single conversion
|
||||||
if (btn_state(BTNST_SUP, BTN_RIGHT)) {
|
while (ADCSRA & (1<<ADSC) ) {}; // wait for conversion to end
|
||||||
};
|
led1 =ADCW; // read result
|
||||||
//if (timer_expired(&mytimer)) {
|
ADMUX = (ADMUX & ~(0x1F)) | 3; // select channel 3
|
||||||
//charge LEDs...
|
ADCSRA |= (1<<ADSC); // start single conversion
|
||||||
|
while (ADCSRA & (1<<ADSC) ) {}; // wait for conversion to end
|
||||||
|
led2 =ADCW; // read result
|
||||||
|
USART0_putc('1');USART0_putc(':');USART0_put_uint16(led1);USART0_crlf();
|
||||||
|
USART0_putc('2');USART0_putc(':');USART0_put_uint16(led2);USART0_crlf();
|
||||||
|
sample = false;
|
||||||
|
} else {
|
||||||
|
//charge LED
|
||||||
//enable LED channels as output
|
//enable LED channels as output
|
||||||
DDRC |= (1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3);
|
DDRC |= (1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3);
|
||||||
|
|
||||||
//init variables
|
|
||||||
led1 =0;
|
|
||||||
led2 =0;
|
|
||||||
|
|
||||||
//discharge completely for test purposes
|
|
||||||
//PORTC = (PORTC & 0b11110000);
|
|
||||||
//wait a while until fully dischcharged ....
|
|
||||||
//for (int i=0; i<100; i++){};
|
|
||||||
|
|
||||||
// charge with reverse polarity (C0, C2 = low C1, C3 = high)
|
// charge with reverse polarity (C0, C2 = low C1, C3 = high)
|
||||||
PORTC = (PORTC & 0b11110000) | (1 << PORTC1) | (1 << PORTC3);
|
PORTC = (PORTC & 0b11110000) | (1 << PORTC1) | (1 << PORTC3);
|
||||||
//wait a while until fully charged ....
|
|
||||||
//for (int i=0; i<10; i++){};
|
|
||||||
|
|
||||||
//set C1 and C3 to input (disable pullups)
|
//set C1 and C3 to input (disable pullups)
|
||||||
DDRC &= ~( (1 << PORTC1) | (1 << PORTC3));
|
DDRC &= ~( (1 << PORTC1) | (1 << PORTC3));
|
||||||
//pull ups off
|
//pull ups off
|
||||||
|
|
||||||
PORTC &= ~( (1 << PORTC1) | (1 << PORTC3));
|
PORTC &= ~( (1 << PORTC1) | (1 << PORTC3));
|
||||||
|
|
||||||
while ((PINC & 0b00001000)!=0){
|
|
||||||
if (PINC & 0b00000010) led1++;
|
|
||||||
//if (PINC & 0b00001000) led2++;
|
|
||||||
};
|
};
|
||||||
USART0_putc('1');USART0_putc(':');USART0_put_uint16(led1);USART0_crlf();
|
sample= true;
|
||||||
USART0_putc('2');USART0_putc(':');USART0_put_uint16(led2);USART0_crlf();
|
timer_set(&mytimer, 1);
|
||||||
//music_setNote(led1+1000,0);
|
}; //end if timer_expired
|
||||||
//timer_set(&mytimer, 1);
|
|
||||||
//}; //end if timer_expired
|
|
||||||
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user