plusewidth and frequentie

I will make a simulator for two signals (fuelinjector on and speedsensor), so I can test the MPGUINO offline (not on the vehicle motorcycle)

i'm thinking on the next signals:

signal 1 ; high signal become low for 10 mS with a frequency of 30 Hz (injector)

signal 2 ; high signal become low for 2 mS with a frequency of 600 Hz (speedsensor)

electronics/mechanics and vehicle technics I understand more or less, but programming arduino?, I a'm a very beginner, but trying and willing to learn

who can help me with some good idears or a working sketch?

best regards Wim

Looking at signal 1.
30 hz is 33.333 ms.
You want it on for 10 ms, and off for 23 ms ?

Is this program intended to run for more than 4 weeks without resetting the processor? Since it seems to need multi tasking to do signal 1 and signal 2, there are a couple ways to do that, depending on how long the program will be running.

I was a little to fast witch sending,

signal 1: 30 Hz= 1000/30 = 33 Ms for one period so the signal I want = 23 mS on (5 V), 10 mS off (0 V)

signal 2: 600 Hz= 1000/600=1,67 mS for one period, so the signal i want= 1,5 mS on , 0,1 mS off

this signals will only be used on the workbench for a short moment (to see iff the MPGUINO is working correctly, when everything is working correctly, i will mount it on the motorcycle..

accuracy is not so important, because it is only for test purpose

The demo several things at a time illustrates how to use millis() to manage timing. The technique also works with micros()

It should not be difficult to adapt the code to do what you want.

...R

Since signal 2 is faster, you need to use micros() rather than millis().
That would make
signal 1: ON 23000 micros and OFF 10000 micros
signal 2: ON 1500 micros and off 100 micros

Check the reference for micros(), there can be some differences depending on which board you are using.

If you have more questions, just ask.

thanks for everyone, the problem is solved

Great, you have it solved.
Would you mind sharing your results/script with us. Someone else may need a similar setup, and would benefit from your solution. Thanks

#include "Arduino.h"
//
// Pin definitions
//
#define PULSE_33 3 // pulse 33 Hz op pin 3
#define PULSE_670 4 // pulse 670 Hz op pin 4

//
// global defines & parameters
//
#define HZ_33_H 20303 // 20303 micro seconden voor de 33 Hz Hoog duur
#define HZ_33_L 10000 // 10000 micro seconden voor de 33 Hz Laag duur
#define HZ_670_H 493 // 493 micro seconden voor de 670 hz Hoog duur
#define HZ_670_L 1000 // 1000 micro seconden voor de 670 hz Laag duur

enum {
laag, // simpele verwijzing naar array indices
hoog
};

enum {
Hz_33, // verwijst naar de 33 Hz waarden
Hz_670 // verwijst naar de 670 Hz waarden
};

//
// global variables
//
uint32_t timer1; // timer voor de 33 Hz
uint32_t timer2; // timer voor de 670 Hz
uint32_t timerWaarden[2][2]; // bevat de tijdsduur voor de puls timers
uint8_t Hz_33_Level; // verwijst naar hoog of laag duur 33 Hz puls
uint8_t Hz_670_Level; // verwijst naar hoog of laag duur 670 Hz Puls

/**

  • @name setup()
  • initialize the program
    */
    void setup()
    {
    //
    // setup IO poorten
    //
    pinMode(PULSE_33 , OUTPUT);
    pinMode(PULSE_670 , OUTPUT);
    //
    // opzetten array met de timer waarden
    //
    timerWaarden[Hz_33][laag] = HZ_33_L;
    timerWaarden[Hz_33][hoog] = HZ_33_H;
    timerWaarden[Hz_670][laag] = HZ_670_L;
    timerWaarden[Hz_670][hoog] = HZ_670_H;

Hz_33_Level = hoog;
Hz_670_Level = hoog;
//
// start de timers (we werken met micro seconden voor enige
// nauwkeurigheid)
//
timer1 = micros();
timer2 = micros();
//
// schrijf de waardes naar de pinnen
//
digitalWrite(PULSE_33 , Hz_33_Level);
digitalWrite(PULSE_670 , Hz_670_Level);
}

/**

  • @name loop()
  • main loop of program and runs endlessly
    */
    void loop()
    {
    uint32_t nu = micros();
    //
    // test de 33 Hz timer
    //
    if ((nu - timer1) > timerWaarden[Hz_33][Hz_33_Level]) {
    //
    // we moeten de polariteit wisselen
    //
    Hz_33_Level = !Hz_33_Level;
    //
    // schrijf alvast de output
    //
    digitalWrite(PULSE_33, Hz_33_Level);
    //
    // en start de timer voor de volgende switch
    //
    timer1 = nu + timerWaarden[Hz_33][Hz_33_Level];
    }
    //
    // test de 670 Hz timer
    //
    if ((nu - timer2) > timerWaarden[Hz_670][Hz_670_Level]) {
    //
    // we moeten de polariteit wisselen
    //
    Hz_670_Level = !Hz_670_Level;
    //
    // schrijf alvast de output
    //
    digitalWrite(PULSE_670, Hz_670_Level);
    //
    // en start de timer voor de volgende switch
    //
    timer1 = nu + timerWaarden[Hz_670][Hz_670_Level];
    }
    }

wim2584:
signal 1: 30 Hz= 1000/30 = 33 Ms for one period so the signal I want = 23 mS on (5 V), 10 mS off (0 V)
...
accuracy is not so important, because it is only for test purpose

Accuracy is absolutely important; 33Ms is well over a year (very nearly 382 days).

Please remember to use code tags when posting code