PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : SIGNAL (SIG_ADC) umsetzen in bascom



pebisoft
15.08.2005, 21:47
wie kann man die interruptroutine für den adc "SIGNAL (SIG_ADC)" in bascom umsetzen.
mfg pebisoft

15.08.2005, 21:59
'--------------------------------------------------------------------
' ADC_INT.BAS
' demonstration of GETADC() function in combintion with the idle mode
' for a better noise immunity
' Getadc() will also work for other AVR chips that have an ADC converter
'--------------------------------------------------------------------
$regfile = "4433def.dat"
$crystal = 4000000
$baud = 19200
'configure single mode and auto prescaler setting
'The single mode must be used with the GETADC() function

'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128
'Because the ADC needs a clock from 50-200 KHz
'The AUTO feature, will select the highest clockrate possible
Config Adc = Single , Prescaler = Auto
'Now give power to the chip
On Adc Adc_isr Nosave
Enable Adc
Enable Interrupts



Dim W As Word , Channel As Byte

Channel = 0
'now read A/D value from channel 0
Do
Channel = 0
'idle will put the micro into sleep.
'an interrupt will wake the micro.
Start Adc
Idle
Stop Adc

Print "Channel " ; Channel ; " value " ; W
Waitms 500
Loop
End

Adc_isr:
push r24
in r24,sreg
push r24
push r25
W = Getadc(channel)
pop r25
pop r24
!out sreg,r24
pop r24
Return
'The new M163 has options for the reference voltage
'For this chip you can use the additional param :
'Config Adc = Single , Prescaler = Auto, Reference = Internal
'The reference param may be :
'OFF : AREF, internal reference turned off
'AVCC : AVCC, with external capacitor at AREF pin
'INTERNAL : Internal 2.56 voltage reference with external capacitor ar AREF pin

'Using the additional param on chip that do not have the internal reference will have no effect.

pebisoft
21.08.2005, 13:25
habe die lösung gefunden für bascom :


$regfile = "m16def.dat"
$crystal = 8000000
$baud = 19200


Dim Adhi As Byte
Dim Adlow As Byte
Dim Adcergebnis As Word
Dim A As String * 10

Config Porta = Input

Disable Interrupts
Adcsra.aden = 1
Adcsra.adate = 1
Adcsra.adie = 1
Adcsra.adsc = 1
Adcsra.adps0 = 1
Adcsra.adps1 = 1
Adcsra.adps2 = 1
Admux.refs0 = 1
Admux.mux0 = 1 ' adc1
Enable Interrupts

On Adc Onadc

Do

Input A
Print A
Waitms 10

Loop

Onadc:
Adcsra.adsc = 1
Adlow = Adcl
Adhi = Adch
Adcergebnis = Adhi * 256
Adcergebnis = Adcergebnis + Adlow
If Adcergebnis < 200 Then
Print Adcergebnis
End If
Return