Ja genau an den Anschlüssen. Aber es ist ja auch in der Anleitung mit Bildern erklärt.
Hier ein paar Funkionen/Code für dich, da ich auch ein RN-Control mit ATmega32 hab.
Ich hab mit den Funktionen gleich ne kleine Beispielanwendung gemacht.Code:// Motorsteuerung für RN-Control mit ATmega32 #include <avr/io.h> #define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT)) #define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT)) #define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT)) // Nur die Funkionen move() und stopmotor() sind für die benutzung gedacht float abs(float arg) { if(arg<0.0) return (-arg); else return arg; } int get_sign(float val) { if(val>0.0) return 1; else return -1; } float limit_range(float val,float low,float high) { if(val<low) return low; else if(val>high) return high; else return val; } void motorinit(void) { DDRD= (1<<PD4) | (1<<PD5); // PWM Pins als ausgang DDRC= (1<<PC6) | (1<<PC7); // 6=Motor 1 Kanal 1 7= Motor 1 Kanal 2 DDRB= (1<<PB0) | (1<<PB1); // 0=Motor 2 Kanal 1 1= Motor 2 Kanal 2 TCCR1A = (1<<COM1A1) | (1<<COM1B1) | (1<<COM1A0) | (1<<COM1B0) | (1<<WGM11) | (1<<WGM10); // 10 Bit Pwm, invertierend TCCR1B = (1<<CS11) | (1<<CS10); // Prescaler 64 OCR1A=1; // Mindestzeit für PWM1 OCR1B=1; // Mindestzeit für PWM2 } void pwm_motor(float vel,char motor_index) // motor_index 0 für Motor 1, 1 für Motor 2 { vel = limit_range(vel,0.0,100.0); if(motor_index==0) OCR1A= (int) (10.23*vel); if(motor_index==1) OCR1B= (int) (10.23*vel); } // Geschwindigkeitsbereich für beide -100 - 100, wobei das Minus nur die Laufrichtung ändert void move(float l_vel, float r_vel) { if(get_sign(l_vel)==1) // Motor 1 Laufrichtung 1 { SETBIT(PORTC,PC6); CLEARBIT(PORTC,PC7); } else // Motor 1 Laufrichtung 2 { SETBIT(PORTC,PC7); CLEARBIT(PORTC,PC6); } if(get_sign(r_vel)==1) // Motor 2 Laufrichutng 1 { SETBIT(PORTB,PB0); CLEARBIT(PORTB,PB1); } else // Motor 2 Laufrichtung 2 { SETBIT(PORTB,PB1); CLEARBIT(PORTB,PB0); } pwm_motor(abs(l_vel),0); pwm_motor(abs(r_vel),1); } void stopmotor(void) { CLEARBIT(PORTB,PB1); CLEARBIT(PORTB,PB0); CLEARBIT(PORTC,PC7); CLEARBIT(PORTC,PC6); } void main(void) { for(;;) { unsigned int x,y; move(50,50); // Beide Motoren gleiche Richtung for(x=0;x<=40000;x++) asm volatile ("nop"); // Pause stopmotor(); move(-50,100); // Motoren verschiedene Richtungen und Geschwindigkeiten for(x=0;x<=40000;x++) asm volatile ("nop"); // Pause move(100,100); // Beide Motoren volle Geschwindigkeit for(x=0;x<=60000;x++) // Längere Pause { for(y=0;y<=60000;y++) asm volatile ("nop"); } stopmotor(); for(x=0;x<=40000;x++) asm volatile ("nop"); // Pause } }
Viel Spaß.
Gruß Muraad






Zitieren

Lesezeichen