Int value servo control and program flow

A 20.9kW IC engine driving a 10kW generator doesn't sound very efficient. What generator RPM to get 60Hz? What engine RPM to get required generator RPM? What is the flywheel mass? How is the engine speed controlled now?

wow glad you have shown interest. Well it does appear to be overkill but I have configured this setup for the following reasons. (Having performed stress tests on a multitude of generators of various name brands providing 3500-17500 kw output.)

  1. Single cylinder splash lubrication engines, regardless of brand, have proven to be good for about 4 months of continuous 24/7 use. Strict maintenance practices provide at best an additional 20-30 days of life. Operating speed 3600 rpm.

  2. Generator head is a 3phase/1phase industrial continuous duty 10Kva providing single phase service. Driven pulley: 3 belt (5/8") 12 inch diam. 2 inch shaft mount. 4 pole 1800 rpm 220Vac @ 60Hz.

  3. Generac 993cc engine. Drive pully 2 belt (5/8") 8" diam. Total weight including motor shaft adapter ~8-10 lbs. Operating speed is ~2000 rpm. The engine provides sufficient power at this rpm.

Lower rpm should double or greater the expected life of engine. I have experimented and tested this setup with single cylinder 8 -15 hp engines. Approxiamtely the same belt ratio was maintianed with all engines tested.. Although the power output fell a bit short of needed power, a reliable throttle control would have provided better performance from the higher hp engines. (Thus the reason I started this project.) However operating at about 2/3 +/- normal rpm the realized engine life increased 2.5 - 3 fold in most cases. A predator 420cc motor providing a full 12 months of 24 /7 service. The engines were all naturally aspirated natural gas fueled with no special adapters other than a supply hose hole drilled in the factory air boxes. (A parker gas solenoid valve 120vac directly wired to the generator ouput is the safety check. no output = no fuel. Engine primed to start process)

Currently (using the 993 engine and same gen head) the throttle is fixed and the load is kept as constant as can possible. Avg load is 10 amps. Demand load can jump to 18 -25 amps depending on appliance use which is kept to a minimum. The system is tolerant of 108vac to 132 vac range but the Hz output will vary from 52-65 hz within those voltages. My goal is to maintain a 60Hz. output. All of the power is routed through 2 Trace engineering 4000kw power inverters. I also have 2 1400 watt solar arrays feeding the inverters. My batteries are undersized but that is another discussion altogether. This should give you the broad vision of what im doing.

thanks for your input. The frequency measurement was taken from example along with the circuit and code. The measurement element worked acutally quite well until i started trying to add code for the servo control and logic.

That is where timing issues came into play and my lack of knowledge regarding functions calls.... well here i am. lol.

I really appreciate the time anyone takes to provide input about this project. Again I cant say thanks enough.

Can you revert to the working code and post that? Perhaps we can see a way to gradually add some more functionality.

Why do you want to trade the servo for a stepper? It's not a big deal, but the stepper solution probably means you'll need to home it at startup to a microswitch so you know where it is. I suppose you might not care, but just know from frequency readings that you have to turn one way or the other.


#include <LiquidCrystal.h>
#define rs 9 
#define en 8 
#define d4 7 
#define d5 6  
#define d6 5 
#define d7 4 
volatile byte freqcount;
unsigned int frequency;
unsigned long timeold;
int frequency1;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void freq_fun()
   //ac cycle, this interrupt function is run twice, so take that into consideration for 
   //calculating frequency
   //Update count
void setup()
   lcd.begin(16, 2);  // intialise the LCD
   //Interrupt 0 is digital pin 2, so that is where the output from the transistor is connected
   //Triggers on FALLING (change from HIGH to LOW)
   attachInterrupt(0, freq_fun, FALLING);
   freqcount = 0;
   frequency = 0;
   timeold = 0;
 void loop()
   //Update frequency every second
   //Don't process interrupts during calculations
    frequency = 60*50/(millis() - timeold)*freqcount; 
   timeold = millis();
   freqcount = 0;
   Serial.print("Frequency: ");
   frequency1 = frequency/4;
     //Print out result to lcd
   //Restart the interrupt processing
   attachInterrupt(0, freq_fun, FALLING);

This is what I started with. The example is provided by Electronics Clinic.
I am using an optocoupler in my setup. The following is the PCB from the schematic i provided above:

I was in the process of mapping the components to the Arduino pin numbers but didnt quite finish it.

I recently acquired the 993 generac motor and it utilizes a stepper motor for throttle control of a NG carberator.

I have and I2C port built on the PCB which was intended for an lcd but if you think we can salvage the current configuration then we could make use of the I2C for the stepper control. Could we not?


I stated " The following is the PCB from the schematic i provided above:"

I was refering to schematic @ post #12.

Also the I2c is in the schematic. The PCB location is adjacent to the Nano and springed terminal.

Your interrupt handling isn't optimal. You don't need to detach the handler, just stop interrupts briefly with noInterrupts. Also, they should be off for as little time as possible, just long enough to copy freqcount to another variable for calculation and then set it to zero. All the printing to serial and LCD can be done later.


frequency = 60*50/(millis() - timeold)*freqcount;

timeold = millis();
freqcount = 0;

//Restart the interrupt processing

Like that?

im supposing the machine code is quite lengthy to detach ?

my bad im an idiot sometimes. here is the schematic that matches the PCB post production.
genschemrev729.pdf (69.3 KB)

ill clean these posts up in the next day or so with corrections in propper places

I'm not completely sure what you're asking here, but I suspect it is quicker to turn interrupts off and on than to drop the handler and re-apply it. Probably not by much, but usually, if you're processing interrupts, speed is important.

use noInterrupts() and interrupts()

won't using a full-wave rectifying bridge result in 120 Hz?

why not use an opto-coupler and open-collector circuit with internal pullup resistor (i.e. INPUT_PULLUP)?

I am using an opto-coupler. 5vac rectified -> DC -> opto-coupler. This mapped to pin D2 of the Arduino. Im at a bit of a loss as to how the pullup resistor would play into the scheme. The rectifying bridge may verywell result in 120hz however it is isolated and is only used for the opto-coupler signaling.

The original circuit used a 2n2222 transistor but that wasnt an ideal setup for obvious reasons. The author reduced the 220AC to 12DC and used a voltage divider to further lower the input voltage to accomodate the 2n2222. I however adopted the 2n2222 for controlling the relays on the PCB.

This setup was from an example I got from Electronic Clinic. There may be better ways to measure AC current but it seemed like the simplest to build when I started this project. I am completely open to suggestions for a better method.

I was referring to the C++ being converted to binary and the length of instructions for attaching vs switching interrupts. It is my understanding that C++ simplifies some instructions that convert to rather lengthy machine code.

but this affects the frequency measurement

i think you're missing the point. noInterrupt/interrupt() are the proper way to temporarily disable interrupts around "critical sections"

I understand and thank you for your input. It is duly noted and I will try the sketch with those corrections.

Regarding the 120hz: Since the measurement is calculated anyway it seems like the that could be compensated for easily.

The points being made here are very good ones. I am just using examples I found. However the 120hz factor was mitigated by the original creator I believe because when starting this project I used a breadboard and arduino to validate the AC power monitoring function. It worked well. Timing issues didnt arise until I started to lengthen the sketch code with servo commands

check post for respnse.

you defend a design that doesn't appear to work properly.

hard to help

Ugg. Thats not what I was expecting to hear lol. Im not trying to defend just explain. I will search for another way to sample the AC signal. Perhaps the example I used cannot be added to readily.

I think I may have been working towards something which requires far more skill and knowledge than I could possibly tackle as a part-time project.

I found my solution and for anyone interested in a complete technical explanation check this link:

stepper throttle control

I never dreamed it would be that technical to be 100% reliable.
Good luck to everyone trying to do the same. I am not giving up but just gonna take some time for research a whole bunch more.

Thanks to everyone who contributed!!!!