Author Topic: Arduino Analog Instruments  (Read 2176 times)

0 Members and 1 Guest are viewing this topic.


Offline Login to see usernames

  • Global Moderator
  • Hero member
  • ****
  • Posts: 3607
Re: Arduino gms
« Reply #9 on: August 15, 2018, 16:50:06 pm »
the arduino will be very useful on the gas management system because for resume it will make the same job much cheaper and easier to develop a full system and control the parameters to tune.. it only need one digital potentiometer to change the parameters and or a touch screen or connection with the computer or cell phone via wireless to show the data  being changed i will use a nextion touchscreen so i dont even need the digital potentiometer 

the main variables we have are

1 the injection timing that is stabilized at acceleration 0 using the pressure signal and frequency signal

2 the frequency compensation variable that is added or subtracted from the injection time to stabilize the rpm of idle at acceleration0

3 rpm - acceleration correlation   set the pedal as the range for the rpm for example at 0 its idle and at middle is 3000 rpm etc so the timing will need to be adjusted regardless of the pressure to reach that rpm when the pedal is pressed

so the accelerator sets directly the comparison rpm seems a good idea... because the program will know how where to go ...

ex at idle you have 1000rpm digital accelerator is set to 0v, than at 1v it is set to 2000rpm it can be set numerically on the program.

so until the car reach that rpm the sensor will keep increasing the timing of the injector to get there every time it reads and see that there is this difference

also we could create a system that instead link the gas production to this instead of only the timing of the injector

so basically until it reach that rpm number of counting it can control the gate time! or simply the gate time should have a direct relatioship with the pedal of course with the range adjustable for the engine

i believe that to have a good acceleration the idle should be at 15% gate or something like that..

than as we press the pedal the system will get crazy to produce the gas needed to reach the rpm set by the pedal



Hope all this reading is useful for you

soon i will post some arduino code here

but i have to buy some sensors and get a 4 stroke engine to play with... i have one here but is broken and i have no money to do either..

so i ask you gently if you believe please donate me... for as small as you can donate will sure help a lot! Every help will be thankful accepted.

i have a link for donations ..

 but if you want you can send me components or test equipments that are useful please send me an inbox 

 if you have any old stuff you dont use in your house do yourself a favor, sell it and do myself a favor donate 10% of what you sold for me or this website and you will fell much better =D



« Last Edit: August 15, 2018, 17:06:50 pm by sebosfato »

Offline Login to see usernames

  • Global Moderator
  • Hero member
  • ****
  • Posts: 3607
Re: Arduino Analog Instruments
« Reply #10 on: August 16, 2018, 04:19:19 am »
i was looking into interrupts that are a way to have a real time port on an arduino only at pin 2 or 3 can do this...

so basically the clock signal from the engine should triger an interrupt that will start a signal to the injectors with the lenght it calculates...

Offline Login to see usernames

  • Global Moderator
  • Hero member
  • ****
  • Posts: 3607
// this is arduino code
// there is 3 inputs one is the pressure signal and one is the clock signal and one is the acceleration pedal
//it will sense the acceleration pedal voltage 0-5v and convert to a set rpm from 0 to 6000 than it will compare the rpm reading with the set and determine the state if is accelerating or deaccelerating. if accelerating it will increase the injector timing until it reach the desired rpm or decrease if its deaccelerating by an increment decrement value
//now i need to stipulate the limits of this functions and a screen and a button to control it 


int clocksignal = 3; //
volatile float miliseconds = 5; // injection timming
int injector = 13;  // injector output
int rpmread = 0;
int accel = A0;   // analog/digital accelerator signal
int pressure = A1;
int rpmset = 0; // rpm determined by analog/digital accelerator
String state;
float timeincrement = 0.01;
float timedecrement = 0.01;
int mininjectiontime = 0;
int maxinjectiontime=10;

void setup() {
  Serial.begin(9600);
  pinMode(clocksignal, INPUT_PULLUP);
  pinMode(injector, OUTPUT);
  attachInterrupt(1, INJECTION, FALLING);

 

;}

void loop() {

 rpmset=(analogRead(accel)*5);   // rpm determined by analog/digital accelerator

 if (rpmset > rpmread ) {
  state="Accelerating" ;
  miliseconds=(miliseconds+timeincrement);
 
}
else {
  state="Deaccelerating";
  miliseconds=miliseconds-timedecrement;



}

  //Serial.println(digitalRead(timming));
  delay(500);
  Serial.print("Accelerator  ");
Serial.print(rpmset);
Serial.println("RPM SET");
Serial.print("Injection Time ");
Serial.print(miliseconds);
Serial.println(" miliseconds");
Serial.print(rpmread);
Serial.println(" RPM Measured ");
Serial.println(state);
 
}

void INJECTION() {
   digitalWrite(injector, HIGH);
   delayMicroseconds(miliseconds*1000);
   digitalWrite(injector, LOW);
   

   
   Serial.print("INJECTED");Serial.print(miliseconds);Serial.print("miliseconds");
   


Serial.println("");Serial.println("");Serial.println("");Serial.println("");
   
}


Offline Login to see usernames

  • Global Moderator
  • Hero member
  • ****
  • Posts: 3607
Re: Arduino Analog Instruments
« Reply #12 on: August 19, 2018, 07:44:25 am »
i added a taskscheduler to have multiple loops for different functions other than the interrupt... one is just to print on the serial monitor every 3 seconds... what i noticed is that to print the info causes instability of the signal but also without printing there are other factors to get hid off

i used one of the outputs of the arduino as a clock generator to test the rpm meter and worked but there is still some instability

i added the limits of the rpm and injector timing respectively 0-7000rpm 0-5v ,  1ms and 10ms.

so the accelerator set the rpm and the arduino set the injectors parameters until it matches the rpm desired

anyone who wants to help finding problems and solutions for them i appreciate




unsigned long newtime;
unsigned long lasttime;

#include <TaskScheduler.h>

int clocksignal = 3; // //input interrupt 1 / pin 3
float injectiontime = 5; //ms  injection timming
int injector = 13;  // injector output
int rpmread = 0;
int accel = A0;   // analog/digital accelerator signal
int pressure = A1;
int rpmset = 0; // rpm determined by analog/digital accelerator
String state;
float timeincrement = 0.1;
float timedecrement = 0.1;
int mininjectiontime = 1;
float maxinjectiontime=10;
int maxrpmset=7000;
int clockcount=0;
int lastclockcount;
int fakerpm=20; // 10ms=6000rpm 20ms=3000 30ms= 2000 60= 1020rpm 75 =780 //fakesignal repetition
int fakeclock = 5; //pin5 output fakeclock   --- connect to pin 3 for simulating engines on .. controle its rpm at task t4


void t1Callback();
void t2Callback();
void t3Callback();
void t4Callback();
//Tasks
Task t1(300, TASK_FOREVER, &t1Callback);    //
Task t2(3000, TASK_FOREVER, &t2Callback);     //
Task t3(500, TASK_FOREVER, &t3Callback); //
Task t4(fakerpm, TASK_FOREVER, &t4Callback);     // 10ms=6000rpm 20ms=3000 30ms= 2000 60= 1020rpm 75 =780 //fakesignal repetition
Scheduler runner;


void INJECTION() {  //interrupt routine
 
 
   digitalWrite(injector, HIGH);
   delayMicroseconds(injectiontime*1000);
   digitalWrite(injector, LOW);
   clockcount++;
 // Serial.print("INJECTED FOR: ");Serial.print(injectiontime);Serial.println("injectiontime");
 

   //Serial.println(clockcount);Serial.println("");Serial.println("");
   //Serial.print(rpmread);
//Serial.println(" RPM Measured ");
}


void t1Callback() {
   
 
 rpmset=constrain((analogRead(accel)*6),0,maxrpmset);   // rpm determined by analog/digital accelerator

 if (rpmset > rpmread ) {
  state="Accelerating" ;  // injection time increase
  injectiontime=constrain((injectiontime+timeincrement),1,10);
  }
else {
  state="Deaccelerating"; // injection time reduce
  injectiontime=constrain((injectiontime-timedecrement),mininjectiontime,maxinjectiontime); 

}
 }

void t2Callback() {

Serial.print("Accelerator  ");
Serial.print(rpmset);
Serial.println(" RPM SET");
Serial.print("Injection Time ");
Serial.print(injectiontime);
//Serial.print(injectiontime);
Serial.println(" miliseconds");
Serial.print(rpmread);
Serial.println(" RPM Measured ");
Serial.println(state);
Serial.println(lastclockcount);

}
//____________________________________________________________________________________________________task3
void t3Callback() {
rpmread=(clockcount-lastclockcount)*60*2;
   lastclockcount=clockcount;
 }

//____________________________________________________________________________________________________task4

void t4Callback() {// fake signal

digitalWrite(fakeclock, HIGH);
delayMicroseconds(100);
digitalWrite(fakeclock, LOW); 
  }



void setup() {
  Serial.begin(9600);
  pinMode(clocksignal, INPUT_PULLUP);
  pinMode(injector, OUTPUT);
  pinMode(fakeclock, OUTPUT);

  attachInterrupt(1, INJECTION, FALLING);

 
  runner.init(); //"Initialized scheduler"
  runner.addTask(t1);
  runner.addTask(t2);
 runner.addTask(t3);
  runner.addTask(t4);
 t1.enable();   
 //t2.enable(); 
 t3.enable(); 
 t4.enable();

;}

void loop() {
runner.execute();
 
}



Offline Login to see usernames

  • Global Moderator
  • Hero member
  • ****
  • Posts: 3607
Re: Arduino Analog Instruments
« Reply #13 on: August 19, 2018, 09:26:28 am »
with some the hint of the guy in the video on the first page for turning off the timer that creates those strange behavior and by manipulating the ports directly instead of the digitalwrite  i was able to generate a very extremely stable frequency nicely almost 50% square 500,230khz with arduino nano using 2useconds on and off (this delay should actually give 250khz but strangely gives 500) using 1usec on and 1 off gives 2Mhz but is not square anymore

this may be the scales it have of division inside the processor..

i imagine the processor has a 16Mhz cristal as a clock source so 2Mhz is 16/8 and 500 is 16/32

but i still didnt understood how does it relate with the time and frequency discrepancy

at lower frequency it seems to have lower discrepancy but although it generate many very precise frequencies it does not generate a continum analog like of course


here is the code to start playing with it :
ps i left the digitalwrite there for you to compare..



//int fakeclock = 13;

void setup() {
//
//pinMode(fakeclock, OUTPUT);
DDRB |= 0B00100000;
cli();
TIMSK0 &= ~(1 << TOIE0);
sei();
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
//digitalWrite(fakeclock, HIGH);
PORTB |= 0B00100000;
delayMicroseconds(2);
PORTB &= 0B11011111;
//digitalWrite(fakeclock, LOW); 
delayMicroseconds(2);
}




Offline Login to see usernames

  • Global Moderator
  • Hero member
  • ****
  • Posts: 3607
Re: Arduino Analog Instruments
« Reply #14 on: August 19, 2018, 09:48:51 am »
the possible outputs with different smallest  configurations of delaymicroseconds are :

2Mhz 1:1
800,360khz   1:2
500Khz 2:2
333khz  3:2
250khz  3:3
200khz  4:3
166,744khz  4:4
142,922khz 5:4
125,058      5:5
111,162   5:6

at lower frequencies the precision distance between frequency decreases

the order of the factor dont change the time per se meaning that the on time and off time are exactly proportional

it seems the microseconds is the lowest division possible

Offline Login to see usernames

  • Global Moderator
  • Hero member
  • ****
  • Posts: 3607
Re: Arduino Analog Instruments
« Reply #15 on: August 19, 2018, 16:43:12 pm »