Moin Gemeinde,
hab ne Denkblockade und bitte um Hilfe...
Wenn ich bei einer 10Bit Auflösung des ADC Werte von 0 bis 1023 bekomme und dabei eine Eingangsspannung von 0 bis 5V habe, könnte die Berechnung wie folgt ausehen:
Wie kommt der Autor dieses Codeschnipsels auf die "0.48875", anstatt 5 (für 5V) ?Code:Dim A As Word Dim B As Single Dim C As Single Config ADC = Single , Prescaler = Auto Start Adc Do A = Getadc(7) B = A * 0.48875 C = B / 100 Print C Loop
Aber noch wichtiger für mich - wie kann ich diese Umrechnung ohne Fließkommazahlen erreichen?
In anderen Basic-Compilern, z.B. für PICs gibts ja nicht mal die Möglichkeit, mit Fließkommazahlen zu rechnen![]()
Also muss es ja auch in Bascom ohne diese gehen - bloss wie?
Ich bin noch nie ne Mathe-Leuchte gewesen, darum bitte ich um Hilfe.
Hier mal ein Beispiel aus einem PIC-Basic Compiler, der den ADC-Wert in Volt auf ein LCD gibt:
Ich kann dieses Verfahren aber leider nicht so richtig in Bascom übernehmen und bitte um Hilfe.Code:'****************************************************************************** ' microcontroller P16F877A ' ' Project: adconlcd ' This project is designed to work with PIC 16F877A ' with minor adjustments, it should work with any other PIC MCU ' that has ADC module. ' ' This code demonstrates how to use library function ADC_read, and library ' procedures and functions for LCD display (4 bit interface) ' '****************************************************************************** program adconlcd dim ch as byte dim t as integer dim a as string[20] dim tlong as longint main: PORTB = 0 ' clear portb TRISB = 0 ' designate portb as output (LCD is connected to portb) intcon = 0 ' disable all interrupts Lcd_init(PORTB) ' initialize (4-bit interface connection) Lcd_Cmd(PORTB, LCD_CURSOR_OFF) ' send command to LCD (cursor off) LCD_Cmd(PORTB,LCD_CLEAR) ' send command to LCD (clear LCD) a = "mikroElektronika" ' assign text to string a LCD_Out(PORTB,1,1,a) ' print string a on LCD, 1st row, 1st column a = "LCD example" ' assign text to string a LCD_Out(PORTB,2,1,a) ' print string a on LCD, 2nd row, 1st column OPTION_REG = $80 ADCON1 = $82 ' configure VDD as Vref, and analog channels TRISA = $FF ' designate porta as input Delay_ms(2000) a = "voltage:" ' assign text to string a DoAdc: t = ADC_read(2) ' get ADC value from 2nd channel LCD_Out(PORTB,2,1,a) ' print string a on LCD, 2nd row, 1st column tlong = t*5000 t = longint(tlong >> 10) ch = t div 1000 ' prepare value for diplay LCD_Chr(PORTB,2,9,48+ch) ' write ASCII at 2nd row, 9th column LCD_Chr(PORTB,2,10,".") ch = integer(t div 100) mod 10 LCD_Chr(PORTB,2,11,48+ch) ch = integer(t div 10) mod 10 LCD_Chr(PORTB,2,12,48+ch) ch = t mod 10 LCD_Chr(PORTB,2,13,48+ch) LCD_Chr(PORTB,2,14,"V") delay_ms(1) goto DoAdc end.
Viele Grüße,
Bruno







Zitieren

Lesezeichen