RC Aircraft idle guard project and some questions.


hi all. first post in forum. last 4 months have been involved in many projects rc aircraft. one.

i building module prevent gas engine stopping unexpectedly. module continuously monitor ignition pulses , calculate rpm. if rpm falls below preset level (set multiturn potentiometer) add throttle 3 seconds gradually taking back.
during process module monitor throttle signal receiver , produce appropriate pwm signal output servo.

the final product based on attiny85 development going on on arduino uno.

the rpm measurement being accomplished using int0. interrupt attached int0 on rising edge. isr short. writes previous value of x1 x2 (both unsigned long) , current millis() x1. sets flag indicating values have changed.

in main loop if flag set, difference of x1 , x2 (transferred y1 , y2 atomic read) used calculate rpm.

to prevent jitter there array last 5 measurements rpm. everytime flag set, rpm being calculated , values in array shifted. last reading entered array. arithmetical averaging of last 5 rpm calculations gives final result.

for pwm signal receiver have tried 2 different approaches. 1 pulsein() function. other waiting pulse , measuring high pulse using micros().

for pwm signal output have tried 2 different approaches. 1 digitalwrite(throut, high) delaymicroseconds(required pulse lenght) , digitalwrite(throut, low). other replacing delaymicroseconds() while statement checking micros() until timeout.

to test module have used arduino uno produces pseudo-ignition pulses. frequency (read rpm) can set using potentiometer.

the code in general works fine there strange problem after switching on attiny85.

the servo making continuous small movements. problem renders whole project unusable. have written new , simple code test situation. code reads pwm signal receiver , sends servo without change.

code: [select]

const int thrin = 1; // throttle signal pin receiver
const int throut = 0; // servo signal output pin

unsigned int thrinpwm;
unsigned int throutpwm;

void setup()
{
  pinmode(throut, output);
}

void loop()
{
  thrinpwm = pulsein(thrin, high, 25000);
  if ((thrinpwm > 1000) && (thrinpwm < 2000))
  {
    throutpwm = thrinpwm;
    servoout();
  }
}

void servoout()
{
  digitalwrite(throut, high);
  delaymicroseconds(throutpwm);
  digitalwrite(throut, low);
}


unfortunately servo jitters.

for servo jitter there may 2 explanations.
1- there problem reading of throttle pwm signal
2- there problem output of pwm signal

so tried different approaches.

first tried algorithm read incoming signal. waiting first low high , measures time in microseconds until pin goes low. there timeout of 22000 microseconds.

code: [select]
void readthr()
{
  limittimer = micros();
  while (digitalread(thrin) == 1)
  {
    if((micros() - limittimer) > 22000) return;
  }
  limittimer = micros();
  while (digitalread(thrin) == 0)
  {
    if((micros() - limittimer) > 22000) return;
  }
  frame = micros();
  while (digitalread(thrin) == 1)
  {
    if((micros() - limittimer) > 22000) return;
  }
  thrinpwm = micros() - frame;
}


there no difference.

then tried method pwm output. writes high outut , continuously monitors micros() until required pulse lenght has been reached.

code: [select]
void servoout()
{
  digitalwrite(throut, high);
  frame = micros();
  while ((micros() - frame) < throutpwm)
  {
  }
  digitalwrite(throut, low);
}


the jitter continues...

now need advice on reading pwm pulse (duration between 1000 - 2000 microseconds recurring every 20 milliseconds) , on output pwm pulse (duration between 1000 - 2000 microseconds) reliably.

quote
for pwm signal output have tried 2 different approaches. 1 digitalwrite(throut, high) delaymicroseconds(required pulse lenght) , digitalwrite(throut, low). other replacing delaymicroseconds() while statement checking micros() until timeout.
have tried using servo library output ?

i have used code change pulse width of rc signal
code: [select]

const byte yawinpin = 7;
const byte yawoutpin = 8;
unsigned long yawduration;

const byte thrinpin = 9;
const byte throutpin = 10;
unsigned long thrduration;

void setup()
{
  serial.begin(115200);
  pinmode(yawinpin, input);
  pinmode(yawoutpin, output);

  pinmode(thrinpin, input);
  pinmode(throutpin, output);
}

void loop()
{
  yawduration = pulsein(yawinpin, high);
  yawduration = map(yawduration, 1000, 1800, 980, 2020);
  digitalwrite(yawoutpin, high);
  delaymicroseconds(yawduration);
  digitalwrite(yawoutpin, low); 

  thrduration = pulsein(thrinpin, high);
  thrduration = map(thrduration, 1000, 2000, 980, 2020);
  digitalwrite(throutpin, high);
  delaymicroseconds(thrduration);
  digitalwrite(throutpin, low); 
}


Arduino Forum > Using Arduino > Programming Questions > RC Aircraft idle guard project and some questions.


arduino

Comments