Es tut sich nichts. Die Status-LED ist grün. Fertig.Code:#include "asuro.h" void LocalInit(void) { // Change Oscillator-frequency of Timer 2 // to 40kHz, no toggling of IO-pin: TCCR2 = (1 << WGM21) | (1 << CS20); OCR2 = 0x64; // 40kHz @8MHz crystal ADCSRA = 0x00; // ADC off // Analog comparator: ACSR = 0x02; // Generate interrupt on falling edge ADMUX = 0x03; // Multiplexer for comparator to // ADC pin 3 SFIOR |= (1 << ACME); // Enable muliplexing of comparator DDRD &= ~(1 << 6); // Port D Pin 6 is input! } void Ping(unsigned char length) { count36kHz = 0; TCCR2 = (1 << WGM21) | (1 << COM20) | (1 << CS20); // Toggling of IO-Pin on // generate the Chirp while ( count36kHz*2 < length ) { OCR2 = 0x64 + length/2 - count36kHz*2; } TCCR2 = (1 << WGM21) | (1 << CS20); // Toggling of IO-Pin off OCR2 = 0x64; // set frequency back to 40kHz } int main(void) { int pos, i, posmarker; Init(); LocalInit(); while(1) { posmarker = 0; Ping(20); StatusLED(YELLOW); for(pos = 0; pos < 100; pos++) { Sleep(10); if((ACSR & (1 << ACI)) != 0) { if(posmarker == 0) { posmarker = pos; } } ACSR |= (1 << ACI); } if(posmarker>10) { StatusLED(RED); MotorDir(FWD, FWD); MotorSpeed(200, 200); } else { StatusLED(GREEN); MotorDir(FWD, RWD); MotorSpeed(0, 200); for(i = 0; i<100; i++) { Sleep(200); } } } return 0; }
Die Hardware habe ich an Sender/Empfänger mit dem Oszi gecheckt. Am Sender stabil 40 kHz (4V) und am Sender kommt ein Sinussignal im 10 mV Bereich an und reagiert auf Hindernisse.
Lesezeichen