I'm trying to make a delay circuit for my car to change the charge time for the iginition coils. The signal is low and then goes high for 5ms to charge the coils, when the signal goes low again it fires the coil. The new coils I have need a 3ms charge time so I plan to delay the charge signal by 2ms. That falling edge to fire is very important. But, I'm having trouble getting really tight timing despite using interrupts. Any help you can offer would be greatly appreciated.
First the hardware, I'm using a ATMEGA8 @ 8MHz with no XTAL or Bootloader. Here is my Board.txt settings.
atmega8.name=Arduino NG or older w/ ATmega8
atmega8.upload.using=usbtinyisp
atmega8.upload.protocol=stk500 atmega8.upload.maximum_size=7168 atmega8.upload.speed=19200
atmega8.bootloader.low_fuses=0xd4 atmega8.bootloader.high_fuses=0xc4 atmega8.bootloader.path=atmega8 atmega8.bootloader.file=ATmegaBOOT.hex atmega8.bootloader.unlock_bits=0x3F atmega8.bootloader.lock_bits=0x0F
atmega8.build.mcu=atmega8 atmega8.build.f_cpu=8000000L atmega8.build.core=arduino
My first program is just following the input, so I could test the hardware, 47uf Cap, .1uf Cap, NPN transistors, and a 74HC7014N buffer chip. I'm using 5ms square wave to signal the Mega8. According to my scope the output from the Mega8 is about 100uS behind the pulse. I would expect maybe a couple of uS but 100 is bad for this project. It would throw my timing off.
Here is my Code for the Mega8:
const int OutputCOPA = 5; const int OutputCOPB = 8;
const int InputCOPA = 2; const int InputCOPB = 3; void setup() { // put your setup code here, to run once:
pinMode(OutputCOPA, OUTPUT); pinMode(OutputCOPB, OUTPUT);
pinMode(InputCOPA, INPUT); pinMode(InputCOPB, INPUT);
attachInterrupt(0, int1, CHANGE);//pin2 attachInterrupt(1, int2, CHANGE); // pin3
digitalWrite(OutputCOPA,HIGH); digitalWrite(OutputCOPB,HIGH);
}
void loop() { //Not Used Yet }
void int1(){ Timer1 = micros(); if (digitalRead(InputCOPA) == true){ digitalWrite(OutputCOPA,LOW); } else { digitalWrite(OutputCOPA,HIGH); }
}
void int2(){ Timer2 = micros(); if (digitalRead(InputCOPA) == true){ digitalWrite(OutputCOPB,LOW); } else { digitalWrite(OutputCOPB,HIGH); } }