hmm. ich kann beim besten willen den fehler nicht finden...
Code:
#include "RP6ControlLib.h"
#include "RP6I2CmasterTWI.h"
#include "RP6Control_I2CMasterLib.h"
void I2C_requestedDataReady(uint8_t dataRequestID)
{
checkRP6Status(dataRequestID);
}
void I2C_transmissionError(uint8_t errorState)
{
writeString_P("\nI2C ERROR - TWI STATE: 0x");
writeInteger(errorState, HEX);
writeChar('\n');
}
volatile uint16_t speed=0;
volatile uint16_t dir=0;
volatile uint16_t speedcount=0;
volatile uint16_t dircount=0;
ISR(TIMER1_COMPA_vect)
{
if (PINA & ADC5)
{
speedcount++;
}
else
{
if (speedcount > 0)
{
speed=speedcount;
}
speedcount=0;
}
if (PINA & ADC3)
{
dircount++;
}
else
{
if (dircount > 0)
{
dir=dircount;
}
dircount=0;
}
}
void initRC(void)
{
TCCR1A = (0 << WGM11) | (0 << WGM10) | (0 << COM1A0) | (0 << COM1A1); // CTC-Mode4, ohne OCR-Pin
TCCR1B = (0 << WGM13) | (1 << WGM12) | (0 << CS12) | (1 << CS11) | (0 << CS10); // CTC und prescaler /8
TIMSK |= (1 << OCIE1A); // Interrupt ein
OCR1A = 20; // 100kHz?
DDRA &= ~ADC5;
PORTA &= ~ADC5;
DDRA &= ~ADC3;
PORTA &= ~ADC3;
}
int main(void)
{
initRP6Control();
initLCD();
initRC();
startStopwatch1();
mSleep(1000);
I2CTWI_initMaster(100);
I2CTWI_setRequestedDataReadyHandler(I2C_requestedDataReady);
I2CTWI_setTransmissionErrorHandler(I2C_transmissionError);
uint16_t speed1, dir1;
while(1)
{
cli(); // Interrupts verbieten
speed1=speed;
dir1=dir;
sei(); // Interrupts wieder zulassen
if (speed1 < 150 && speed1 > 140)
{
if (dir1 > 180){ setMotorDir(BWD,FWD); setMotorPower(150,150); }
if (dir1 < 120){ setMotorDir(FWD,BWD); setMotorPower(150,150); }
}
if (speed1 < 140)
{
setMotorDir(BWD, BWD);
if(dir1 < 140){ setMotorPower((300-speed1),(300-speed1)-dir1); }
if(dir1 > 150){ setMotorPower((300-speed1)-(300-dir1),(300-speed1)); }
if(dir1 < 150 && dir1 > 140) { setMotorPower(300-speed1, 300-speed1); }
}
if (speed1 > 150)
{
setMotorDir(FWD, FWD);
if(dir1 < 140){ setMotorPower(speed1+dir1,speed1-dir1); }
if(dir1 > 150){ setMotorPower(speed1-(300-dir1), speed1+(300-dir1)); }
if(dir1 < 150 && dir1 > 140) { setMotorPower(speed1, speed1); }
}
if(adcLSL < 500 || adcLSR < 500) { PORTA |= ADC7; }
if(adcLSL > 500 && adcLSR > 500) { PORTA &= ~ADC7; }
task_checkINT0();
task_I2CTWI();
}
return 0;
}
bin ich blind oder was -.- ?
Lesezeichen