-
An den Motoren liegt es nicht, folgendes Programm läuft:
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)
{
count72kHz = 0;
TCCR2 = (1 << WGM21) | (1 << COM20) | (1 << CS20);
// Toggling of IO-Pin on
// generate the Chirp
while(count72kHz < length) {
OCR2 = 0x64 + length / 2 - count72kHz;
}
TCCR2 = (1 << WGM21) | (1 << CS20); // Toggling of IO-Pin off
OCR2 = 0x64; // set frequency to 40kHz
}
int main(void)
{
int pos, i;
int posmarker;
Init();
LocalInit();
while(TRUE) {
posmarker = 0;
Ping(20);
for(pos = 0; pos < 100; pos++) {
Sleep(10);
if((ACSR & (1 << ACI)) != 0) {
if(posmarker == 0) { posmarker = pos; }
}
ACSR |= (1 << ACI);
}
if(posmarker < 15) {
StatusLED(GREEN);
MotorDir(FWD, FWD);
MotorSpeed(200, 200);
}
else {
StatusLED(RED);
MotorDir(FWD, RWD);
MotorSpeed(0, 200);
for(i = 0; i<100; i++) { Sleep(200); }
}
}
return 0;
}
werde es jetzt nochmal nach und nach auf Ausweichen statts folgen umschreiben.
-
Code geändert auf:
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)
{
count72kHz = 0;
TCCR2 = (1 << WGM21) | (1 << COM20) | (1 << CS20);
// Toggling of IO-Pin on
// generate the Chirp
while(count72kHz < length) {
OCR2 = 0x64 + length / 2 - count72kHz;
}
TCCR2 = (1 << WGM21) | (1 << CS20); // Toggling of IO-Pin off
OCR2 = 0x64; // set frequency to 40kHz
}
int main(void)
{
int pos, i;
int posmarker;
Init();
LocalInit();
while(TRUE) {
posmarker = 0;
Ping(20);
for(pos = 0; pos < 100; pos++) {
Sleep(10);
if((ACSR & (1 << ACI)) != 0) {
if(posmarker == 0) { posmarker = pos; }
}
ACSR |= (1 << ACI);
}
if(posmarker < 15) {
StatusLED(GREEN);
MotorDir(FWD, RWD);
MotorSpeed(0, 200);
for(i = 0; i<100; i++){
Sleep(200);
}
}
else {
StatusLED(RED);
MotorDir(FWD, FWD);
MotorSpeed(200, 200);
}
}
return 0;
}
Da gehts auch schon los ^^
Anstatts das sich beide Räder vorwäts drehen, dreht sich nur das rechte rückwärts. Dabei ist ja garnix vor dem US-Sensor und selbst wenn da etwas ist, ändert sich nix am verhalten...
Was mach ich denn falsch? Läuft das Programm denn bei jemanden?
Hat vielleicht einer einen Tipp oder ein funktionierendes Programm das ich testen kann?
-
Ich bin doch nicht der einzige der diese Erweiterung nutzt, da müsste doch mal jemand einen Testcode für mich haben, von mir aus auch per PN wenn es nicht jeder sehen soll ^^
-
Hallo,
Da hab ich leider keine Ahnung mehr aber vielleicht liegt's am compiler?
Probier mal dies:
Code:
if((ACSR & (1 << ACI)) != 0) {
auseinander zu schreiben:
Code:
unsigned char aci,acsr;
Code:
aci = ( 1 << ACI ) ;
acsr = ACSR & aci ;
if ( acsr != 0 ) {
und auch einige Sleep() im "else { StatusLED(RED);" ein zu bauen.
Gruss,
Henk
-
Also die StatusLED leuchtet nur grün wenn ich mit der neuen Lib compeliere (scheint mir so).
ältere lib: auf asuro werden 32pages geflasht
neuere lib: auf asuro werden nur 18pages geflasht
Das er am Anfang nicht einfach gerade fährt, liegt wohl an dem Teil wo:
posmarker =0; gesetzt wird. posmarker wird aber nicht größer 10 und somit wird alles unter else ausgeführt weil if nicht zutrifft >.<
mal weiter grübeln und deine idee mal verstehen und umsetzen :D
-
Soho! ^^
Der Code sieht jetzt wiefolgt aus:
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)
{
count72kHz = 0;
TCCR2 = (1 << WGM21) | (1 << COM20) | (1 << CS20);
// Toggling of IO-Pin on
// generate the Chirp
while(count72kHz < length) {
OCR2 = 0x64 + length / 2 - count72kHz;
}
TCCR2 = (1 << WGM21) | (1 << CS20); // Toggling of IO-Pin off
OCR2 = 0x64; // set frequency to 40kHz
}
int main(void)
{
int pos, i;
int posmarker;
unsigned char aci,acsr;
Init();
LocalInit();
while(TRUE){
posmarker = 0;
Ping(20);
for(pos = 0; pos < 100; pos++) {
Sleep(10);
aci = ( 1 << ACI ) ;
acsr = ACSR & aci ;
if ( acsr != 0 ) {
if(posmarker == 0) { posmarker = pos; }
}
ACSR |= (1 << ACI);
}
if(posmarker < 13) {
StatusLED(GREEN);
MotorDir(FWD, RWD);
MotorSpeed(0,170);
}
else {
StatusLED(RED);
MotorDir(FWD, FWD);
MotorSpeed(200,200);
for(i = 0; i<100; i++) { Sleep(200); }
}
}
return 0;
}
jetzt läfuts fast so wie ich will. Nur das wohl manchmal auch ohne Hinderniss der wert von "posmarker" über 13 steigt.