Low Tec signal generator

I’m working on a fuel efficiency gauge and needed a way to test on the bench. This is basically two duinos. One (the plain chip and crystal) has been programmed in arduino to simulate a vehicle vss and injector signal, and the other is running the mpg gauge code. The test code is at the bottom. Now it isn’t single digit microsecond accurate, but it also isn’t limited by the number of timers either. With this approach you can generate a lot of different signals, i.e. buttons, etc. And since both the mpg gauge and the signal generator are connected to the computer simultaneously it is quite possible to have a PC program with all kinds of scenarios that tell the signal generator what to generate and get the result from the gunio to see if it is correct. Maybe someone will find the techniques useful, the microseconds function is going to break in 0012 though :frowning:

//GPL Software 
//cheesey signal generator, made for bench testing the mpguino
//signal generator pins
#define sig1Pin 2   //inj
#define sig2Pin 3   

//overflow counter used by millis()   
extern volatile unsigned long timer0_overflow_count;   
unsigned long lastMicroSeconds=millis() * 1000;
unsigned long microSeconds (void){  
  unsigned long tmp_timer0_overflow_count; 
  unsigned long tmp; 
  byte tmp_tcnt0; 
  cli(); //disable interrupts 
  tmp_timer0_overflow_count = timer0_overflow_count; 
  tmp_tcnt0 = TCNT0; 
  sei(); // enable interrupts 
  tmp = ((tmp_timer0_overflow_count << 8) + tmp_tcnt0) * 4;  
  if((tmp<=lastMicroSeconds) && (lastMicroSeconds<4290560000ul)) 
    return microSeconds();  
  return tmp;  

unsigned long elapsedMicroseconds(unsigned long startMicroSeconds, unsigned long msec ){   
  if(msec >= startMicroSeconds)   
    return msec-startMicroSeconds;   
  return 4294967295 - (startMicroSeconds-msec);   

metro signal generator notes:
//#define vssPulsesPerMile 10000ul   
//#define microSecondsPerGallon 267857143ul //injector flow rate   
@20mph, 4th gear
~44000uS injector open time per 1/2 second
18 inj pulses per 1/2 second
55 vss pulses per 1/2 second
sig1, off for 2444uS, on for 25333uS
sig2, on for 16000uS, off for 2180uS
unsigned long sig1Start; //injector
byte sig1State = HIGH; //injector 1=closed
unsigned long sig2Start; //vss
byte sig2State = LOW; //vss

#define sig1PinOffTime 2444
#define sig1PinOnTime 25333
#define sig2PinOnTime 16000
#define sig2PinOffTime 2180

void setup (void){    

void loop (void){    

  sig1Start = microSeconds();
  sig2Start = sig1Start;
    //snapshot of the time variables:
    unsigned long tmp = microSeconds();  
    unsigned long tmp1 = elapsedMicroseconds(sig1Start, tmp);  
    unsigned long tmp2 = elapsedMicroseconds(sig2Start, tmp);  

    //sig 1 timing logic
      if (tmp1>=sig1PinOnTime){
      if (tmp1>=sig1PinOffTime){

    //sig 2 timing logic
      if (tmp2>=sig2PinOnTime){
      if (tmp2>=sig2PinOffTime){


     //sig3?  sigX?