PWM help

I am new to Arduino and need some very basic help I have a project to try out. I want to read PWM pulse time from a EFI fuel injector which runs from about 2 m/sec to about 10 m/sec then send the signal back out the Arduino I want to be able to add to the pulse time with a vr pot up to about 30% I am new to all of this and have been doing a lot of reading and now going around in circles I was thought i would use Pulsein to measure the pulse time in m/sec then analog for the vr input and calculate the output i want my question is What is the best way to generate a PWM out put or is there a better way to do this

Do the incoming EFI and outgoing PWM pulses need to be synchronized ? I suspect they do.

If so, this is going to get a bit technical, and you may need to read the relevant Arduino pages to understand what I'm going on about ;-)

Anyway, assuming you need synchronisation

You are better off using an interrupt e.g pin 2 for interrupt 0, that triggers on Change (rising or falling edge), and handle the delay to lengthen the pulse using another timer eg timer2

Then just read the analogue input from the pot in the main loop and store it in a variable (you may need to mark the variable as volatile )

So that in the interrupt routine when the EFI pulse starts, you get the current nanoseconds and turn on the output pulse

When the EFI pulse ends, the interrupt will be called again, and in the interrupt handler, you get the nanosecond time and compare it to the start time, this gives you the pulse length from the EFI, you then take the value from the pot that you have previously stored (in the main loop() and calculate the addition time required before the EFI pulse output needs to end. You then start a timer with this delay time.

When the interrupt is called on the timer (i.e its complete), you end the EFI output pulse

And around you go !

Thanks for the response. synchronization would be good but not critical That is mostly beyond my knowledge at this stage I will take your advice and do some more reading. Thanks for pointing in the right direction Are there any examples around you can direct me to?

If you don't need synchronization it would be easier, but I'm not sure about the precision you require.

You could just use Analog write http://arduino.cc/en/Reference/analogWrite to generate the PWM but I'm not sure if setting up the using the normal dividers etc is going to give you the level of control you need.

For reading the pulse width you could use pulsein http://arduino.cc/en/Reference/pulseIn

i used this for reading the feul injector of my aprilia scooter ,
it reads on pin pulses on pin 5 and send them true to pin 8 ,
but the delay can give problems , this i onley used to read the value’s
and send them back out so i can see the response of the motor ,

// sketch for testing incoming pwm values //
int throtv;
#include <Servo.h> 
Servo throttle; 
void setup() {
  Serial.begin(9600); 
  Serial.println (" input pwm testing on pin 6");
  delay (400); 
  pinMode(5, INPUT); // Set input channel for throttle on pin 6 from rx //
  throttle.attach(8);
}

void loop(){
  throtv = pulseIn(5, HIGH, 20000); //checking throttle input
  Serial.print ("PWM = ");
  Serial.println (throtv);
  throttle.writeMicroseconds(throtv); // set throttle output to 0 for starting kk2.0 //
  delay (1100); // this delay i use to read the values ,, but this can delay also the in and output
}

if i am right you want to add a extra 30 % injector rate , before or after ,
to speed things up , to see the best performance ?

sorry added this later ,
when you talk about injector ,
i think about a engine ,
and a spark example

normaly a engine wil spark , when cilinder shaft is in right position , and feul is injected ,
and the spark wil spark at a certain time , and whe have a cumbustion :smiley:
so if you want to do injector mods , like let say , change the timing of the feul getting sprayed in the engine ,
the spark time also needs to be changed ,
example , when you let say increase 30 % of feul injector , and the timing from the spark = sparking ,
you wil have a burned injector ,
or do you want to increase the volume of the injector spray in the engine by 30 % ?
:grin:

please explain , because your idea can have nice effects ,

I want to increase the PWM length some where from 10% 30% longer
to add more fuel to the engine depending on the vr pot
At the start would be better but i think it will be harder so at the
end will be ok synchronization is not critical. If there is a time difference
between the injector read pulse and pwm out that will be ok
the main thing is to be able to add the extra fuel with the vr pot

i am dutch so my english is not super ,, but the stuf you use ,, is the voltage compatible ,,, to use a arduino or do you need to change voltages also ,,, i can change the sketch ,,, example input is live output ,, normal mode no % added input increased 30 ,, overide mode 30 % added to the tottal sum this can also mean 2 things

i have let say 1000 i ad 30 % = 1030 ,, when i give more gas my 1000 wil be 1030 ,, the added 30 % wil make this 1030 /100 =1040.3 if i use it in the full curve !

this is wat you want , a ful curved added % adde true a potential ,

or do you onley want to ad 30 proccent 1000 /100 = 10 so 30 % = 300 .. and ad this to the incoming value ?

LOL hard explain ,, you want the first method i think ?

I want to use a variable pot to add from 0 up to 30% to the duty cycle of the fuel injector over the whole range I have set a voltage divider to lower the 12v to 5v and will use mosfets to power the injectors. I am stumped with the digital PWM output any examples will be great

throttle.writeMicroseconds(throtv); throtv can be also number ,,, exapmle throttle.writeMicroseconds(1500); == mid pos for a servo servo.writeMicroseconds(1800);

you can use pulses or a range from 1-180

i can write a example , make a picture or drawing how you want this connected ,
and what electronics you have !

To keep it simple i have injector pulse in I will use a variable pot to analog in and want a square wave pulse out

The var pot will lengthen the duty cycle depending on its position An example would be great Thanks

rogerClark: If you don't need synchronization it would be easier, but I'm not sure about the precision you require.

You could just use Analog write http://arduino.cc/en/Reference/analogWrite to generate the PWM but I'm not sure if setting up the using the normal dividers etc is going to give you the level of control you need.

For reading the pulse width you could use pulsein http://arduino.cc/en/Reference/pulseIn

Hi Roger, i came across your reply and could do with a question answering i am thinking of using two Arduino Nano's connected via the TX RX lines and want to use one to have 4 potentiometers for position and the other to have 4 PVM lines to operate 4 servos connected to a camera, what i want to do is when you move a potentiometer one way that the servo starts to move in that direction and the further you move it the faster the servo moves and the opposite for the other way, at the moment i am using one of my radio control transmitters and receivers to get it to work but i would like to do it via the nano's. as i am new to this i am just guessing that it could be done i can program my transmitter to do it and even set the different end points for the 4 servos but trying to do it via Arduino is a new one to me.

regards Poppy Ann.