Den Code kriegst du mit [ code ] ... [/ code ]
ohne die Leerzeichen rein.
schreib mal noch "Enable Adc" rein.
und noch
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Hallo zusammen,
ich habe ien kleines Problem und hoffe jemand kann mir helfen.
Also ich versuche mit einem ATmega8 am Port PC0(ADC0) eine Spannung eizulesen und den Wert auszugeben.
Die Konfiguration kann man unter Bascom sowohl in Maschinencode als auch mit Bascom Hi-Level-Statements ausführen. Angeschlossen wird ein Poti.
Nun mein Problem:
Konfiguration im Maschinecode funktioniert bestens, sogar als Kurvenausgabe. Kommentiere ich Maschinecode aus, und verwende Bascom, ist der ausgegebene Wert IMMER 1023! Egal vohin ich das Poti stelle.
Code:'ACC + Poti: A/D-Konverter, einfaches Beispiel 'Hardware: Poti1 an PC0/ADC0 ' MAX232 an PD0/PD1, Nullmodemkabel zum PC '---------------------------------------------------------- $regfile = "m8def.dat" 'ATmega8-Deklarationen $crystal = 3686400 'Quarz: 3,6864 MHz $baud = 9600 'Baudrate zum PC: 9600 Baud '---------------------------------------------------------- Dim H As Word Dim L As Byte Ddrc = &B00000000 'PC7...PC0=0: PortC-Pins auf Eingang '---------------------------------------------------------- 'Register direkt gesetzt, läuft 'Admux = &B01100000 'Bits7+6=01: Aref ist intern verbunden 'Bit5=1: LeftAdjust, nur 8 Bit in ADCH 'Bits3...0=0000: Pin ADC0 wählen 'Adcsr = &B11100111 'Bit7=1:AdcOn,Bit6=1:Start,Bit5=1:Frei 'Bits2+1+0=111: AdcClock=AvrClock/128 '---------------------------------------------------------- 'BASCOM Statements liefern immer nur den Wert 1023 Config Adc = Single , Prescaler = 128 Enable Interrupts Start Adc '---------------------------------------------------------- Do 'Hauptschleife 'udr = Adch 'Aktuelles AD-HiByte in die UART H = Getadc(0) 'aktueelen Wert auslesen Print H 'Print h Waitms 200 'Datenmenge etwas begrenzen Loop
Was mache ich Falsch????
mfg.
Dietmar
(Entschuldigt bitte die Form, aber ich weiß nicht wie ich den Code richtig reinbekomme.)
Den Code kriegst du mit [ code ] ... [/ code ]
ohne die Leerzeichen rein.
schreib mal noch "Enable Adc" rein.
und noch
Config Adc = Single , Prescaler = Auto , Reference = Avcc
MFG Moritz
www.free-webspace.biz/update
Dieser Code sollte es tun:
Code:'-------------------------------------------------------------------- ' ADC.BAS ' demonstration of GETADC() function for 8535 or M163 micro ' Getadc() will also work for other AVR chips that have an ADC converter '-------------------------------------------------------------------- $regfile = "8535def.dat" ' we use the 8535 '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,15,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 Start Adc 'With STOP ADC, you can remove the power from the chip 'Stop Adc Dim W As Word , Channel As Byte Channel = 0 'now read A/D value from channel 0 Do W = Getadc(channel) Print "Channel " ; Channel ; " value " ; W Incr Channel If Channel > 7 Then Channel = 0 Loop End '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.
MFG Moritz
www.free-webspace.biz/update
Hallo Moritz,
danke für Deine Anwort.
Dies ergibt das gleiche Erbenis: 1023.
mfg.
Dietmar
@ Moritz
Danke für Dein Beispiel.
Das ist der Code aus der Bascom-Hilfe. Den habe ich auch schon ausprobiert. Der tuts auch nicht. Immer 1023, egal wo das Poti steht.
mfg.
Dietmar
Das verstehe ich dann leider auch nicht, hab leider gerade nix zum testen da...
Hier nochmla ein anderer Code:
Müsstest alles was du nicht brauchst streichen, der Code müsste aber laufen, meine ihn schon benutzt zu haben.Code:$regfile = "m8def.dat" $crystal = 8000000 $baud = 2400 Config Adc = Single , Prescaler = Auto , Reference = Avcc Admux = &B01100100 On Adc Onadc Config Pind.3 = Output Config Pinc.4 = Input Config Pinc.0 = Input Config Pinc.1 = Input Portc.4 = 1 Portc.0 = 1 Portc.1 = 1 Portd.3 = 1 Dim Switch As Word Dim Switsch As Word Start Adc Enable Interrupts Enable Adc Do Switch = Getadc(4) Print Switch Switsch = Getadc(0) Print Switsch Waitms 100 Loop End Onadc: If Getadc(4) < 1023 Then Print "i" End If Print Getadc(4) If Getadc(0) < 1023 Then Print "i2" End If Print Getadc(0) Return
MFG Moritz
www.free-webspace.biz/update
hallo, ich gebe es auf einem lcd aus. da ich 5 volt referenz angelegt habe komme ich beim sharpsensor nur bis 512, der liefert nur 2,5v max steuerspannung.
ich könnte natürlich einen widerstand bei der referenz dazuschalten, damit ich bis 1024 komme, 512 reicht mir aus.
$regfile = "m16def.dat"
$crystal = 8000000
Enable Interrupts
Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , Rs = Portc.5 , E = Portc.4
Config Lcd = 16 * 2
Config Adc = Single , Prescaler = Auto
Dim Adc_vh As Byte
Dim W_vh As Word
Adc_vh = 0 ' pin a0
Start Adc
Do
Cls
Locate 1 , 1
W_vh = Getadc(adc_vh)
Lcd "wert:" ; W_vh
Waitms 200
Loop
mfg pebisoft
Hallo zusammen,
ersteinmal Danke für euere Unterstützung.
Manchmal liegen die Probleme auch an der Hardware.
Ich habe soeben ein neues Modul Mega8 bekommen, und siehe es funzt.
Damit ist anzunehmen, dass das alte Modul evtl. einen Schuss hat.
Jetzt laufen auch euere Programme.
Nochmals Danke. =D>
mfg.
Dietmar
hallo, du hast deine programme auch ein bisschen zu gross angesetzt.
denk daran, basic ist einfach strukturiert. wenn du mit deinen ansatz programmieren möchtest, probier das einmal winavr-c. geht wunderbar.
ich glaube mit winavr bist du besser dran.
mfg pebisoft
@pebisoft
Danke für Deinen Hinweis.
Aber ich glaube, dass es sich in Basic auch recht gut programmieren läßt. Natürlich kann man statt der Bascom-HiLevel-Statements auch direkt Maschinencode schreiben, wie ich es ja auch getan habe.
Aber Bascom ist ein Basicdialekt, den ich verstehe, C müßte ich mir erst mühsam aneigen. Selbst auf die Gefahr hin, dass MEIN Basiccode etwas zu groß wird. Ich kann damit leben.
Nochmals Danke für den Hinweis.
mfg
Dietmar
Lesezeichen