Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years ago.
how to make a cyclinders identification engine ?
Hello. I started programming with the mbed microcontroller. I work on a project réalsation an adjustment device for generators Group engines. For starters, I have connected my microcontroller to my lcd screen. I then programmed the frequency display on my LCD screen. On my oscilloscope, I made sure to keep a rectangular voltage of 5V. Once this frequency obtained, I converted to rev / min, and then I posted my duty cycle square wave. I made a kind of choice using the push buttons (1 through 6) for my otor has 6 cylinders with the condition "if" .ca is the first part. It is closed. The second part I started there three days is to achieve the identification of cylinders of my engine to detect the type of cylinder, that is to say the place of each cylinder on my oscilloscope. For doing that, aparament, I have to add to my program, a second input and an output, the number 1 cylinder, which is synchronous with my switch (type 1-4-3-2 represents the display order my pulse on my oscilloscope). Once this part done, I have to display a menu for each cylinder. But I'm thinking, I have no idea how to achieve this second part. Any of you would he do a similar project? Or do you have an idea of how I should go about it? I attached my program you and thank you in advance.
#include "mbed.h" #include "TextLCD.h" TextLCD lcd(p15, p14, p17, p18, p19, p20); // rs, e, d4-d7 //déclaration de p15,p16,P17... dans lcd Ticker tick; InterruptIn in(p10); // déclaration de p10 dans in DigitalIn e1(p21); DigitalIn e2(p22); DigitalIn e3(p23); DigitalIn e4(p24); DigitalIn e5(p25); DigitalIn e6(p26); Timer t; Timer t_on; Timer t_off; int t_period = 0; // This is the period between interrupts in microseconds float t_freq = 0; // <-- Set in an interrupt but read in main. Should be volatile or the compiler could optimise it out. void flip(); //Renvoie la frequence int main() { int trmin; int dwell=0; float alpha=0; float angle1=0;float angle2=0;float angle3=0;float angle4=0;float angle5=0;float angle6=0; in.mode(PullDown); // Set the pin to Pull Down mode. in.rise(&flip); //Set up the interrupt for rising edge t.start(); //start the timer while (1) { wait_ms(100); trmin=(t_freq*4*30)/4; if (in==1) { // <--- the input that you have created not the pin number. t_on.start(); t_off.stop(); } else { t_on.stop(); t_off.start(); alpha=t_on/(t_on+t_off); dwell=alpha*100; } if(e1==1) { angle1=(dwell*360)/100; lcd.printf("ac 1cy=%f\r\n",angle1);} else if(e2==1){ angle2=(dwell*360)/200; lcd.printf("ac 2cy=%f\r\n",angle2);} else if(e3==1){ angle3=(dwell*360)/300; lcd.printf("ac 3cy=%f\r\n",angle3); break;} else if(e4==1){ angle4=(dwell*360)/400; lcd.printf("ac 4cy=%f\r\n",angle4);} else if(e5==1){ angle5=(dwell*360)/500; lcd.printf("ac 5cy=%f\r\n",angle5);} else if(e6==1){ angle6=(dwell*360)/600; lcd.printf("ac 6cy=%f\r\n",angle6);} } } void flip() { t_period = t.read_us(); t_freq = (1/(float)t_period)*1000000; t.reset(); }