Hi! New to the arduino forum, i´m a bit familiar with arduino but not an expert by any means.
Just wanted to ask a question about a project i´m doing where i simulate the output of an rpm sensor of an engine, which has 60 teeth (pulses fro 1 to 0), the thing is, in engines, there is two missing teeth to mark the top dead center of piston 1 usually.
Now that is not the problem, but contributes to the main problem, processing speed of arduino with my code, wich i´ll attach.
I´ll be attaching a pic with an image of what a wheel looks like, so you have a better idea. 
there´s two false teeth 180º apart in the wheel i´m trying to replicate whereas this one only has one flase tooth.

This is what the rpm sensor output looks like, now, i know this is not a square signal, but square signa does the job, just so you have a better idea of what the false tooth looks like.
Back to the problem. So the problem is that at 6000 rpm (100rps) a spin lasts 10ms, with 60 teeth, and 120 switches from 0 to 1, the gap is 83 microseconds between high and low, the problem shows in the first teeth of every spin, because i have to map a potenciometer to move the rps value, and show the rpm in a LCD screen, wich takes too much time and slows the process, making the signal bad and generating an error in the ECU i´m trying to trick in thinking there´s an engine running.
Btw i´m using an Arduino UNO Rev3.
Any ideas on how i can make it easier for arduino to run this program quicker? I´ve already used port manipulation to make the change between bool values faster, although the problem remains in the mapping and calculations for rpm and rps.
Thanks in advance!
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int val;
int pot = 3;
int rps;
int rpm;
int teeth = 60; //Teeth count
int interval; //interval between switch from 1 to 0
int count;
int output = 5;
void setup() {
lcd.begin(16, 2);
lcd.print("RPM");
lcd.setCursor(0, 1);
pinMode(output, OUTPUT);
}
void loop() {
for (count = 0; count < teeth; count++) { //for loop for teeth count
val = analogRead(pot);
rps = map(val, 0, 1023, 10, 50); //pot map to revs per second (min-600rpm, max 3000rpm)
rpm = (rps * 60);
interval = (((1000000 / (rps * teeth)) / 2)); //interval in microseconds
lcd.print(rpm);
if (count = 0 or 1 or 30 or 31) { //flase teeth 0
digitalWrite(output, LOW); // pin 5 = 0
delayMicroseconds(interval);
}
else if (count = 2 or 3 or 32 or 33) { //false teeth 1
digitalWrite(output, HIGH); //pin 5 = 1
delayMicroseconds(interval);
}
else { //normal functioning
digitalWrite(output, LOW); // pin 5 = 0
delayMicroseconds(interval);
digitalWrite(output, HIGH); //pin 5 = 1
delayMicroseconds(interval);
}
}
}
Proyecto.ino (1.3 KB)
