ADC Probleme bascom

Gast #1198228
Lesenswert?

Hallo

Ich will gewisse Analogwerte im uC wandeln und es an einem port 
ausgeben. Ich habe einen Atmega16 im TQFP gehäuse.

könnt ihr mal drüberschauen?


$regfile = "m16def.dat"
$crystal = 1000000
$baud = 9600
$hwstack = 32                                               ' default
use 32 for the hardware stack
$swstack = 10                                               'default use
10 for the SW stack
$framesize = 40                                             'default use
40 for the frame space


Config Porta = Input
Config Portb = Output

Config Adc = Single , Prescaler = Auto
Start Adc

Print "START CONVERTER"
Dim W As Integer

Do

      W = Getadc(0)

      Select Case W
         Case Is >= 205 : Portb = &B00000001
         Case Is >= 232 : Portb = &B00000010
         Case Is >= 259 : Portb = &B00000011
         Case Is >= 286 : Portb = &B00000100
         Case Is >= 313 : Portb = &B00000101
         Case Is >= 340 : Portb = &B00000110
         Case Is >= 367 : Portb = &B00000111
         Case Is >= 394 : Portb = &B00001000
         Case Is >= 421 : Portb = &B00001001
         Case Is >= 448 : Portb = &B00001010
         Case Is >= 475 : Portb = &B00001011
         Case Is >= 502 : Portb = &B00001100
         Case Is >= 529 : Portb = &B00001101
         Case Is >= 556 : Portb = &B00001110
         Case Is >= 583 : Portb = &B00001111
         Case Is >= 610 : Portb = &B00011111
         Case Is >= 637 : Portb = &B00101111
         Case Is >= 664 : Portb = &B00111111
         Case Is >= 691 : Portb = &B01001111
         Case Is >= 718 : Portb = &B01011111
         Case Is >= 745 : Portb = &B01101111
         Case Is >= 772 : Portb = &B01111111
         Case Is >= 799 : Portb = &B10001111
         Case Is >= 826 : Portb = &B10011111
         Case Is >= 853 : Portb = &B10101111
         Case Is >= 880 : Portb = &B10111111
         Case Is >= 907 : Portb = &B11001111
         Case Is >= 934 : Portb = &B11011111
         Case Is >= 961 : Portb = &B11101111
         Case Is >= 988 : Portb = &B11111111
      End Select
      Print W
Loop
End
#1198598
Lesenswert?

hi,
in deiner select case wird es auch keine Ausgangssignale geben, wenn W 
unter 205 ist, dafür gibt es keine Anweisung (könnte ja heissen: case is 
< 205). Für alle Werte, die über 205 liegen, ist in jedem Fall die erste 
Bedingung (case is >= 205) gültig. Bei allen Werten darüber (z.B. 610) 
kann die entsprechende Anweisung nicht ausgeführt werden, weil die erste 
gültige ja schon mit der ersten (>= 205) ausgeführt wird.
Die case Verzweigung ist für den angedachten Zweck (Bereich1: 205-232, 
Bereich2: 232-259, etc) richtig gecodet, die Zuweisungen müssen aber 
absteigend erfolgen, so dass die erste Bedingung dem höchsten Bereich 
entspricht.

select case W
   case is >= 980 : Anweisung     ' Wertebereich 980 - 1024
   case is >= 950 :               ' Wertebereich 950 - 979
   .
   .
end select

So herum tät ein Schuh draus werden. Gilt übrigens nicht nur für Bascom, 
das Problem einer unlogischen Definition ergäbe in jeder anderen Sprache 
dasselbe Resultat.
Grüssens, harry

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren