Hallo zusammen
bin neu in diesem Forum habe in sachen Arduino schon ein bisschen Erfahrung gesammelt und schon einige kleine Projekte realisiert
aktuell möchte ich gerne für die Carrera Digital meine eigene CU basteln
und zwar möchte ich gene die Funktion void manchesterEncode() in einen interrupt setzen
sie soll alle 7500 microsekunden ausgeführt werden habe schon einiges probiert aber es hat nichts funktioniert vl kann mir ja jemand helfen
const int dataOutPin = 3; // connection to MOSFET driver circuit
const long wordRateMicros = 7500; // send a new data word every 7,5 ms
unsigned long intervalWordMicros = 0; // will store the time difference to last word(microseconds)
unsigned long previousWordMicros = 0; // will store last time when a word has been send (microseconds)
unsigned long currentMicros = 0; // will store the current runtime (microseconds)
void setup() { //////
Serial.begin(115200); // initialize serial bus
pinMode(dataOutPin, OUTPUT); // initialize the dataPin as an output
digitalWrite( dataOutPin, HIGH ); // set output Pin to HIGH, racetrack voltage is default 20 V
} //////
void loop() { //////
currentMicros = micros(); // store current runtime
intervalWordMicros = currentMicros - previousWordMicros; // calculate interval
if (intervalWordMicros > wordRateMicros) { // is time to start a new data word?
previousWordMicros = currentMicros; // new data word starts
manchesterEncode( 648 );} //binary:0000001010001000,controller2,
}
void manchesterEncode(word dataWord){ //////
const int halfClockMicros = 40; // experimental value for half clock rate of 50 microseconds on 16 MHz Arduino Uno
int bitPos = 13; // bit counter for position of bit in dataWord
int currentBit = 0; // store current bit
while ( !currentBit ){ //
currentBit = ( dataWord >> bitPos ) & 1; // store bit on position bitPos in currentBit, currentBit becomes 0 or 1
bitPos--;} // switch to next postion
bitPos++; // get back to start bit
do{ //
currentBit = ( dataWord >> bitPos ) & 1; // store bit on position bitPos in currentBit, currentBit becomes 0 or 1
if ( currentBit == 1 ){ //
digitalWrite( dataOutPin, HIGH ); //
delayMicroseconds ( halfClockMicros ); //
digitalWrite( dataOutPin, LOW); //
delayMicroseconds ( halfClockMicros );} //
else{ //
digitalWrite( dataOutPin, LOW ); //
delayMicroseconds ( halfClockMicros ); //
digitalWrite( dataOutPin, HIGH ); //
delayMicroseconds ( halfClockMicros );} //
bitPos --; // goto next bit
} while ( bitPos >= 0 ); // until all bits are processed
digitalWrite(dataOutPin, HIGH ); // make sure to leave subroutine always with digital level HIGH
}