Kann mir bitte jemand mit Code helfen? Ich habe ein 24 Zähne Triggerrad. Jeder Zahn wird vom Hall-Sensor registriert und ich benötige, dass Arduino 36 Impulse des entsprechenden 24-Puls-Eingangs simuliert.Arduino C++ Berechnung Triggerpunkte
Hier ist mein Code mit DelayMicroseconds, aber ich kann DelayMicroseconds nicht verwenden, weil Arduino nicht größer als 16k Mikroverzögerung versteht.
const int hall = 2; // hall sensor
const int ledPin = 13; // the pin that the LED is attached to
// Variables will change:
int teethCounter = 0;
int hallState = 0;
int lasthallState = 0;
long cycles=0;
boolean cycle = false;
unsigned long microsStart = 0;
unsigned long microsStop = 0;
unsigned long usElapsed = 0;
unsigned long usElapsedUp = 0;
unsigned long usInterval;
void setup() {
// initialize the button pin as a input:
pinMode(hall, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
hallState = digitalRead(hall);
if(cycle==true){
microsStart=micros();
}
if(cycle==true){
usInterval = usElapsedUp/72;
for (int i=0; i <= 36; i++){
digitalWrite(13,HIGH);
delayMicroseconds(usInterval);
digitalWrite(13,LOW);
delayMicroseconds(usInterval);
cycle = false;
}
}
// compare the hallState to its previous state
if (hallState != lasthallState) {
// if the state has changed, increment the counter
if (hallState == HIGH) {
teethCounter++;
if(teethCounter==24){
cycle = true;
cycles++;
teethCounter=0;
usElapsedUp = usElapsed;
}
Serial.print("Tooth count: ");
Serial.print(teethCounter);
Serial.print(" Cycles: ");
Serial.print(cycles);
Serial.print(" Time: ");
Serial.print(usElapsedUp);
Serial.print(" Interval: ");
Serial.println(usInterval);
}
microsStop=micros();
usElapsed=microsStop-microsStart;
}
// save the current state as the last state,
//for next time through the loop
lasthallState = hallState;
}
Wie kann ich berechnen und ab wo kann ich Triggerpunkte nehmen?
If(event happens==true){
digitalWrite(13,HIGH);
}
If(event happens==false){
digitalWrite(13,LOW);
}
If it helps to understand here is a block diagram
Sie benötigen eine Art von Funktion, die von 24 bis 36 konvertiert; da dies kein 1: 1-Mapping ist. Woher kommen die zusätzlichen 12 Impulse? –
Möchten Sie von der 24-Puls-Frequenz * auf eine 36-Puls-Frequenz umrechnen? –
Ja, genau das brauche ich –