Hallo Leute,
ich spiele grad mit dem AD-Wandler des Mega 16 rum.
Zur Strommessung. Ich messe die Spannung am Ein- (I_U1) und am Ausgang (I_U2) des Shunts. Die Differenz ergibt die am Shunt abfallende Spannung. Geteilt durch den Widerstand ergibt das den fließenden Strom. Da die Eingänge des AD-Wandlers nur max VCC vertragen wird ein Spannungsteiler 47K/4k7 vorgeschaltet. Soweit die Theorie.
Mit der Spannung funktionierts, Strom noch nicht getestet.
Momentan ist nur AD0 angeschlossen. Der Maximal Wert 1023 ist erreicht, wenn an AD0= 2,508 Volt anliegen.Code:'ADC auf LCD 'Quick and Dirty from Gandalf 21.1.07 ''LCD mit HD44780 kompatiblem Controller 2 Zeilen a 16 Zeichen ' 'Anschluß 'LCD Pin 1 = 0Volt (GND) 'LCD Pin 2 = +5 Volt (VDD) 'LCD Pin 3 = 0-5 Volt Kontrast (V0): Poti 10k zwischen 0V und 5V Schleifer an LCD3 'LCD Pin 4 = RS an Portc.2 'LCD Pin 5 = R/W an +5V 'LCD Pin 6 = E an Portc.3 'LCD Pin 7 = DB0 'frei 'LCD Pin 8 = DB1 'frei 'LCD Pin 9 = DB2 'frei 'LCD Pin 10 = DB3 'frei 'LCD Pin 11 = DB4 an Portc.4 'LCD Pin 12 = DB5 an Portc.5 'LCD Pin 13 = DB6 an Portc.6 'LCD Pin 14 = DB7 an Portc.7 '_____________________________________________________________ $crystal = 16000000 $regfile = "m16def.dat" ' Ich verwende AT Mega 16 $hwstack = 32 $swstack = 8 $framesize = 24 Config Lcd = 16 * 2 Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portc.4 , Rs = Portc.5 Cls Initlcd 'initialisiert das LCD '-------------------------------------------------------------- '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 = 128 , Reference = Internal 'Don't forget to configurem Analog Ports as Input Config Porta = Input 'Now give power to the chip Start Adc 'With STOP ADC, you can remove the power from the chip 'Stop Adc Dim U As Word Dim Spannung As Integer Dim I_u1 As Word Dim I_u2 As Word Dim Strom As Integer Dim R As Integer Dim Channel As Byte Dim Faktor As Integer Dim U_shunt As Integer U = 0 Spannung = 0 I_u1 = 0 I_u2 = 0 Strom = 0 R = 0.06 'Stromshunt hat 0.06 Ohm Channel = 0 'Korrekturfaktor (U) 1023/U_max (=30V) Faktor = 30.4 U_shunt = 0 'now read A/D value from channel 0 Do 'Begin Hauptschleife 'Spannung U = Getadc(0) 'Eingang PortA.0 Spannung = U / Faktor 'Umrechnung Binär-Wert in Volt 'now read A/D value from channel 1 and 2 'Strom I_u1 = Getadc(1) 'Spannung Eingang Shunt I_u2 = Getadc(2) 'Spannung Ausgang Shunt 'calculate current U_shunt = I_u1 - I_u2 'Der Spannungsabfall am Shunt Strom = U_shunt / R 'Berechnung Strom 'Anzeige Cursor Off Upperline 'setzt Cursor in die obere Zeile Lcd "U= " ; Spannung ; " V Bin=" ; U Waitms 300 Lowerline Lcd "I= " ; Strom ; " A Bin=" ; Strom Waitms 500 Loop 'erneut aufrufen End
Warum? Ist das die Spannung der internen Referenz?
besser wäre es, wenn ich 1023 erst bei 5 Volt hätte. Wie mach ich das?







 
			
			 
					
					
					
						 Zitieren
Zitieren

Lesezeichen