Hi all, I have a project I would like some help with. The code I have so far is attached and works great. It is on a pro mini 16Mhz clone. I repair CDI modules for mowers and other small engines and for a couple years I have had a 555 timer that I have used for testing. It is lacking in several ways. Now I have started this project that will have:
1) a LCD to display rpm from 500 to 3000 2) generate a pulse at intervals from 120Ms to 20Ms to trigger the CDI (one pulse / revolution) 3) generate pulses at 50Hz to 300Hz to simulate the charging coils. Here may be the tricky part, as there are 6 pulses per revolution, but skip every 6th pulse and have that time interval align with the above triggering pulse. (you don't want a triggering pulse at the same time the charging coil has output because the part that the charging coil charges is shorted at that moment) 4) input the trigger pulse and also input a signal from the coil and display the time interval as ° timing, as at low rpm there is a delay varying from 100us to 0us approx. The delay at low rpm is taken away at higher rpm to produce advance.
What I have so far is the LCD which works well and displays the rpm. Also for now I had it display the Ms between pulses just to be sure it was changing correctly. The pulse out I made 1Ms and used 2 transistors to switch 12 vdc to the input of the CDI, works well. I added the pin 7 output as the future high pulse rate simulating charging coils. I will feed this also with 2 transistors through a transformer to obtain approx 200 vac. Thanks, hope it is not to ambitious! (edited errors)
//Pulse Generator Arduino Code
#include "U8glib.h"
U8GLIB_ST7920_128X64_1X u8g(13, 11, 10); // SPI Com: SCK = en = 15, MOSI = rw = 16, CS = di = 17
int pot1 = A5; // select the input pin for the pot
int potValue = 0; // variable to store the value coming from the sensor
int pulseValue = 0; // 2 variables from one pot
int delayValue = 0;
int outputPin = 8; // select the pin for the output for trigger pulse
int chargePin = 7; // select the pin for the output for charge pulses
void draw() {
// graphic commands to redraw the complete screen should be placed here
u8g.setPrintPos(0, 15); // call procedure from base class, http://arduino.cc/en/Serial/Print
u8g.print("RPM =");
u8g.setPrintPos(50, 15);
u8g.print(potValue);
u8g.setPrintPos(8, 30);
u8g.print("Ms =");
u8g.setPrintPos(50, 30);
u8g.print(pulseValue);
u8g.setPrintPos(0, 45);
u8g.print("Advance =");
u8g.setPrintPos(80, 45);
u8g.print("10"); // for use in future code
}
void setup() {
Serial.begin(115200); // serial com speed for display
// flip screen, if required
// u8g.setRot180();
pinMode(outputPin, OUTPUT); // declare the outputPin as an OUTPUT
pinMode(chargePin, OUTPUT); // declare the chargePin as an OUTPUT
u8g.firstPage();
u8g.setFont(u8g_font_unifont);
delay (2000);
//Timer1 set up 2ms pulse every 50 ms
TCCR1A = 0;
TCCR1B = (1 << WGM12);//CTC mode to OCR1A
OCR1A = 12500; //50 ms to top value
TIMSK1 |= (1 << OCIE1A);//interrupt enable compareA
TIMSK1 |= (1 << OCIE1B);//interrupt enable compareB
OCR1B = 250; //1 ms pulse width
TCCR1B |= (1 << CS11) |(1<