Ich hab jetzt ein kleines Programm mit Bascom geschrieben, das den Konverter testet. Ez steuert jeden Motor einzeln hoch, indem es den Motorwert von 0 bis 130 alle 100ms um 1 erhöht, und zwar erst den Linke, dann den rechten und zum Schluss den hinteren Motor. Als Anzeige wird für jeden Motor eine LED angesteuert. Da bei mir die Motoren erst bei einm Wert ab 50 reagieren muss man ein wenig Gedult haben, bis der erste Motor läuft.
Hier das Programm, und als Anhang auch das HEX file dazu.
Code:'===CHIP SETTINGS=== $regfile = "m328pdef.dat" $framesize = 64 $swstack = 64 $hwstack = 64 $crystal = 16000000 $baud = 38400 '===SERIAL IN SETTINGS=== Config Serialout = Buffered , Size = 254 Config Serialin = Buffered , Size = 254 '===ADC SETTINGS=== Config Adc = Single , Prescaler = Auto , Reference = Avcc 'avcc reference @ arduino =5V '===PORT SETTINGS=== Config Scl = Portd.5 'for ESCs Config Sda = Portd.4 'for ESCs Config Pind.6 = Output 'servo Portd.6 = 0 'servo Config Pind.7 = Output 'led 1 Config Pinb.0 = Output 'led 2 Config Pinb.1 = Output 'led 3 Config Pinb.5 = Output 'Arduino LED_grn '===DECLARATIONS=== '--Global-- '--I2C-- Const M_h = &H52 'i2c address: motor at the back Const M_l = &H54 'i2c address: motor at the left Const M_r = &H56 'i2c address: motor at the right Dim Ms_h_i As Integer 'contains motor nominal value as integer Dim Ms_r_i As Integer 'contains motor nominal value as integer Dim Ms_l_i As Integer 'contains motor nominal value as integer Dim Ms_h As Word 'converts motor nominal value Dim Ms_r As Word 'converts motor nominal value Dim Ms_l As Word 'converts motor nominal value Dim Currentmotor As Integer '--Subs-- Declare Sub Send_mots 'check and reshape motor signals and send them via I2C '--Alias's Led_1 Alias Portd.7 Led_2 Alias Portb.0 Led_3 Alias Portb.1 Led_grn Alias Portb.5 'a green led on the arduino mini pro '===START CONDITIONS=== Set Led_1 'light up led's after reset Set Led_2 Set Led_3 '--Variables-- 'prepare some variables 'Clear Serialin 'Clear Serialout '--Startup 2-- Waitms 100 Start Adc I2cinit Currentmotor = 1 Ms_h = 0 : I2csend M_h , Ms_h 'turn off the motors Ms_r = 0 : I2csend M_r , Ms_r Ms_l = 0 : I2csend M_l , Ms_l Led_grn = 0 Waitms 100 Reset Led_1 'turn off led's Reset Led_2 Reset Led_3 '==============MAIN LOOP======================================================== 'All this does is calling subs in a loop all the time Do Send_mots Loop End '===MOTORS I2C================================================================== Sub Send_mots If Ms_l > 130 Then Ms_l = 0 Currentmotor = Currentmotor + 1 If Currentmotor > 3 Then Currentmotor = 1 End If End If If Ms_r > 130 Then Ms_r = 0 Currentmotor = Currentmotor + 1 If Currentmotor > 3 Then Currentmotor = 1 End If End If If Ms_h > 130 Then Ms_h = 0 Currentmotor = Currentmotor + 1 If Currentmotor > 3 Then Currentmotor = 1 End If End If If Currentmotor = 1 Then Ms_l = Ms_l + 1 Set Led_1 Reset Led_2 Reset Led_3 End If If Currentmotor = 2 Then Ms_r = Ms_r + 1 Reset Led_1 Set Led_2 Reset Led_3 End If If Currentmotor = 3 Then Ms_h = Ms_h + 1 Reset Led_1 Reset Led_2 Set Led_3 End If I2csend M_h , Ms_h I2csend M_r , Ms_r I2csend M_l , Ms_l Waitms 100 End Sub







					
					
					
						
Zitieren
			

Lesezeichen