Ich verwende den Freerun Modus für schnellstmögliche Messwerterfassung, die halt mit Bascom möglich ist.
Mit GETADC(x) benutzt Du IMMER ADC=Single als Modus, auch wenn Du FREE angibt
Beispiel für den Free-Modus (aus einem Tutorial)
Daraus kannst Du Dir das dann ableiten.
Code:
'initialize ADC
Config Adc = Free , Prescaler = 32 , Reference = Avcc 'ADC is automatically started, so immediately
Stop Adc 'stop ADC before it reach interrupt and we change channel
'define constants
Const Number_of_channels = 6 'ADC0-ADC5 on ATmega8 (value can also be for example 2 if we use ADC0-ADC1)
Const Adc_low_array_size = Number_of_channels * 2 'overlay bytes on word array
Const Adc_high_array_size = Adc_low_array_size - 1 'Adc_high array is smaller by 1 because of offset
'define variables
Dim Adc_value(number_of_channels) As Word
Dim Adc_low(adc_low_array_size) As Byte At Adc_value(1) Overlay
Dim Adc_high(adc_high_array_size) As Byte At Adc_value(1) + 1 Overlay
Dim Inital_admux_value As Byte
Dim Old_channel_value As Byte
'enable interrupts
Enable Adc 'will set ADCSRA.ADIE bit
Enable Interrupts
'define interrupts
On Adc Adc_isr
'initialize start conditions
Old_channel_value = 1 ' (0 * 2) + 1
Inital_admux_value = Admux 'store ADMUX register before channels are changed
Start Adc 'This will set ADC Enable bit, but not also ADCSRA.ADSC bit, so
Set Adcsra.adsc 'set ADC Start Conversion bit manually
'------------------------------------------------------------------------------
'The Interrupt Handler For The ADC Interrupt
'------------------------------------------------------------------------------
Adc_isr:
Adc_low(old_channel_value) = Adcl 'read ADCL first then ADCH
Adc_high(old_channel_value) = Adch 'it will not work other way
'new AD conversion has allready started so its time to change channel, but before we do that we need to
'store current channel, because channel change will not take effect until next conversion has started
Old_channel_value = Admux 'save status of ADMUX register
Old_channel_value = Old_channel_value Xor Inital_admux_value 'leave only channel number, remove informations about reference source
Old_channel_value = Old_channel_value * 2 'multiply by 2 and
Incr Old_channel_value 'add 1 to make it compatible with overlayed variables
If Old_channel_value => Adc_high_array_size Then Admux = Inital_admux_value Else Incr Admux 'change channel
'Toggle Admux.mux0 'you can use your own change channel logic (this will toggle ADC0 and ADC1)
'place it on the end of ISR to be on the safe side that at least 1 ADC clock cycle has passed
Return
Lesezeichen